2017-10-08 10 views
0

oracle/toad.Oracle Declare 변수를 사용하여 다른 select 쿼리에서 사용

변수를 정의하고 select에서 값을 삽입하려고합니다. 그 값을 설정 한 후에 다른 select 문으로 사용하고 있습니다. 그러나 이것은 나에게 오류를 제공하고 INTO 절은 아마도 당신이 Implicit Statement Results in Oracle Database 12c Release 1를 검색이 SELECT

declare maxLineNo number := 0; 

BEGIN 
select Max(b.Line_No) into maxLineNo FROM Brokerage b WHERE b.External_App_Id = 3720  AND b.Account_Id = '16970' ; 

SELECT b.External_App_Id -- this select giving erro 
     , maxLineNo + 1 
     , b.Currency 
     , '' 
     , CAST(SUM(b.Brokerage_Amt) as VARCHAR2(17)) 
     , '' 
     , '' 
     , 1003 -- 1003 for Report summary 
     , '' 
    FROM Brokerage b 
    WHERE b.External_App_Id = 3720 
    GROUP BY External_App_Id, B.CURRENCY 
    ORDER BY 2; 

DBMS_OUTPUT.PUT_LINE(maxLineNo); -- this is giving value 
end; 
+1

이,'SELECT'는'INTO' 절 –

+0

와 함께 작동 그래서 무엇을 제안합니까? 블록을 닫으면 var MaxLineNo를 외부에서 사용할 수 없습니다. – PawanS

+1

또한 공백 값에 대해서는 '대신'NULL을 쓰는 것이 좋습니다. –

답변

0

예상된다 PL/SQL 블록 내

declare 
    maxLineNo number := 0; 
    rc sys_refcursor; 
BEGIN 
select Max(b.Line_No) into maxLineNo 
FROM Brokerage b 
WHERE b.External_App_Id = 3720  AND b.Account_Id = '16970' ; 

open rc for 
SELECT b.External_App_Id -- this select giving erro 
     , '' 
     , b.Currency 
     , '' 
     , CAST(SUM(b.Brokerage_Amt) as VARCHAR2(17)) 
     , '' 
     , '' 
     , 1003 -- 1003 for Report summary 
     , '' 
    FROM Brokerage b 
    WHERE b.External_App_Id = 3720 
    GROUP BY External_App_Id, B.CURRENCY 
    ORDER BY 2; 

DBMS_OUTPUT.PUT_LINE(maxLineNo); -- this is giving value 

dbms_sql.return_result(rc); 
end;