Oracle PL/SQL select into variables

前端 未结 2 1645
甜味超标
甜味超标 2020-12-19 22:32

I am trying to run the following query in SQL Developer, but I am receiving an error. I am trying to declare two local variables (var_num1 and payDate) and then set the var

相关标签:
2条回答
  • 2020-12-19 22:38

    You cannot use SELECT without INTO clause in PL/SQL. The output of the SELECT must be stored somewhere. Eg. table or variable or perhaps a record. See example below how to store result of the SELECT statement into record.

    DECLARE
      var_num1 number; 
      payDate date;
      v_result Paycode%ROWTYPE;
    BEGIN 
      var_num1 := 100; 
      payDate := '10/1/2013';
    
        SELECT * INTO v_result
        FROM Paycode
        WHERE PaycodeID = var_num1 and PaycodeDate = payDate;
    
    END; 
    
    0 讨论(0)
  • 2020-12-19 22:57

    If you want to get a resultset back in SQL Developer with this code block you will need to open a ref cursor for the query e.g.

    DECLARE
      refCur REF CURSOR;
      refc refCur;
      var_num1 number; 
      payDate date;
      v_result Paycode%ROWTYPE;
    BEGIN 
      var_num1 := 100; 
      payDate := '10/1/2013';
    
    OPEN refc FOR
        SELECT * 
        FROM Paycode
        WHERE PaycodeID = var_num1 and PaycodeDate = payDate;
    
    END; 
    
    0 讨论(0)
提交回复
热议问题