sqlplus 和 sqldeveloper 之间的区别?

发布于 2024-10-26 12:04:35 字数 244 浏览 8 评论 0原文

我有一个用于创建表并插入数据的 sql 脚本文件。

服务器运行在 Oracle 10g 上。

当我使用 sqldeveloper (远程计算机)并运行我的脚本时,一切都很完美。但是,当我在服务器上使用 sqlplus 在同一数据库、模式、用户上运行相同的脚本时,会出现一些错误(完整性、唯一性...)?

这是什么问题,为什么我在 sqldeveloper 上没有问题,但在 sqlplus 上却有一些问题?什么会导致这种情况?

I have a sql script file that creates tables and inserts data.

The server runs on Oracle 10g.

When I use sqldeveloper (remote computer) and I run my script everything is perfect. But when I go on the server and I run the same script on the same database, schema, user with sqlplus some error appears (integrity, unique ...) ?

What's the problem, why didn't I have problem on sqldeveloper but did have some on sqlplus? What can cause that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岁月打碎记忆 2024-11-02 12:04:35

好吧,我发现了问题:

  • 第一个是注释(不支持/*注释*/或--在末尾行注释)
  • 我的脚本上有一些匿名块,我在开头放置了一些/(错误)并且结束。但在sqlplus上,以/开头,重新执行之前的查询。
  • 删除注释后,我在某些创建表上出现了空行,并且 sqlplus 在创建表内出现空行问题。

Ok i found the problems:

  • The first was the comment (/* comment */ are not supported or -- comment at the end line)
  • I had some anonymous block on my script and I put some / at the begin (by error) and the end. But on sqlplus, the / at the begin, re-execute the previous query.
  • After removing the comment i got blank line on some create table and sqlplus have problem with blank line inside the create table.
香草可樂 2024-11-02 12:04:35

我运行我的脚本,一切都很完美。但是,当我进入服务器并在同一数据库、模式、用户上使用 sqlplus 运行相同的脚本时,会出现一些错误(完整性、唯一性...)?

您的脚本似乎处理创建和插入,但不处理现有数据的删除。如果不看你的脚本,就无法说明这一点,但我可以用我的测试数据模拟相同的情况。

test.sql

create table parts ( id number primary key, 
                     description varchar2(240)
                   )
/

insert into parts values(1,'Keyboard');
insert into parts values(2,'Mouse');
insert into parts values(3,'Monitor');

在 SQL Developer 中运行脚本:

在 SQL*Plus 中运行 - 同一用户、架构、数据库:

SQL> @/home/oracle/Desktop/test.sql
create table parts ( id number primary key,
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object


insert into parts values(1,'Keyboard')
*
ERROR at line 1:
ORA-00001: unique constraint (HR.SYS_C0016596) violated


insert into parts values(2,'Mouse')
*
ERROR at line 1:
ORA-00001: unique constraint (HR.SYS_C0016596) violated


insert into parts values(3,'Monitor')
*
ERROR at line 1:
ORA-00001: unique constraint (HR.SYS_C0016596) violated

I run my script everything is perfect. But when I go on the server and i run the same script on the same database, schema, user with sqlplus some error appears (integrity, unique ...) ?

It would seem like your script handles creation and insertion, but not deletion of existing data. Without having a look at your script, there's not way to tell this, but I can simulate the same with my test data.

test.sql:

create table parts ( id number primary key, 
                     description varchar2(240)
                   )
/

insert into parts values(1,'Keyboard');
insert into parts values(2,'Mouse');
insert into parts values(3,'Monitor');

Run the script in SQL Developer:

Run in SQL*Plus - same user, schema, database:

SQL> @/home/oracle/Desktop/test.sql
create table parts ( id number primary key,
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object


insert into parts values(1,'Keyboard')
*
ERROR at line 1:
ORA-00001: unique constraint (HR.SYS_C0016596) violated


insert into parts values(2,'Mouse')
*
ERROR at line 1:
ORA-00001: unique constraint (HR.SYS_C0016596) violated


insert into parts values(3,'Monitor')
*
ERROR at line 1:
ORA-00001: unique constraint (HR.SYS_C0016596) violated
简美 2024-11-02 12:04:35

我在类似位置遇到的问题:

  • Any BEGIN ... END;外部块后面必须跟有 / 行。
  • 分号后面不能有任何内容
    • 这很好;
    • 这很糟糕; -- 评论
    • 这很糟糕;;
  • Sql 命令(选择、插入等)中间不能有空行
    • <代码>选择
      “这很好”
      来自双
    • SELECT '这很糟糕'
      [没有文字的空行]
      来自双

感谢您对 /* 多行注释 */ 的提示 - 我已将其添加到我的测试脚本中。

Problems I have encountered in a similar position:

  • Any BEGIN ... END; outer blocks must be followed with a / line.
  • Semicolons cannot have anything after them
    • this is good;
    • this is bad; -- comment
    • this is bad;;
  • Sql commands (select, insert etc) cannot have empty lines in the middle
    • SELECT
      'this is good'
      FROM Dual
    • SELECT 'this is bad'
      [empty line with no text]
      FROM Dual

Thanks for the heads-up on the /* multi-line comments */ - I've added that to my test script.

ι不睡觉的鱼゛ 2024-11-02 12:04:35

为了完整起见,SQL Developer 和 sqlplus 很可能使用不同的 nls 会话参数运行。要进行检查,请在 sqlplus 和 SQL Developer 中运行此命令并比较结果:

SELECT * FROM nls_session_parameters;

如果存在一些差异,您可以通过以下方式设置所需的 nls_session_parameters:

ALTER SESSION SET NLS_DATE_FORMAT='DD/MM/RR';
ALTER SESSION SET NLS_TIMESTAMP_FORMAT='DD/MM/RR HH24:MI:SSXFF';

Just for completeness, its quite possible that SQL Developer and sqlplus run with different nls session parameters. To check, run this command in sqlplus and SQL Developer and compare the results:

SELECT * FROM nls_session_parameters;

In case there is some difference you can set the nls_session_parameters you want via something like:

ALTER SESSION SET NLS_DATE_FORMAT='DD/MM/RR';
ALTER SESSION SET NLS_TIMESTAMP_FORMAT='DD/MM/RR HH24:MI:SSXFF';
千里故人稀 2024-11-02 12:04:35

另一个可能的区别:

有一个名为“NLS_DATE_FORMAT”的会话参数,它确定在没有调用 TO_CHAR() 的情况下选择时用于显示日期的格式。

在我的工作场所,我相信数据库中的默认 NLS_DATE_FORMAT 设置为“DD-MM-YYYY”,但 SQL Developer 中的默认值似乎是“DD-MON-YY”。

因此,以下内容适用于我们的 SQLPlus 用户,但不适用于 SQL Developer 用户,因为日期将首先使用 NLS_DATE_FORMAT 自动转换为字符串,然后使用传递到 to_date() 的格式进行解析。

select to_date(sysdate, 'DD-MM-YYYY') from DUAL;

如果是这种情况,SQLDeveloper 将给出以下错误:

ORA-01858: 在需要数字的地方发现了非数字字符

01858。 00000 - “在需要数字的地方发现了非数字字符”

*原因:使用日期格式模型转换的输入数据是
不正确。输入数据不包含数字,而数字是
格式模型所要求的。

*操作:修复输入数据或日期格式模型以确保
元素的数量和类型匹配。然后重试该操作。

Another possible difference:

There is a session parameter called 'NLS_DATE_FORMAT' that determines the format to use to display dates when selected without a TO_CHAR() call.

At my place of work, I believe the default NLS_DATE_FORMAT is set in the database to be 'DD-MM-YYYY', but the default in SQL developer seems to be 'DD-MON-YY'.

Therefore, the following will work for our SQLPlus users, but not SQL Developer users, as the date will first be automatically converted to a string using NLS_DATE_FORMAT before being parsed with the format passed into to_date().

select to_date(sysdate, 'DD-MM-YYYY') from DUAL;

If this is the case, SQLDeveloper will give the following error:

ORA-01858: a non-numeric character was found where a numeric was expected

01858. 00000 - "a non-numeric character was found where a numeric was expected"

*Cause: The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.

*Action: Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文