Sql:oracle 11g CREATE PROCEDURE

Source: Internet
Author: User

CREATE OR REPLACE PROCEDURE proc_insert_bookkindlist (temtypename nvarchar2,temparent int) asncount number;  Begin--select COUNT (*) into ncount from Bookkindlist fm1 where EXISTS (SELECT bookkindname from Bookkindlist fm2 where FM2. Bookkindname=temtypename);--to determine whether to save select COUNT (*) into the ncount from Bookkindlist where bookkindname=temtypename;if Ncount<=0 Thenbegininsert into Bookkindlist (bookkindname,bookkindparent) VALUES (temtypename,temparent); commit;  End;elsebegin SELECT Bookkindid into ncount from Bookkindlist where bookkindname=temtypename; Dbms_output.put_line (' existence of the same record, add unsuccessful! ' | | ncount); end;end if; Exception when others then Dbms_output.put_line (' There is a problem, add unsuccessful! ' | |       ncount); Rollback; End proc_insert_bookkindlist;--Test Oracle 11g-coated 20150526exec proc_insert_bookkindlist (' Oil paint ', 3);d ROP PROCEDURE PROC_ Insert_bookkindout; CREATE OR REPLACE PROCEDURE procinsertbookkindout--Add return ID (temtypename nvarchar2,temparent number,temid out number) ASNC Ount Number;reid number;begin--Select COUNT (*) into ncount from Bookkindlist fm1 where EXISTS (SELECT bookkindname from Bookkindlist fm2 where FM2. Bookkindname=temtypename);--to determine whether to save select COUNT (*) into the ncount from Bookkindlist where bookkindname=temtypename;if Ncount<=0 Thenbegininsert into Bookkindlist (bookkindid,bookkindname,bookkindparent) VALUES (BookKindList_ seq.nextval,temtypename,temparent); Select Bookkindlist_seq.currval into Reid from Dual;temid:=reid;dbms_output.put_ Line (' Add success! ' | |  TEMID); Commit;end;elsebegin SELECT bookkindid into ncount from Bookkindlist where bookkindname=temtypename; Dbms_output.put_line (' existence of the same record, add unsuccessful! ' | |  ncount); Temid:=0;end;end if; Exception when others then begin Dbms_output.put_line (' There is a problem, add unsuccessful! ' | |      ncount);       temid:=0;     Rollback; End;end procinsertbookkindout;--test Oracle 11g tu poly 20150526declaremid number:=0;nam nvarchar2 (100): = ' black and white ';p ar number:=3 ; Begin--proc_insert_bookkindout (Nam in Nvarchar2,par in Int,mid in out int);p Rocinsertbookkindout (nam,par , mid); if mid>0 thendbms_output.put_line (' Add success! output parameter: ' | | mid); Elsedbms_output.put_line (' There is the same record, add not successful! output parameter: ' | | mid); end If;end;

  

Sql:oracle 11g CREATE PROCEDURE

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.