Using stored procedures in Oracle to implement additions and deletions

Source: Internet
Author: User

A simple example of how an oracle who has not contacted Oracle for a project in the company is prepared to use the Proc implementation additions and deletions:

CREATE TABLE T1

(

SID number NOT NULL primary key,

Sname VARCHAR2 (10)

)

Tablespace test;

Declare

A number: = 1;

Begin

Loop

INSERT into T1 values (A, ' snow ');

a:=a+1;

Exit when a=100;

End Loop;

End

----1.insert

Create or replace procedure Proc_insert

(

Sid number,

Sname VARCHAR2

)

Is

Begin

Insert into SCOTT.T1 (sid,sname) values (sid,sname);

Dbms_output.put_line (' Number of rows affected: ' | | Sql%rowcount);

Commit

End

;

Set Serveroutput on

exec proc_insert (' snow ');

----2.update

Create or replace procedure Proc_update

(

Isid in number,

Nsname in VARCHAR2

)

Is

Begin

Update scott.t1 set sname=nsname where Sid=isid;

If Sql%found Then

Dbms_output. Put_Line (' Update successful! ');

Else

Dbms_output. Put_Line (' Update failed! ');

End If;

Commit

End

;

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.