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 (integ开发者_JAVA百科rity, unique ...) ?
What's the problem, why didn't I have problem on sqldeveloper but did have some on sqlplus? What can cause that?
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.
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
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.
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';
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.
精彩评论