If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL0418N when inserting with select from the same table.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-04, 03:02
rydenius rydenius is offline
Registered User
 
Join Date: May 2003
Location: Stockholm, Sweden
Posts: 15
Question SQL0418N when inserting with select from the same table.

I have the following table (simplified):

CREATE TABLE aaa (
bbb INTEGER NOT NULL,
ccc INTEGER NOT NULL,
ddd INTEGER NOT NULL
);

There is a uniqe index on bbb,ccc. Try to execute the following PreparedStatement via JDBC:

INSERT INTO aaa (bbb, ccc, ddd) SELECT ?, ccc, ddd FROM aaa WHERE bbb=?

(Intention: copy all rows with a specific bbb value to new rows with another bbb value)

Get the following exception while executing in DB2:

COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/6000] SQL0418N A statement contains a use of a parameter marker that is not valid. SQLSTATE=42610
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.throw_S QLException(SQLExceptionGenerator.java:238)
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.check_r eturn_code(SQLExceptionGenerator.java:402)
at COM.ibm.db2.jdbc.net.SQLExceptionGenerator.check_r eturn_code(SQLExceptionGenerator.java:380)
at COM.ibm.db2.jdbc.net.DB2PreparedStatement.executeU pdate(DB2PreparedStatement.java:717)
at org.jboss.resource.adapter.jdbc.WrappedPreparedSta tement.executeUpdate(WrappedPreparedStatement.java :335)
...

Does anybody know how I can adjust my SQL statement (hopefully in a db vendor neutral way)?
Reply With Quote
  #2 (permalink)  
Old 10-12-04, 03:57
rydenius rydenius is offline
Registered User
 
Join Date: May 2003
Location: Stockholm, Sweden
Posts: 15
Lightbulb

Found solution:

INSERT INTO aaa (bbb, ccc, ddd) SELECT CAST (? AS INTEGER), ccc, ddd FROM aaa WHERE bbb=?

Obviously DB2 requires constants to be explicitly type casted.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On