Error when trying to load data from Unix script - shell

when i am trying to execute the SQL script from Unix server its showing error but the same SQL i am running from sql navigator its working fine .. kindly help me on it..
INSERT INTO t_csocstudent_course_local
(SELECT tsct.student_id,
tsct.object_lookup_id,
tsct.course_id,
tsct.xcourse_id,
clt.NAME,
tsct.course_type,
FROM temp_stud_course tsct join course_local clt
on tsct.COURSE_ID = clt.COURSE_ID
WHERE TO_CHAR (sc_timestamp, 'YYYYMMDDHH24MISS') >
(SELECT TO_CHAR (MAX (sc_timestamp), 'YYYYMMDDHH24MISS')
FROM t_student_course_local)
AND tsct.xcourse_id IN
('EX1','EX2'));
Error :
Error in loading main table
Enter password:
SP2-0734: unknown command beginning "WHERE TO..." - rest of line ignored.
AND tsct.xcourse_id IN
*
ERROR at line 3:
ORA-00933: SQL command not properly ended
Thanks in advance !!

I can't remember if the Oracle command line client permits extra whitespace linebreaks. Remove the extra linebreak before the WHERE clause.
Update
From the documentation, an empty line terminates a SQL statement by default in SQLplus.
SQLT[ERMINATOR] {;|c|OFF|ON}|
Set the char used to end and execute SQL commands to c.
OFF disables the command terminator - use an empty line instead.
ON resets the terminator to the default semicolon (;).
You can change the behavior to use semicolons instead of empty lines:
SET SQLTERMINATOR ON

Related

Invalid Number with Substitution Variable

I am having trouble trying to get an input to be accepted as a number variable. Here is the code I have:
ACCEPT clientidnum NUMBER PROMPT 'Enter Client Number(s): '
SELECT * FROM PROD.GS_EXTERNAL_CONTACT#prd1.WORLD
WHERE GEC_GS_EXT_CONTACT_ID IN (SELECT GEC_GS_EXT_CONTACT_ID
FROM PROD.CLIENT#prd1.WORLD a
WHERE CT_CLIENT_ID = to_number(trim(replace('&clientidnum',CHR(13)))) AND
a.GEC_GS_EXT_CONTACT_ID NOT IN (SELECT GEC_GS_EXT_CONTACT_ID
FROM PROD.GS_EXTERNAL_CONTACT b
WHERE a.GEC_GS_EXT_CONTACT_ID= b.GEC_GS_EXT_CONTACT_ID));
And when I run this in SQL Plus, it comes back with the below error:
ERROR at line 4:
ORA-01722: invalid number
Thanks for the assistance! Sorry if this is an easy question, but I'm use to SQL Server and was thrown on Oracle to get some things to work correctly.
Figured it out. SET DEFINE was set to OFF in my glogin.sql script. I added SET DEFINE ON to the script I am running and it works.

ASE ISQL (SyBase): how to debug truncation error (which field causes it)

I have a long SyBase SQL query that causes a truncation error. If I run it in ISQL, I get the error with the line number, however, the line number is the beginning of the query so it doesn't tell me which field is causing the truncation error. How can I debug this and get more relevent info about the error?
I use print command to find place with error. For example:
print '1'
select * from tab
print '2'
insert into tab..
print '3'
update ...
print '4'
You can also use ASE ISQL tool. There is tool for debug, see How to debug in the Debug menu.

Oracle SELECT INTO OUTFILE, what's wrong with this query?

This is the query that I am executing from sqlplus:
select * into outfile 'my_file.txt'
fields terminated by '\t' lines terminated by '\n'
from my_table where my_column = 'stuff';
I get the following error:
FROM keyword not found where expected
What am I doing wrong?
P.S. I know that there are other ways to flush the output to file but I really want to win this against Oracle...
SELECT ... INTO OUTFILE is MySQL-specific syntax. It won't work on other DBMSs such as Oracle.
In Oracle you would surround the statement with SPOOL filename...SPOOL OFF.

Oracle Pl/SQL trigger compilation error via SQL*PLUS

I have a problem with compiling an Oracle trigger via SQL*PLUS - I don't think I'm being dumb but I can't see what the problem is.
We have an installer script which is essentially a batch file which creates/refreshes all the objects in the database by calling SQLPLUS on multiple scripts, each containing one view, trigger, etc. The tables and views are created first, then then triggers. The V_BS_GRIDFIELDS view below may or may not be created at this point, or may be created later by a different process. The view is an updatable view, so we have a trigger placed on it to push updates to different tables, as below:
CREATE OR REPLACE FORCE TRIGGER TR_INSTUPD_BS
INSTEAD OF INSERT OR UPDATE OR DELETE
ON V_BS_GRIDFIELDS
FOR EACH ROW
BEGIN
IF INSERTING OR DELETING THEN
NULL;
END IF;
IF UPDATING THEN
-- Can only change these fields
IF (:OLD.VISIBLE <> :NEW.VISIBLE) OR (:OLD.COMPULSORY <> :NEW.COMPULSORY) THEN
-- Source Table = BS_GRIDFIELDS
IF (:OLD.SOURCE_TYPE = 0) THEN
UPDATE BS_GRIDFIELDS BS_GF
SET BS_GF.VISIBLE = :NEW.VISIBLE,
BS_GF.COMPULSORY = :NEW.COMPULSORY
WHERE BS_GF.FIELD_NAME = :OLD.FIELD_NAME;
END IF;
END IF;
END IF;
END;
The issue is that oracle SQL*PLUS seems to stop compiling the trigger after the first blank line, on line 6:
SQL> #"TR_INSTUPD_BS.sql";
SP2-0734: unknown command beginning "IF INSERTI..." - rest of line ignored.
SP2-0042: unknown command "NULL" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0734: unknown command beginning "IF UPDATIN..." - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SP2-0734: unknown command beginning "IF (:OLD.V..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.S..." - rest of line ignored.
SP2-0552: Bind variable "OLD" not declared.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
If you remove the blank line on line 6, it seems to stop compiling at the first semicolon, on line 7:
SQL> #"TR_INSTUPD_BS.sql";
Warning: Trigger created with compilation errors.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0734: unknown command beginning "IF UPDATIN..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.V..." - rest of line ignored.
SP2-0734: unknown command beginning "IF (:OLD.S..." - rest of line ignored.
SP2-0552: Bind variable "OLD" not declared.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END IF" - rest of line ignored.
SP2-0042: unknown command "END" - rest of line ignored.
SP2-0044: For a list of known commands enter HELP
and to leave enter EXIT.
SQL>
We have lots of triggers created in this way, and all of them have spaces, semicolons, etc, and get created OK. I've tested and seen the same issue on Oracle 9, 10, 11. Can anyone shed light on this?
Thanks.
in its default setting SQL*Plus won't deal properly with blank lines, you need to issue the following command:
SQL> SET SQLBLANKLINES on
See this other SO.
Update: I answered too fast, the blank line doesn't seem to be the problem here. I tried your code on my database and the issue seems to come from the FORCE keyword. The 10gR2 documentation doesn't mention this keyword. The trigger compiles when you remove it.

Incorrect syntax near ')'

I have a BasicMSI project (Installshield 2009) that runs a SQL script during the installation process.
During the installation I receive the following error.
Error 27506.Error executing SQL script {SCRIPTNAME}. Line 352. Incorrect syntax near ')'. (102)
The problem is that I don't have any ')' at line 352 of the script and also the script works without any problems if I run it with SQL Management Studio Express.
Can anyone tell me what is the problem and how can I fix it?
Thanks.
PS. I cannot set the script error handling option to "On Error, Goto Next Statement" because therefor it will not create some of my foreign keys.
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRIGGER_NAME]'))
EXEC dbo.sp_executesql #statement = N'
CREATE TRIGGER [dbo].[TRIGGER_NAME]
ON [dbo].[TABLE_NAME] -- LINE: 352
INSTEAD OF INSERT
AS
BEGIN
DECLARE #Count INT;
SET #Count = (SELECT COUNT([Name])
FROM TABLE_NAME
WHERE IsDeleted = 0 AND [Name] IN (SELECT [Name] FROM INSERTED));
IF #Count > 0
BEGIN
RAISERROR (''Error Message.'', 16, 1);
Rollback;
END
ELSE
BEGIN
INSERT INTO dbo.TABLE_NAME SELECT {Columns} FROM INSERTED;
SELECT CONVERT(BigInt,SCOPE_IDENTITY()) AS [value]
END
END
'
GO
I was getting similar errors (one with ')' as the offending character, one with ';' as the offending character). Then I noticed that when InstallShield imported my scripts, it had changed ">" to ">" and "<" to "<" and "&" to "&". Doing search-and-replace across the imported scripts in the InstallShield script editor for these three substitutions fixed the issue for me.
It seems reasonable that this error might occur if you've written an IN statement, which you populate programmatically, only at runtime some values are missing, resulting in a statement saying "... WHERE x IN()", which is invalid.
This would generate that error, and also, it is an error that could easily appear in one environment but not another. It is hard to give more detail than that without actually seeing the script.

Resources