pl sql在程序中设置变量

时间:2013-03-13 20:56:57

标签: plsql

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

我想做这样的事情:

 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;

1 个答案:

答案 0 :(得分: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;