0
CREATE OR REPLACE PROCEDURE ABC ( REG_NO   IN  CO_ENROLMENT.S_REGNO%TYPE,
                                  TERM     IN  COURSEOFFERING.CO_TERMNUMBER%TYPE,
                                  YEAR     IN  COURSEOFFERING.CO_YEAR%TYPE,
                                  CO_TITLE IN  COURSE.C_TITLE%TYPE,
                                  EN_DATE  OUT CO_ENROLMENT.COE_ENROLDATE%TYPE,
                                  COM_ST   OUT CO_ENROLMENT.COE_COMPLETIONSTATUS%TYPE)

AS 
BEGIN
   SELECT M.COE_COMPLETIONSTATUS, M.COE_ENROLDATE 
     INTO COM_ST, EN_DATE
     FROM COURSEOFFERING O
    INNER JOIN COURSE C
            ON C.C_ID = O.C_ID
    INNER JOIN CO_ENROLMENT M
            ON M.CO_ID = O.CO_ID
    WHERE M.S_REGNO LIKE REG_NO AND
          O.CO_TERMNUMBER LIKE TERM AND
          O.CO_YEAR LIKE YEAR AND
          C.C_TITLE LIKE CO_TITLE;
END ABC;

I have written down above procedure. Below is PL/SQL block to call above procedure,

DECLARE
  COMPL_STATUS   CO_ENROLMENT.COE_COMPLETIONSTATUS%TYPE;
  ENROL_DATE     CO_ENROLMENT.COE_ENROLDATE%TYPE;
BEGIN
  ABC (44444444, 2009, 2, 'PLSQL Programming', 
       EN_DATE => enrol_date, COM_ST =>compl_status);
  DBMS_OUTPUT.PUT_LINE ('STUDENT COMPLETION STATUS AND ENROLMENT DATE IS ' 
                         || ENROL_DATE
                         || '    ' 
                         || compl_status );
END;

It returns me error as no data found, but when I run query separately I get the output. I couldn't figure out what is wrong. Did I wrote procedure block correctly and Parameters passed in PL/SQL block are correct?

4
  • if your procedure is not doing any insert/update/delete then why not use a function instead? Commented Oct 31, 2012 at 7:55
  • Everything is working fine except that output values are not printed......output line is printed i.e.STUDENT COMPLETION STATUS AND ENROLMENT DATE IS but no values for ENROL_DATE and COMPL_STATUS. I also cross checked with just query and it returned me output values with the same input parameters. I think the problem is somewhere in passing or retrieving output parameters though I'm not sure. Commented Oct 31, 2012 at 8:04
  • Why are you passing the value 2009 to term and 2 to year? Surely these parameters should be reversed. It seems like you would benefit from always using named parameter notation (like you use for the last two parameters). Commented Oct 31, 2012 at 8:06
  • My above comment is true after making that correction!!! Commented Oct 31, 2012 at 8:09

4 Answers 4

1

In proc you have year on third place buth you call it on second place. And how are types (COURSEOFFERING.CO_TERMNUMBER%TYPE, COURSEOFFERING.CO_TERMNUMBER%TYPE) declared?

Sign up to request clarification or add additional context in comments.

6 Comments

I declared all the field with the same type as that of a specified table's column.
Ind what about parameter switching
try declaring reg_no, term and year AS number type!
got the output as but date and completion status is not printed OUTPUT - STUDENT COMPLETION STATUS AND ENROLMENT DATE IS
then also change other parameter types in simple types (DATE, NUMBER, VARCHAR2...)
|
1

When select statement in your ABC procedure returns no rows the NO_DATA_FOUND exception will be raised and execution of your stored-procedure will be halted. To avoid such behavior you need to add EXCEPTION section in the stored procedure to catch the exception and react appropriately. To that end the execution section of your stored procedure might look:

BEGIN
   SELECT M.COE_COMPLETIONSTATUS, M.COE_ENROLDATE 
     INTO COM_ST, EN_DATE
     FROM COURSEOFFERING O
    INNER JOIN COURSE C
            ON C.C_ID = O.C_ID
    INNER JOIN CO_ENROLMENT M
            ON M.CO_ID = O.CO_ID
    WHERE M.S_REGNO LIKE REG_NO AND
          O.CO_TERMNUMBER LIKE TERM AND
          O.CO_YEAR LIKE YEAR AND
          C.C_TITLE LIKE CO_TITLE;
EXCEPTION
  WHEN NO_DATA_FOUND
  THEN DBMS_OUTPUT.PUT_LINE('No data found') -- for example
END ABC

Or if you want to proceed even if select statement raises exception you might enclose your select statement with nested BEGIN .. END block.

BEGIN
   -- some code before
   BEGIN    
     SELECT M.COE_COMPLETIONSTATUS, M.COE_ENROLDATE 
       INTO COM_ST, EN_DATE
       FROM COURSEOFFERING O
      INNER JOIN COURSE C
              ON C.C_ID = O.C_ID
      INNER JOIN CO_ENROLMENT M
              ON M.CO_ID = O.CO_ID
      WHERE M.S_REGNO LIKE REG_NO AND
            O.CO_TERMNUMBER LIKE TERM AND
            O.CO_YEAR LIKE YEAR AND
            C.C_TITLE LIKE CO_TITLE;
   EXCEPTION
     WHEN NO_DATA_FOUND
     THEN DBMS_OUTPUT.PUT_LINE('No data found') -- for example
  END;
  -- some code after
END ABC

Comments

1

You probably lack wildcards in your procedure query.

16:02:06 SYSTEM@dwh-prod> select * from dual where 'abc' like 'ab'; 

no rows selected                                                    


16:02:18 SYSTEM@dwh-prod> select * from dual where 'abc' like 'ab%';

D                                                                   
-                                                                   
X                                                                   

Without them, C.C_TITLE LIKE CO_TITLE is equal to C.C_TITLE = CO_TITLE, which is not neccessarily what you want.

Try C.C_TITLE LIKE '%'||CO_TITLE||'%' etc.

2 Comments

Cool dude..........yippe...ohh man after so much of struggle finally got the output!!! Thank You so much wild card was the culprit.....but I had used TRIM function, it should had given me result?
maybe. maybe not. It depends upon what and how you were trimming. I can't tell without seeing actual code together with data.
0

You're calling your stored procedure incorrectly. You have to specify parameters in the correct order, or use named parameter notation, ie

ABC (44444444, 2, 2009, 'PLSQL Programming', enrol_date, compl_status);

or

ABC (REG_NO => 44444444, YEAR => 2009, TERM => 2,
   CO_TITLE => 'PLSQL Programming', 
   EN_DATE => enrol_date, COM_ST =>compl_status);

You can see that if you use named parameter notation you can specify parameters in a different order (or not at all if the parameters have DEFAULT values).

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.