[英]Oracle fetch cursor into cursor
我只想知道如何将游标提取到另一个游标中。 我有以下包装:
create or replace
PACKAGE Matching AS
type Cursor_Return is ref Cursor;
Procedure Get_Data
(Cus_ID in Varchar2,
Cursor_back OUT Cursor_Return,
Cursor_back2 OUT Cursor_Return);
END BARCODEMATCHING;
create or replace
PACKAGE BODY Matching AS
Procedure Matching_Proc
(Cus_ID in Varchar2,
Cursor_back OUT Cursor_Return,
Cursor_back2 OUT Cursor_Return
) AS
BEGIN
Open Cursor_back for 'Select * from cus.customerHead where CustomerID = ' || cus_Id;
Open Cursor_back2 for 'Select Cus_Location, Cus_zipcode from cus.customerBody where = CustomerID = ' || cus_ID;
Fetch Cursor_back2 into Cursor_back;
END Matching_Proc;
END Matching;
到目前为止,这是我的代码。 我只需要返回Cursor:'Cursor_back'。 当我尝试运行此代码时,出现错误:ORA-06512:缺少表达式。 有没有办法解决这个问题? 我可以声明我的两个Colums,然后以另一种方式移交给Cursor_back2吗? 我只是想返回带有两个(最多四个)列的Cursor_back,所以我有一个类似的输出:
cus.customerbody.cus_location | cus.customerbody.cus_zipcode | cus.customerhead.cus_id | cus.customerhead.cus_Name | and so on
提前致谢。
您收到“ ORA-06512:缺少表达式”错误,因为在此行中有一个额外的=
符号:
Open Cursor_back2 for 'Select Cus_Location, Cus_zipcode from cus.customerBody where = CustomerID = ' || cus_ID;
它应该where = CustomerID =
,而不应该where = CustomerID =
where = CustomerID =
。 游标语句不必是动态的,可以使用:
Open Cursor_back for
Select * from cus.customerHead where CustomerID = cus_Id;
Open Cursor_back2 for
Select Cus_Location, Cus_zipcode from cus.customerBody where CustomerID = cus_ID;
如果您坚持使用动态版本,在该版本中直到运行时才能对查询进行语法检查,所以由于您将cus_ID
作为字符串传递, cus_ID
您可能需要将其作为动态SQL语句的一部分用转义的单引号引起来。 但是除非确实需要,否则不要使用动态SQL。
但是,您实际上并不想要两个游标,因为您试图合并两个相关查询中的值。 您需要在表之间进行联接,并使用单个out参数游标,例如:
Open Cursor_back for
Select cb.cus_location, cb.cus_zipcode, ch.cus_id, ch.cus_Name
from cus.customerHead ch
join cus.customerBody cb
on cb.customerID = ch.customerID
where ch.CustomerID = cus_Id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.