Hi All, SA 12.0.1.4134 I want to create a procedure with the text:
When you try to save this process getting an error message:
Q: What kind of error (in the help, it is not described) and why is it happening ? |
Thiago is correct in his comment above: when there are multiple value tuples in the values clause then only constant values are allowed, so as a result variables are not allowed. I am unsure why there is this restriction. I have sent a note to the doc team to add a note to the VALUES clause section in the INSERT statement documentation. [Update] After some more scanning of the code I see that host variables are also allowed in the list of values of the value row constructor when there are multiple values specified. Syntax
documented for SA 12.0.1 Look in the help section "INSERT INTO statement, syntax" in the example at the end of description. Q: So it's all the same mistake that this request does not work with the variable or not ?
(15 Apr '16, 02:52)
Stalker
Replies hidden
FWIW, the doc sample with a table with columns all having defaults does work: create table T_Test( col1 int default autoincrement primary key, col2 int default 2, col3 int default 3); insert T_Test() values (), (), (); select * from T_Test; returns col1,col2,col3 1,2,3 2,2,3 3,2,3 . As Mark has pointed out, the restriction (which I would call a bug...) does only apply to multi-row insert and local (or connection-specific) variables, such as begin declare nInt int = 4; create variable varInt int = 5; insert T_Test values (default, nInt, nInt); -- works insert T_Test values (default, varInt, varInt); -- works insert T_Test values (default, nInt, nInt), (default, nInt, nInt); -- fails with SQLCODE -1710 insert T_Test values (default, varInt, varInt), (default, varInt, varInt); -- fails with SQLCODE -1710 end;
(15 Apr '16, 07:57)
Volker Barth
|
FWIW, while the restriction seems to hold as Mark has explained, you might use an INSERT SELECT instead of an INSERT with multiple rows if you want to insert multiple rows with variables, such as begin declare nInt int = 6; insert T_Test select null, nInt, nInt union all select null, nInt, nInt; end; |
FWIW, it's not documented for v12.0.1 but for v16 and above, see here. Can't tell why it's happening, to me the INSERT statement looks good. For further tests I would use nID as a connection variable and test the INSERT statement without the surrounding stored procedure...
Very awkward, I have tested with 2 inserts and it works fine:
It looks like INSERT of multiple rows only accepts values.
I ran this code below on iSQL and I got the same error:
BUG?