on 2016 Apr 13 3:37 AM
Hi All,
SA 12.0.1.4134
I want to create a procedure with the text:
CREATE PROCEDURE "DBA"."test"(in nID integer)
BEGIN
insert into dba.TEST(IDENTITY, SUBITEM)
values(nID, 3), (default, nID);
commit;
END
When you try to save this process getting an error message:
The procedure 'test (DBA)' could not be modified in the database.
Invalid value for INSERT near 'nID' on line ???
SQLCODE: -1710
SQLSTATE: 42000
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.