2

Im a newbie to Oracle and trying to create a new procedure but getting a error,

Error-expression P_EMP_SAL cannot be used as an INTO target of SELECT/FETCH statement..

CREATE OR REPLACE PROCEDURE getempsal(
        p_emp_id IN NUMBER,
        p_emp_month IN CHAR,
        p_emp_sal in INTEGER)

AS
BEGIN
    SELECT EMP_SAL
    INTO p_emp_sal
    FROM EMPLOYEE_SAL
    WHERE EMP_ID = p_emp_id
    and EMP_MONTH = p_emp_month;

END getempsal;

2 Answers 2

2

You specify IN for a parameter you want to return from a procedure. Try p_emp_sal OUT INTEGER.

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/subprograms.htm#i4107

4
  • it worked but how do I call it?..I tried calling using getempsal(1,'JAN',OUTVAR) but get a error Feb 1, 2013 at 4:00
  • @user1050619 it depends of the environment you use for calling. can you be a bit more specific and provide a sample with error? Feb 1, 2013 at 4:14
  • Im calling it in oracle toad. getempsal(1,'JAN',OUTVAR) given me invalid statement Feb 1, 2013 at 4:31
  • 1
    try declare var integer; begin getempsal(1, 'JAN', var); end;? Feb 1, 2013 at 4:50
-1

Take out put parameter refcursor and make changes in body of procedure

Open outCursor for SELECT EMP_SAL
    INTO p_emp_sal
    FROM EMPLOYEE_SAL
    WHERE EMP_ID = p_emp_id
    and EMP_MONTH = p_emp_month;
1
  • if you want single value you can take varialble instead of cursor Feb 1, 2013 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.