0

这是我正在尝试运行的程序。它插入两个表table1和一个关联表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;"

没有参数,查询工作正常。即,如果我删除所有:somethings值并对值进行硬编码,那么它在我运行时运行时不会出现错误exec Insert_Row;

使用参数(带有:somethings),有错误:

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'

我究竟做错了什么?

编辑

@ron tornambe 的解决方案后查询是:

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;"

此修改后的错误是:

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'

非常感谢。

4

2 回答 2

2

试试这个

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;

如果传递参数,则不需要冒号,可以直接分配参数名称。另一点是,如果您从客户端或前端调用此过程,最好从您的过程中删除提交并使用来自调用客户端的提交。

于 2012-10-28T19:09:02.490 回答
1

您只需要在“summary IN VARCHAR2”之后加一个逗号。此外,关键字“IN”是默认值。7

于 2012-10-28T18:51:07.000 回答