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

Timo Hahn

User, can you describe what you try to archive. Executing an operation will just do that, executing it. If you want to refresh the UI you hae to issue a ppr. However, without more information it's hard to tell which way to go.

Timo

Leandro Vitale

i will use the hard refresh because my information of the TreeTable don't refresh adequately and need use Ctrl + F5 to working and obtain information last updated

Timo Hahn

Why does the info on hte tree table not refresh?

Timo

PaKo

Beside data model, which is refreshed as per your code snippet, you should also refresh view component (or entire page, which you do with Ctrl+F5). As I dont know how you wish to "trigger" refresh, I'll assume you are doing it from some button. Lets say command / action button which triggers some action in backing bean (doing something in database) so you wish to show updated state in a table. Then you have just to put partialTrigger on your af:table to be the action button (or multiple of them, look into doc for partialTrigger property). Then, after the model is refreshed (as per executing binding action) JSF will rerender also the table view and - you get your data updated!

Also, there is a way to grammatically force refresh of particular table from your code (instead using declarative partialTrigger approach). At the end of your code to refresh model, just add something like:

private RichTable tableBinding;

...

AdfFacesContext.getCurrentInstance().addPartialTarget(tableBinding);

Leandro Vitale

This is i don't know..

Timo Hahn

Well, if xou don't describe youe whole use case and we can only guess. My guess is as @PaKo already told you that you have to send a ppr to the table or the surrounding layout container (e.g. af:panelCollection). If the change of hte data is invoked by a button, you can do this decoratively by adding the id of hte button to the Table or layout container. If you do t his you should use the Edit option you get if you click on the  wheel on the right side of the partial trigger property. This will ensure that you get the right id including any naming containers.

Timo

Leandro Vitale

For example, I run the application that shows me a table in the database. If I modify this database physically, when refreshing the page do not see the changes reflected, I need to close the application and re-run. Is the information cached?

Timo Hahn
Answer

This works fro me without writing on line of code. I start with the emp table in the HR db as

pastedImage_0.png

in my sample it looks like

pastedImage_1.png

as you see equal. Then I change the DB to 24000 and commit to get

pastedImage_2.png

Now I hit the refresh declarative button

pastedImage_3.png

and get

pastedImage_4.png

So I see the new or changes data in the db in my table

All I did was to add a partialTrigger in the table pointing to the refreshButton!

<af:table value="#{bindings.EmployeesView1.collectionModel}" var="row" rows="#{bindings.EmployeesView1.rangeSize}"

                                  emptyText="#{bindings.EmployeesView1.viewable ? 'No data to display.' : 'Access Denied.'}" rowBandingInterval="0"

                                  selectedRowKeys="#{bindings.EmployeesView1.collectionModel.selectedRow}"

                                  selectionListener="#{bindings.EmployeesView1.collectionModel.makeCurrent}" rowSelection="single"

                                  fetchSize="#{bindings.EmployeesView1.rangeSize}" filterModel="#{bindings.EmployeesView1Query.queryDescriptor}"

                                  filterVisible="true" queryListener="#{bindings.EmployeesView1Query.processQuery}" varStatus="vs" id="t1"

                                  **partialTriggers="::b2"**\>

That's it.

Timo

Marked as Answer by Leandro Vitale · Sep 27 2020
Leandro Vitale

Thanks, is the solution

1 - 9
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,668 views