firstthree (my_seqid in varchar2) as cursor c1 is     select sname, grade from student s join taken

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

//stored procedure

 

create or replace procedure firstthree (my_seqid in varchar2) as

cursor c1 is

    select sname, grade from student s join taken t on s.sid=t.sid

      where seqid=my_seqid

      order by grade desc;

-- my_sname varchar2(40);

my_sname student.sname%TYPE;

-- my_grade number(2,1);

my_grade taken.grade%TYPE;

begin

/* clear the my_tmp table */

delete from my_tmp;

commit;

 

open c1;

for i in 1..3 loop

    fetch c1 into my_sname, my_grade;

    exit when c1%notfound; /* in case the number requested */

                           /* is more than the total */

                           /* number of enrolled students */

    /* display the result */

    dbms_output.put_line('name: ' || my_sname || ' ' || 'grade: ' || my_grade);

    /* put into temporary table */

    insert into my_tmp values(my_sname, my_grade);

    commit;

end loop;

close c1;

end;

/

--------------

//php

<?

$connection = oci_connect ("test", "test", "test");

if ($connection == false){

   $e = oci_error();

   die($e['message']);

}

 

// the statement to call the stored procedure

$query = "begin " .

         " firstThree(:my_seqid); " .

        "end;";

 

$cursor = oci_parse($connection, $query);

if ($cursor == false){

   $e = oci_error($connection);

   die($e['message']);

}

 

// after parsing, bind the variable with Oracle variable.

oci_bind_by_name($cursor, ":my_seqid", $my_seqid, 5);

$my_seqid = '00001';

 

$result = oci_execute($cursor, OCI_NO_AUTO_COMMIT);

if ($result == false){

   $e = oci_error($cursor);

   die($e['message']);

}

 

oci_commit($connection);

oci_close($connection);

 

echo("Operation completed successfully.");

?>

----------------------------

Modify the stored procedure and the above PHP code to output (echo) the average of the top three grades in the Web page.

 

You need to modify the header of procedure firstThree() to

create or replace procedure firstThree(my_seqid in varchar2, my_average out number)

 

to include an output parameter my_average which outputs the average grade. Note the keyword OUT is used to indicate an output parameter. In the PHP code, you also need to bind an output variable. For example, if you use :my_average as the actual output parameter in the PL/SQL code, you can use the follow PHP code to bind it with a PHP variable $my_average:

 

oci_bind_by_name($cursor, ":my_average", $my_average, 40);

 

Note that 40 is used as the fourth argument of oci_bind_by_name() since the maximum length of a number in Oracle is 40 digits. The size of the PHP output variable must be large enough to accommodate the output parameter from the stored procedure. oci_bind_by_name resizes the PHP output variable my_average based on the length argument, which is 40 in this case.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY