Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 04: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, 04: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

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