View previous topic :: View next topic
|
Author |
Message |
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
Hi,
I have written code like below to insert into the table, but i am getting sql code error of -104 in prepare sql statement and -518 in execute statement. help me in correcting the mistake please...
Code: |
VAL.L = ,FIELD1,FIELD2,FIELD3,FIELD4
DATA = SUBSTR(VAL.L,3)
QUERY1='INSERT INTO 'SRCSCHEMA'.'TABLE' VALUES('DATA') '
ADDRESS DSNREXX "EXECSQL DECLARE C2 CURSOR FOR S2"
IF SQLCODE <> 0 THEN CALL SQLCA
ADDRESS DSNREXX "EXECSQL PREPARE S2 FROM :QUERY1"
IF SQLCODE <> 0 THEN SAY SQLCODE CALL SQLCA
ADDRESS DSNREXX "EXECSQL EXECUTE S2 USING :DATA"
IF SQLCODE = 0 THEN
SAY "INSERT SUCCESSFUL"
ELSE
DO
SAY "INSERT OPERATION FAILED"
SAY 'SQLCODE' SQLCODE
SAY 'SQLSTATE' SQLSTATE
SAY 'SQL ERROR MESSAGE' SQLERRMC
END
|
VAL.L is obtained from SQL Fetch statement earlier to this code and that works fine..... |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
I suggest that you take out the DECLARE CURSOR statement. S2 is an INSERT, which does not require a cursor. You could also consider EXECUTE IMMEDIATE for the Insert rather than PREPARE+EXECUTE. |
|
Back to top |
|
|
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
don.leahy wrote: |
I suggest that you take out the DECLARE CURSOR statement. S2 is an INSERT, which does not require a cursor. You could also consider EXECUTE IMMEDIATE for the Insert rather than PREPARE+EXECUTE. |
I tried as how you suggested but still get the same:
Code: |
QUERY1='INSERT INTO 'SRCSCHEMA'.'TABLE' VALUES('DATA') '
ADDRESS DSNREXX "EXECSQL PREPARE S2 FROM :QUERY1"
IF SQLCODE <> 0 THEN SAY SQLCODE CALL SQLCA
ADDRESS DSNREXX "EXECSQL EXECUTE IMMEDIATE S2"
IF SQLCODE = 0 THEN
SAY "INSERT SUCCESSFUL"
ELSE
DO
SAY "INSERT OPERATION FAILED"
SAY 'SQLCODE' SQLCODE
SAY 'SQLSTATE' SQLSTATE
SAY 'SQL ERROR MESSAGE' SQLERRMC
END
|
output Error:
Code: |
INSERT OPERATION FAILED
SQLCODE -104
SQLSTATE 42601
SQL ERROR MESSAGE S2:<HOST-VARIABLE>
***
|
|
|
Back to top |
|
|
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
It says the return -104 is illegal token and it should be token-list.... what does the token mean here in the INSERT QUERY....? |
|
Back to top |
|
|
sakrat
Active User
Joined: 05 Feb 2014 Posts: 164 Location: India
|
|
|
|
don.leahy wrote: |
I suggest that you take out the DECLARE CURSOR statement. S2 is an INSERT, which does not require a cursor. You could also consider EXECUTE IMMEDIATE for the Insert rather than PREPARE+EXECUTE. |
I sorted out the mistake that I made. now i am able to insert successfully...Thank you very much for give me the suggestion which was very useful to me to understand.....
Thanks,
sakrat |
|
Back to top |
|
|
|