Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Having problems returning multiple rows with parameterised CURSOR and IF, ELSE DBMS_OUPUT

2652078May 23 2014 — edited May 23 2014

Hi folks

I'm using 11g Express Edition 11.2.0.2.0.

I'm trying to return the name of a student, all of their tests taken, grade, passing grade and whether this is a pass or fail.

In the code i've 'cobbled' together, if the student has failed it works. However, if the student has passed it just returns 'Result = Pass'  and fails to return their name, tests, grade and passing grade.

A second issue (and please let me know if i need to post this in a separate thread) is if a student has carried out multiple tests, it only returns one.

Thanks for any advice you can give me.

SET SERVEROUTPUT ON

DECLARE

  CURSOR c_pass_fail_cursor

    (p_studentid number) IS

    SELECT students.firstname,

      test_history.score,

      test_id.test_name,

      test_id.passing_grade

    FROM students

    INNER JOIN test_history

      ON students.STUDENT_ID = test_history.student_id

    INNER JOIN test_id

      ON test_id.test_id = test_history.test_id

    WHERE students.student_id = p_studentid

    AND test_history.SCORE < test_id.passing_grade;

   

  v_name students.firstname%type;

  v_score test_history.SCORE%type;

  v_test test_id.test_name%type;

  v_passing test_id.passing_grade%type;

  v_result varchar2(4); 

   

BEGIN

  OPEN c_pass_fail_cursor (1);

  LOOP

    FETCH c_pass_fail_cursor INTO v_name, v_score, v_test, v_passing;

  EXIT WHEN c_pass_fail_cursor%notfound;

  END LOOP;

  CLOSE c_pass_fail_cursor;

 

  IF v_score < v_passing then

    v_result := 'Fail';

    DBMS_OUTPUT.PUT_LINE (v_name || ' ' || v_score || ' ' || v_test || ' ' || v_passing || ' ' || 'Result = ' || v_result); 

  ELSE

    v_result := 'Pass';

    DBMS_OUTPUT.PUT_LINE (v_name || ' ' || v_score || ' ' || v_test || ' ' || v_passing || ' ' || 'Result = ' || v_result);

  END IF;

 

END;

/

This post has been answered by David Berger on May 23 2014
Jump to Answer

Comments

dmcghan
Answer
990870,

Please set up a demo of your problem on apex.oracle.com. Provide us with developer credentials and steps to reproduce.

Regards,
Dan

blog: http://DanielMcghan.us/
work: http://SkillBuilders.com/APEX/
Marked as Answer by Srinivash · Sep 27 2020
Howard (... in Training)
Hi 990870,

A few preliminaries. Could we get you to change your handle from a number to a name? (I'm Howard.) Also, If you haven't read the useful advice in https://forums.oracle.com/forums/ann.jspa?annID=1324 , take a look.

A demo is a great idea.

A few thoughts. [I'm only a newbie.] In what I've done, APEX seemingly constructs/makes a page (or region) visible and then updates it. So, one sees the current value and it changes to the the new value before our very eyes. A feature? It could be a useful one. But what we want is to have the page cleared before it's made visible so we don't see the former image. Right?

So, is there a way to change the page before it displays? Can we do this: Hide the region, update the region, show the updated region? Not sure.

But if it were, say, a single button -- maybe that can be done with some javascript. You already have a DA.

One could add a new action "Execute Javascript Code" and in Settings have the following Code:
[This was someone's example to show or hide a button based on a count in P9_COUNT.]
var my_cnt = $v('P9_COUNT');
if( my_cnt > 0 )
{
   $('#MY_SUB_BTN').show();
}
else
{
   $('#MY_SUB_BTN').hide();
};
So one would have three actions on the same DA. The first would hide the region, the second would hide the button and the third would show the update region without the button. Maybe it could work.

I'll see if there's any time to experiment with this today.

Regards,
Howard
Srinivash
Hi Dan,
I have made a demo app at apex.oracle.com with the following credentials
workspace-srinivash
user-srinivashvarma@yahoo.com
password-twilight


you can go to the only app present there named as 'practice dynamic action jan'.When you run the page you will get an select list item which you when change displays the report according to the empno selected.But before it shows the report it also shows no data found for few second which I dont required.Also when you select a empno and then NULL then again any other empno it will show the previous report first.
And my restriction is I cant submit page.It has to be done through dynamic action

Thanks in advance
Srinivash
Srinivash
Hi Howard,
Thanks for the suggestion I did change my handle and I think the idea you are giving will require me to page reload which I cant do in my page as it will completely change other things because of the other on load process.Please go through the demo I provided and help me.

Thanks in advance
Srinivash
HarryF
My approach is to have a conditional on the region:

:SELECT_LIST is not null

If the page action when value changed for the select list is submit page it will refresh the page and show the region.
Tom Petrus
Srinivash,

First of all, the built-in refresh has been made so that no screen-flicker-effect would occur: the refreshed region is a bit of html requested from the server, dumped in a container, and then replaces the original html (a report in this case).
What you want, from what I understand, is to hide the region when it is refreshed.

Looking at your app, you probably want to keep the region hidden during the PLSQL code and the refresh action. I just put the "Hide" effect you had under the "False" actions as first action in the "True" actions.
Doesn't that achieve what you want? I'm not sure why you put a false action under a change event. A change will always be a true action, it will only fire when there is an actual change.
dmcghan
Srinivash,

I looks like the refresh action was move to asynchronous Ajax (kinda funny, I know) and that was the problem. However, if you leverage the apexafterrefresh event that is triggered on the region after the refresh is complete, then it's an easy workaround.

I updated your demo to do this via a new dynamic action. Is that working as you wanted it to?

Regards,
Dan

blog: http://DanielMcghan.us/
work: http://SkillBuilders.com/APEX/
Srinivash
Hi Dan,
Thanks a lot Its working as required I wanted when the select list is chosen as NULL then the region should hide and I added that as a false condition and now its totally as required.So after refresh action which I was missing .Once again thanks for the help Dan.

Thanks
Srinivash
Srinivash
Hi Harry,
Actually i had the limitation of not making the page reload so i cant make the report region as conditional and also the refresh action only works on the report query it doesn't refresh or check the condition there again so I was not able to apply this approach.Thanks for your help.

Thanks
Srinivash
Srinivash
Hi Tom,
I needed that false action to hide the region when the select list is changed to NULL and when not NULL to refresh and show the region.Thanks for your suggestion that hide thing is the correct approach you are correct.

Thanks
Srinivash
1 - 10
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 20 2014
Added on May 23 2014
3 comments
1,669 views