How a function in Oracle returns a result set

Source: Internet
Author: User

In Oracle, it is sometimes used to return a result set with a function, and here is the demo:

1234567 create or replace type t_test as object(id integer,create_time date,object_name varchar2(60));create or replace type t_test_table as table of t_test;

1. Using an array of methods

1234567891011121314151617181920 create or replace function f_test(n in number default null)return t_test_table asv_test t_test_table := t_test_table();beginfor i in 1 .. n loopv_test.extend();v_test(v_test.count) := t_test(i, sysdate, ‘name‘ || i);end loop;return v_test;end f_test;/SQL> select * from table(f_test(5));ID CREATE_TIME OBJECT_NAME-------- -------------- -------------1 07-4月 -15 name12 07-4月 -15 name23 07-4月 -15 name34 07-4月 -15 name45 07-4月 -15 name5

2. Using the pipe function

123456789101112131415161718192021 create or replace function f_test_pipe(n in number default null)return t_test_tablePIPELINED asv_test t_test_table := t_test_table();beginfor i in 1 .. nvl(n, 100) looppipe row(t_test(i, sysdate, ‘name‘ || i));end loop;return;end f_test_pipe;/SQL> select * from table(f_test_pipe(5));ID CREATE_TIME OBJECT_NAME---------- -------------- ----------------1 07-4月 -15 mc12 07-4月 -15 mc23 07-4月 -15 mc34 07-4月 -15 mc45 07-4月 -15 mc5

How a function in Oracle returns a result set

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.