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