mySQL語法中的儲存過程及if語句的使用簡例

2022-01-11 14:54:36 字數 883 閱讀 1441

1

create

procedure

gh() #注意各個地方的分號!此**應先執行除掉最後一句的部分,然後執行call gh顯示已經儲存的結果

2begin

3declare c_no int

; #宣告資料型別的方法45

select

count(*) into

c_no # 將乙個結果存入乙個變數

6from

jyb

7where jszh in(8

select

jszh

9from

dzb10

where dw =

'經濟系');

1112

if c_no =

0then    #if......then......else.....end

if13

select xm as 姓名,dw as 所在單位,zc as

職稱14

from

dzb15

where dw =

'經濟系

'and

16not

exists(17

select*18

from

jyb,dzb

19where dzb.jszh = jyb.jszh and dw =

'經濟系');

2021

else

22select

'此係還有人沒有還書

'; #此處select相當於print

2324

endif;25

end26

2728 call gh;

python3 從入門到開車

mysql語法例項 mysql 儲存過程語法及例項

1 下面為乙個儲存過程的定義過程 create procedure proc name in parameter integer begin declare variable varchar 20 if parameter 1 then set variable mysql else set var...

儲存過程語法及例項

一般儲存過程的格式 create or replace procedure 儲存過程名 param1 in type,param2 out type as變數1 型別 值範圍 變數2 型別 值範圍 begin 語句塊exception 異常處理 when others then rollback e...

MYSQL中儲存過程的建立,呼叫及語法

mysql 儲存過程是從 mysql 5.0 開始增加的新功能。儲存過程的優點有一籮筐。不過最主要的還是執行效率和sql 封裝 特別是 sql 封裝功能,如果沒有儲存過程,在外部程式訪問資料庫時 例如 php 要組織很多 sql 語句。特別是業務邏輯複雜 的時候,一大堆的 sql 和條件夾雜在 ph...