"Go" a few common Oracle stored procedures

Source: Internet
Author: User

http://blog.bossma.cn/database/some-oracle-storing-process/Several common Oracle stored procedures

Date: January 6, 2008/Category: DataBase/ 7,268 views/Comments

Beginner Oracle, learn about Oracle's stored procedures, run a few examples, and make a memo to facilitate later use:
1. Insert Data:
Insert several data into a table

0123456789101112131415161718192021222324252627282930313233 /*Create a table tb1contains two fields col1, col2*/Create table tb1( col1 Char(+), col2 Char(+)); / * stored procedure for inserting data * /CREATE OR REPLACE PROCEDURE insertamounttest (st_num in number,/* Start value * /ed_num in number/* End value * /) isBEGINDeclare I number ; begin/ * Loop Insert * /for i in st_num. ed_num LOOP INSERT into tb1 values(i,' Test '); END LOOP; end; commit; / * Exception handling * /EXCEPTIONwhen OTHERS Thenrollback; END; / * Execute under Commondline * /exec insertamounttest(1,+);

2. Update data

0123456789101112131415 CREATE OR REPLACE PROCEDURE updateamounttest (where_num in VARCHAR2/*sql Statement condition value * /) isBEGINUPDATE tb1 SET col2=' test2 ' where col1 like where_num| | '% '; / * Exception handling * /EXCEPTIONwhen OTHERS Thenrollback; END; / * Execute under Commondline * /exec updateamounttest(' one ');

3. Calls between stored procedures
Update with a query as an example

C #
0123456789101112131415161718192021222324252627282930313233343536 /*query Update stored procedure, call Update stored procedure UPDATEAMOUNTTEST2*/CREATE OR REPLACE PROCEDURE selectupdatetest (tjstr in CHAR ) is upstr CHAR(+); begin/*querying for field values to update*/Select a. Col2 to upstr from tb1 a where a. col1 = tjstr; /*call the update stored proceduretwo parameters passed in for update*/UPDATEAMOUNTTEST2(' One ',upstr); end selectupdatetest; /*updated stored procedure, called by Selectupdatetest*/CREATE OR REPLACE PROCEDURE UPDATEAMOUNTTEST2 (where_num in VARCHAR2,/* Update condition * /set_name in VARCHAR2/* Updated field values * /) isBEGINUPDATE tb1 SET col2=set_name where col1 like where_num| | '% '; EXCEPTIONwhen OTHERS Thenrollback; END;

"Go" a few common Oracle stored procedures

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.