儲存過程練習

2021-08-29 13:12:50 字數 2501 閱讀 4055

insert

into

person 

values(1

,'zdw','

zdw','

test1')

insert

into

person 

values(2

,'test',

'test',

'test2')

insert

into

person 

values(3

,'admin',

'admin',

'admin3')

/*在儲存過程中使用子查詢

*/create

procedure

person_sub_query

(@id

int)

asselect

*from

person 

where

id <

(select

count(*

) from

person)

goexecute

person_sub_query 2/*

在儲存過程中修改引數值,使用多個查詢語句:

*/create

procedure

person_multi_query

(@id

int)

asselect

@id=

(select

count(*

) from

person 

where

id >

@id)

select

@id=

@id-

1select

*from

person 

where

id =

@idgo

execute

person_multi_query 1

/*建立表

*/create

table

person

(id 

intprimary

key,

username 

varchar(50

) not

null

,password 

varchar(20

) not

null

,address 

varchar

(200

) not

null)/*

增加一條記錄的儲存過程

*/create

procedure

proc_person

(@id

int,

@username

varchar(50

),@password

varchar(20

),@address

varchar

(200) )

asinsert

into

person(id,username,password,address) 

values

(@id

,@username

,@password

,@address)go

/*傳值順序是你宣告變數時的順序

*/exec

proc_person 1,

'admin',

'admin',

'bj'select

*from

person;

/*修改資料的儲存過程

*/create

procedure

proc_person_update

(@id

int,

@username

varchar(50

),@password

varchar(50

))asupdate

person 

setusername

=@username

, password

=@password

whereid=

@idgo

execute

proc_person_update 1,

'test',

'test

'select

*from

person

/*刪除資料的儲存過程

*/create

procedure

proc_person_del

(@id

int)

asdelete

from

person 

where

id =

@idgo

execute

proc_person_del 

1select

*from

person

々上善若水々 2008-04-10 10:11

儲存過程練習

游標為輸出引數 create or replace procedure pro emp select empsal out sys refcursor as begin open empsal for select empno,sal from emp end pro emp select 呼叫 d...

小練習 分頁儲存過程

create database dbtest use dbtest if exists select from sysobjects where name pagetest drop table pagetest go 建立測試表 create table pagetest id int ident...

Oracle 儲存過程練習小樣例

建立更新的儲存過程,輸錯訂單號顯示訂單不存在 create or replace procedure upd shipdate orderid number,shipdate date ise no row exception begin update ord set v shipdate ship...