0

我不确定如何在调用另一个存储过程的存储过程中设置变量。我想保存返回的值并稍后在另一个选择中使用它。

我想做这样的事情:

 PROCEDURE procName(bcur OUT IssCur)
 IS
cur2 IssCur;
extCur IssCur;
exlineno varchar2(30);

BEGIN
exlineno :=getExternlineno(exlineno,'50036648','00060');
open cur2 for SELECT concat(SUBSTR(susr2, 0, INSTR(susr2, '-')-1),'' ) from OrderDetail;

要调用的存储过程

 PROCEDURE getExternlineno(
oRetValue OUT varchar2,
pKey IN varchar2,
poNum IN varchar2)
AS
Begin
  select externlineno into oRetValue  from podetail where pokey = pKey and polinenumber    = poNum;
end getExternlineno;

一旦我弄清楚如何做到这一点,我也可以分解这样的东西(它不理解 proc 名称:

      SELECT concat(concat(SUBSTR(susr2, 0, INSTR(susr2, '-')-1),'' ),' - ' || getExternlineno(exlineno,'50036648','00060')) from OrderDetail;
4

1 回答 1

1

叶戈尔的评论是正确的。您应该声明getExternlineno为函数以便在 SQL 查询中使用它。

该函数getExternlineno将变为:

FUNCTION getExternlineno(
pKey IN varchar2,
poNum IN varchar2)
RETURN VARCHAR
AS
DECLARE
oRetValue VARCHAR2(2000); -- Change the precision as per program's requirements.
Begin
  select externlineno into oRetValue from podetail where pokey = pKey and polinenumber = poNum;
end getExternlineno;
    /

您的procName程序将变为:

PROCEDURE procName(bcur OUT IssCur)
IS
cur2 IssCur;
extCur IssCur;
exlineno varchar2(30);

BEGIN
exlineno := getExternlineno('50036648','00060'); -- Notice the change in number of arguments here.
open cur2 for SELECT concat(SUBSTR(susr2, 0, INSTR(susr2, '-')-1),'' ) from OrderDetail;
END procName;
/

您的 SQL 查询将变为:

      SELECT concat(concat(SUBSTR(susr2, 0, INSTR(susr2, '-')-1),'' ),' - '
             || getExternlineno('50036648','00060'))
        FROM OrderDetail;
于 2013-03-15T09:01:06.813 回答