Example of calling Oracle stored procedure with a cursor in plus

Source: Internet
Author: User
Previously, I answered some questions from some netizens about how to wear a collection of returned records in www.linuxidc.comlinux2012-0765117.htm. Presumably

Before in The Post http://www.linuxidc.com/Linux/2012-07/65117.htm answered some netizens on how to wear a collection of returned records stored procedures. Presumably

In the previous post, I answered some questions from some netizens about how to wear a stored procedure that returns a set of records. I think many netizens already understand this. I will not talk about it more here.

How to call a stored procedure with a cursor in sqlplus

How Does Oracle execute the process with a cursor?

Here is an example.

-- Use the cursor (the cursor is actually a temporary table in the memory)
Declare
Money cms3_simcard.card_1_% type: = 0; -- Define the same type as the table Field
Cursor mycursor is -- defines the cursor
Select * from cms3_simcard
Where return_flag = 1 and msisdn like '000000 ';
My_record mycursor % rowtype; -- defines the cursor record type
Counter int: = 0;

Begin
Open mycursor; -- open the cursor
If mycursor % isopen then -- determines whether the open is successful
Loop -- Obtain Record Sets cyclically
Fetch mycursor into my_record; -- get records in the cursor
If mycursor % found then -- the cursor's found attribute determines whether a record exists
Dbms_output.put_line (my_record.card_logs );
Else
Exit;
End if;
End loop;
Else
Dbms_output.put_line ('cursor not opened ');
End if;
Close mycursor;
End;

If you want to ask me how to call the program, you should not ask because there are too many people who know it. No more nonsense.

First, let's look at the table structure of t1.

Check the data in Table T1.

As with the previous post, create a package first

Creating a stored procedure with a cursor is a stored procedure that returns a set of records.

All the data is available, and the focus is on it. A collection of records returned when a stored procedure is called

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.