儲存過程基礎學習

2021-08-31 09:01:59 字數 1935 閱讀 7259

--建立儲存過程

create proc procedurename

--儲存過程引數

@params

as --執行語句

return

--執行儲存過程

go--變數的申明

declare @param int

--變數的賦值 賦值是前面必須加set

set @param=32

--申明多個變數

declare @s varchar(23),@a int

--sql 裡面的if語句

if--條件

begin

--執行語句

endelse begin

--執行語句

enddeclare @d int

set @d=233

if @d=233 begin

--列印

print '正確'

end

else begin

print '錯誤'

end

--sql 裡的多條件選擇語句

declare @contion int,@test varchar(32)

set @contion=12

select @contion

case

when @test='一' then 1

when @test='二' then 2

when @test='三' then 3

else 100

end--迴圈語句

while --條件

begin

--執行語句

enddeclare @t int

set @t=1

while @t<1000 begin

set @t=@t

end--列印

print @t

--truncate table author 刪除

--從查詢的結果中建立乙個新錶

--select into newtable

select * into newtables from uname

--insert into select

--把uname裡面的字段username賦值到abc

--abc 表必須存在

insert into abc select username from uname

--建立臨時表語法:

create table #temp(

id int identity(1,1) primary key,

name varchar(18),

*** varchar(39)

)--查詢臨時表

select *from #temp

---儲存過程

--要建立儲存過程的shjuuk

use netgpsdb4

--判斷要建立的儲存過程是否存在

if exists(select name from systemobj where name='vehiclebyuserid' and type='p')

--刪除儲存過程

drop proc vehiclebyuserid

go--建立儲存過程

create proc vehiclebyuserid

--儲存過程引數

declare @temp1 int

declare @temp2 varchar(12)

declare @te*** varchar(32)

as--執行儲存過程函式體

insert into uname(age,names,***) values(@temp1,@temp2,@te***)

return

--執行

go--執行儲存過程

exec vehiclebuuserid 12,'ad','男'

儲存過程基礎

建立輸入引數儲存過程 create or replace procedure lyr3 name varchar2,age number is begin insert into student values sys guid name,age end 建立輸出儲存過程 create procedu...

基礎 儲存過程

github mysql 5.0開始支援儲存過程,儲存過程是存在資料庫中的一段sql集合,呼叫儲存過程可以減少很多任務作量,減少資料在資料庫和應用伺服器上的傳輸,對於提高資料處理的效率,同時注意,儲存過程沒有or replace的關鍵字,mysql的儲存過程引數包括 in,out,inout 三種模...

儲存過程基礎

儲存過程基礎語法 1.1 基本結構 create or replace procedure 儲存過程名字 引數1 in number,引數2 in number as 變數1 integer 0 變數2 date begin end 1.2 select into statement 將select...