Return SQL RET

Source: Internet
Author: User

Simple: --创建procedure create or replace procedure sql_test(out_return out sys_refcursor) is begin    open out_return  for ‘select * from tgp_funds‘ ; end;Https://zhidao.baidu.com/question/922899782581115539.html http://blog.csdn.net/xwq911/article/details/ 46278901 Guidance: Oracle does not support separate SELECT statements if a SELECT statement is used in the Oracle database stored procedure, either using a "SELECT INTO variable" statement or using a cursor.

Let's look at this stored procedure:

Create or replace procedure Pro_test
Is
Begin
SELECT * from T_test;
End Pro_test;

Is this stored procedure correct?

It was a long time since yesterday. (a SELECT statement was used in a stored procedure, but neither a cursor nor an into) was used.

In a stored procedure (Oracle database) If a SELECT statement is used, either using a "SELECT INTO variable" statement or using a cursor, Oracle does not support a separate SELECT statement (as stated in the wrong statement).

Select into is relatively simple, but if you return a result set, you will not be able to meet the requirements.

Cursors are divided into cursor-type cursors and Sys_refcursor-type cursors.

Cursor type cursors--cannot be used for parameter passing

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 use of the cursor, which needs to be written between Begin and end)

Begin

Select Class_name into cursor_2 from class where ...;

can use

for XXX in cursor

Loop

....

End Loop; --Traversal of the cursor

End Pro_test;

Sys_refcursor-Type Cursors

Create or Replace procedure Pro_test (Rscursor out Sys_refcursor) is

Cursor sys_refcursor;

Name Varhcar (20);

Begin

Open cursor for

Select name from student where ...; --open to assign by using open

--Traversal

Loop

Fetch cursor into name--fetch into to open traversed each piece of data

Exit when Cursor%notfound; --No record information found

Dbms_output.putline (xxxx);

End Loop;

Rscursor: = cursor;

End Pro_test;

Http://www.cnblogs.com/sc-xx/archive/2011/12/03/2275084.html

Return SQL RET

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.