Detailed description of select and parameters in oracle stored procedures

Source: Internet
Author: User

 

Create or replace procedure pro_test

Is

Begin

Select * from t_test;

End pro_test;

Is this stored procedure correct?

Yesterday, this was a long delay (the select statement was used in a stored procedure, but neither the cursor nor the into statement was used ).

If a select statement is used in the Stored Procedure (oracle Database tutorial), either the "select into variable" statement or the cursor is used, oracle does not support separate select statements (if the statement is incorrect, please note ).

Select into is relatively simple, but if a result set is returned, it cannot meet the requirements.

Cursor-type cursor and sys_refcursor-type cursor

Cursor type cursor -- cannot be used for parameter transfer

Create or replace procedure pro_test () is

Cusor_1 cursor is select field name from table name where condition;

(Or

Select class_name into cursor_2 from class where ...;

Another usage of cursor, which must be written between begin and end)

Begin

Select class_name into cursor_2 from class where ...;

Available

For xxx in cursor

Loop

....

End loop; -- traverses cursor

End pro_test;

Sys_refcursor type cursor

Create or replace procedure pro_test (rscursor out sys_refcursor) is

Cursor sys_refcursor;

Name varhcar (20 );

Begin

Open cursor

Select name from student where...; -- use open to open and assign values

-- Traversal

Loop

Fetch cursor into name -- fetch

Exit when cursor % notfound; -- record information not found

Dbms_output.putline (xxxx );

End loop;

Rscursor: = cursor;

End pro_test;


How to call other stored procedures in Stored Procedures (these are all with parameters)

 

A stored procedure with parameters.
SQL> create or replace procedure helloworld1 (
2 p_user_name varchar2
3)
4 begin
5 dbms_output.put_line ('hello' | p_user_name | '! ');
6 end helloworld1;
7/

Procedure created.

SQL> create or replace procedure callhelloworld1 (
2 p_user varchar2
3)
4 begin
5 -- call the Stored Procedure
6 helloworld1 (p_user );
7 end callhelloworld1;
8/

Procedure created.

Run
SQL> set serveroutput on
SQL> exec callhelloworld1 ('Tom ');
Hello tom!

Pl/SQL procedure successfully completed.

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.