Reputation: 11830
Here's a procedure that I'm trying to run. It inserts into two tables - table1
and an association table table2
.
create or replace procedure Insert_Row (summary IN VARCHAR2
description IN VARCHAR2, status IN NUMBER,
date_submitted IN DATE, last_updated IN DATE,
owner_id IN NUMBER, reporter_id IN NUMBER,
foo IN VARCHAR2, bar IN VARCHAR2,
first_assignee IN NUMBER)
is
l_cur_id number;
begin
insert into table1
(summary, description, status, date_submitted,
last_updated, owner_id, reporter_id,
foo, bar)
values( :summary, :description, :status,
to_date(:date_submitted,'YYYY-MM-DD'),
to_date(:last_updated,'YYYY-MM-DD'), :owner_id,
:reporter_id, :foo, :bar)
returning action_id into l_cur_id;
insert into table2(action_id, assignee_id)
values(l_cur_id,:test);
commit;
end;"
Without the parameters, the query works fine. I.e. if I remove all the :somethings
and hardcode the values then it runs with no errors when I run exec Insert_Row;
With the parameters (with the :somethings
), there are errors:
show errors procedure Insert_Row;
Errors: check compiler log
2/4 PLS-00103: Encountered the symbol "DESCRIPTION" when expecting one of the following:
:= . ) , @ % default character
The symbol "," was substituted for "DESCRIPTION" to continue.
14/13 PLS-00049: bad bind variable 'SUMMARY'
14/23 PLS-00049: bad bind variable 'DESCRIPTION'
14/37 PLS-00049: bad bind variable 'STATUS'
15/21 PLS-00049: bad bind variable 'DATE_SUBMITTED'
16/21 PLS-00049: bad bind variable 'LAST_UPDATED'
16/50 PLS-00049: bad bind variable 'OWNER_ID'
17/13 PLS-00049: bad bind variable 'REPORTER_ID'
17/27 PLS-00049: bad bind variable 'FOO'
17/33 PLS-00049: bad bind variable 'BAR'
20/21 PLS-00049: bad bind variable 'TEST'
what am I doing wrong?
EDIT
Query after @ron tornambe's solution is:
create or replace procedure Insert_Row (summary IN VARCHAR2,
description IN VARCHAR2, status IN NUMBER,
date_submitted IN DATE, last_updated IN DATE,
owner_id IN NUMBER, reporter_id IN NUMBER,
foo IN VARCHAR2, bar IN VARCHAR2,
first_assignee IN NUMBER)
is
l_cur_id number;
begin
insert into table1
(summary, description, status, date_submitted,
last_updated, owner_id, reporter_id,
foo, bar)
values( :summary, :description, :status,
to_date(:date_submitted,'YYYY-MM-DD'),
to_date(:last_updated,'YYYY-MM-DD'), :owner_id,
:reporter_id, :foo, :bar)
returning action_id into l_cur_id;
insert into table2(action_id, assignee_id)
values(l_cur_id,:test);
commit;
end;"
Error after this modification is:
14/13 PLS-00049: bad bind variable 'SUMMARY'
14/23 PLS-00049: bad bind variable 'DESCRIPTION'
14/37 PLS-00049: bad bind variable 'STATUS'
15/21 PLS-00049: bad bind variable 'DATE_SUBMITTED'
16/21 PLS-00049: bad bind variable 'LAST_UPDATED'
16/50 PLS-00049: bad bind variable 'OWNER_ID'
17/13 PLS-00049: bad bind variable 'REPORTER_ID'
17/27 PLS-00049: bad bind variable 'FOO'
17/33 PLS-00049: bad bind variable 'BAR'
20/21 PLS-00049: bad bind variable 'TEST'
Many thanks.
Upvotes: 0
Views: 5193
Reputation: 14731
Try this
create or replace procedure Insert_Row (summary IN VARCHAR2,
description IN VARCHAR2, status IN NUMBER,
date_submitted IN DATE, last_updated IN DATE,
owner_id IN NUMBER, reporter_id IN NUMBER,
foo IN VARCHAR2, bar IN VARCHAR2,
first_assignee IN NUMBER)
is
l_cur_id number;
begin
insert into table1
(summary, description, status, date_submitted,
last_updated, owner_id, reporter_id,
foo, bar)
values( summary, description, status,
to_date(date_submitted,'YYYY-MM-DD'),
to_date(last_updated,'YYYY-MM-DD'), owner_id,
reporter_id, foo, bar)
returning action_id into l_cur_id;
insert into table2(action_id, assignee_id)
values(l_cur_id,test);
commit;
end;
You do not need to have colon if you are passing parameters, you could directly assign parameter names. Another point is if you are calling this procedure from a client or from front end, better remove commit from your procedure and use commit from your calling client.
Upvotes: 2
Reputation: 10780
You just need a comma after "summary IN VARCHAR2". Also, the keyword "IN" is the default.7
Upvotes: 1