Use of oracle custom functions

Source: Internet
Author: User

Oracle user-defined functions are one of the most important functions. The following describes how to use oracle user-defined functions to implement the return table type, which is helpful to you.

Functions in oracle can return the table type. However, this table type is actually a collection type similar to an array) This type cannot be directly used as the from object.

Since oracle 9i, we have provided a concept called "pipeline table functions" to solve this problem.
This type of function must return a set type and indicate pipelined.
This function cannot return specific variables. It must return an empty return.
In this function, each row in the table to be returned is sent using the pipe row () statement.

When this function is called, the pipeline stream is simulated as a dataset using the table () keyword.
The following is a simple example:

 
 
  1. create table tb1(k number, v varchar2(10));  
  2.  
  3. insert into tb1(k, v) values(100,'aaa');  
  4. insert into tb1(k, v) values(200,'bbb');  
  5. insert into tb1(k, v) values(200,'ccc');  
  6.  
  7. select * from tb1;  
  8.  
  9. create type row_type1 as object(k number, v varchar2(10));  
  10.  
  11. create type table_type1 as table of row_type1;  
  12.  
  13. create or replace function fun1 return table_type1 pipelined as  
  14. v row_type1;  
  15. begin  
  16. for myrow in (select k, v from tb1) loop  
  17.   v := row_type1(myrow.k, myrow.v);  
  18.   pipe row (v);  
  19. end loop;  
  20. return;  
  21. end;  
  22.  
  23. select * from table(fun1);  


 

Oracle TRIM function syntax

Oracle date functions

Oracle trunc () function usage

Syntax for creating an Oracle package

Use of Oracle to_char Functions

Related Article

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.