我已经使用下面的代码在火狐上使用iSQL +创建了一个过程。该过程编译成功。
create or replace procedure get_staff (
product_no in varchar2,
o_cursor out sys_refcursor)
is
begin
open o_cursor for
'select sr.name, sr.bonus from sales_staff sr inner join product p on p.sales_staff_id = sr.staff_id where product_no = ' || product_no ;
end;我正在尝试使用以下代码调用此过程
var rc refcursor
exec get_staff('A56',:rc)
print rc我得到以下错误。
ERROR at line 1:
ORA-00904: "A56": invalid identifier
ORA-06512: at "AA2850.GET_STAFF", line 6
ORA-06512: at line 1
ERROR:
ORA-24338: statement handle not executed
SP2-0625: Error printing variable "rc" 发布于 2013-01-23 15:36:11
在这种情况下,不需要动态sql:
open o_cursor for
select sr.name, sr.bonus
from sales_staff sr
inner join product p
on p.sales_staff_id = sr.staff_id
where p.product_no = product_no;如果您使用的是动态SQL,那么在大多数情况下,理想情况下您会希望绑定:
open o_cursor for
'select sr.name, sr.bonus
from sales_staff sr
inner join product p
on p.sales_staff_id = sr.staff_id
where p.product_no = :b1' using product_no;如果做不到这一点(在边缘情况下,有时您希望避免不正确数据的绑定变量),varchar2s需要用引号括起来:
open o_cursor for
'select sr.name, sr.bonus
from sales_staff sr
inner join product p
on p.sales_staff_id = sr.staff_id
where p.product_no = ''' ||product_no||'''';但您应该转义单引号,并验证product_no没有分号等(即小心SQL注入)
https://stackoverflow.com/questions/14473220
复制相似问题