Oracle creates stored procedures in two ways

Source: Internet
Author: User

Oracle creates stored procedures in two ways

Create or replace procedure Getdefault is
Begin

Execute immediate ' Create global temporary table deftemp (PID varchar2 (5)) on commit delete rows ';
SELECT * from Deftemp;

End

Method Two
/*
Let's see a
1: Create a temporary table
2: Insert result set into temporary table
3: Return the result set of the temporary table
Simple instance of Oracle stored procedure creation
*/

Declare
Create_str varchar2 (100);
Dept_row Dept%rowtype;
Begin
CREATE_STR: = ' Create global temporary table temp on commit preserve rows as select * from dept ';
Execute immediate create_str;
Execute immediate ' SELECT * from temp where rownum=1 ' into dept_row;
Dbms_output.put_line (Dept_row.deptno | | ') +'|| dept_row.dname| | ' +'|| DEPT_ROW.LOC);
End


/*

1, each statement after the end of use;
2, the DDL needs to use execute immediate dynamic SQL execution
3, the stored procedure does not support direct Select, need to use a cursor
*/

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.