Anatomy of the actual usage of Oracle stored procedures

Source: Internet
Author: User

The following articles mainly describe the actual usage of the Oracle stored procedure. This article uses the actual application code to introduce the actual operation process of the Oracle stored procedure, the following is a detailed description of the relevant content. I hope you will gain some benefits after browsing.

 
 
  1. create table stuInfo  
  2. (  
  3. stuID int primary key,  
  4. stuName varchar2(20)  
  5. )  
  6. create or replace procedure proc1  
  7. is  
  8. begin  
  9. insert into stuInfo values(1,'liheng');  
  10. end;  
  11. create or replace procedure proc2  
  12. (  
  13. v_ID int,  
  14. v_Name varchar2  
  15. )  
  16. is  
  17. begin  
  18. insert into stuInfo values(v_ID,v_Name);  
  19. commit;  

Remember to submit

 
 
  1. end;  
  2. create or replace procedure proc3  
  3. (  
  4. v_ID int,  
  5. v_Name out varchar2  
  6. )  
  7. is  
  8. varName stuInfo.Stuname%type;  
  9. begin  
  10. select stuName into varName from stuInfo where stuID=v_ID;  
  11. v_Name:=varName;  
  12. end;  

Returns all records.

 
 
  1. create or replace package PKG_STUINFO is  
  2. type stuInfoCursorType is ref cursor;  
  3. procedure getStuInfo (stuInfoCursor out stuInfoCursorType);  
  4. end;  
  5. create or replace package body PKG_STUINFO is  
  6. procedure getStuInfo (stuInfoCursor out stuInfoCursorType)  
  7. is  
  8. var_cursor stuInfoCursorType;  
  9. begin  
  10. open var_cursor for select * from stuInfo;  
  11. stuInfoCursor:=var_cursor;  
  12. end;  
  13. end;  

Return records by number

 
 
  1. create or replace package PKG_STUINFO is  
  2. type stuInfoCursorType is ref cursor;  
  3. procedure getStuInfo (v_ID int,stuInfoCursor out stuInfoCursorType);  
  4. end;  
  5. create or replace package body PKG_STUINFO is  
  6. procedure getStuInfo (v_ID int,stuInfoCursor out stuInfoCursorType)  
  7. is  
  8. var_cursor stuInfoCursorType;  
  9. begin  
  10. if v_ID=0 then  
  11. open var_cursor for select * from stuInfo;  
  12. else  
  13. open var_cursor for select * from stuInfo where stuID=v_ID;  
  14. end if;  
  15. stuInfoCursor:=var_cursor;  
  16. end;  
  17. end;  

Return records by name

 
 
  1. create or replace package PKG_STUINFO is  
  2. type stuInfoCursorType is ref cursor;  
  3. procedure getStuInfo (v_Name varchar2,stuInfoCursor out stuInfoCursorType);  
  4. end;  
  5. create or replace package body PKG_STUINFO is  
  6. procedure getStuInfo (v_Name varchar2,stuInfoCursor out stuInfoCursorType)  
  7. is  
  8. var_cursor stuInfoCursorType;  
  9. begin  
  10. if v_Name =' ' then  
  11. open var_cursor for select * from stuInfo;  
  12. else  
  13. open var_cursor for select * from stuInfo where stuName like '%'||v_Name||'%';  
  14. end if;  
  15. stuInfoCursor:=var_cursor;  
  16. end;  
  17. end;   

The above content describes the usage of the Oracle stored procedure, hoping to help you in this regard.

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.