mysql存儲過程嵌套if
BEGIN
IFEXISTS(select1fromrw_yzs_Staticwherepagetype=i_pagetypeandcatalogCode=i_catalogCodeandserviceCode=i_serviceCodeandserviceName=i_serviceName)THEN
updaterw_yzs_StaticsetserviceCode=i_serviceCode,serviceName=i_serviceName,zgbb=i_zgbb,sxmc=i_sxmc,cnqx=i_cnqx,sfbz=i_sfbz,dz=i_dz,bldx=i_bldx,bltj=i_bltj,sxcl=i_sxcl,ckbllc=i_ckbllc,wsbllc=i_wsbllc,blsx=i_blsx,blyj=i_blyj,bz=i_bz,updatetime=NOW()
wherepagetype=i_pagetypeandcatalogCode=i_catalogCodeandserviceCode=i_serviceCodeandserviceName=i_serviceName;
ELSE
INSERTINTOrw_yzs_Static(pagetype,divisioncode,divisionname,catalogCode,catalogName,serviceCode,serviceName,orgGroup,zgbb,sxmc,cnqx,sfbz,dz,bldx,bltj,sxcl,ckbllc,wsbllc,blsx,blyj,bz,updatetime)
VALUES(i_pagetype,i_divisioncode,i_divisionname,i_catalogCode,i_catalogName,i_serviceCode,i_serviceName,i_orgGroup,i_zgbb,i_sxmc,i_cnqx,i_sfbz,i_dz,i_bldx,i_bltj,i_sxcl,i_ckbllc,i_wsbllc,i_blsx,i_blyj,i_bz,now());
ENDIF;
END
例子與回答無關:
這里應該用case when then 這類的吧
這里給個思路,具體用法還是自己去網路吧。應該太多了這種教學。
select case 學分 when <60 then xf=0 from xscj where 學號=xh and 課程名稱 =kcmc
你里你應該新增一個變數來記錄成績的值 才能對此進行IF判斷
㈡ mysql 存儲過程 if條件 判斷變數的值是否0
mysql> DELIMITER //
mysql> CREATE PROCEDURE TestIfElse
-> (
-> p_val INT
-> )
-> BEGIN
-> IF (p_val = 1) THEN
-> SELECT '1' AS A;
-> ELSEIF (p_val = 2) THEN
-> SELECT '2' AS A;
-> ELSE
-> SELECT 'other' AS A;
-> END IF;
-> END//
Query OK, 0 rows affected (0.05 sec)
上面是一個最簡單的 mysql 的
IF / ELSEIF 的例子了...
㈢ mysql 存儲過程中的 if exists 判斷問題
SELECT沒有IF EXISTS 語法,你可以用select count(*) from information_schema.tables where table_schema='your_schema' and table_name='your_tab';看返回0還是1來判斷。
㈣ 存儲過程的if,else怎麼寫
不同的資料庫中,存儲過程中if else 語句寫法有一些差別。
如果是SQLServer資料庫,存儲過程的if, else語句可以這樣寫:
ifa>b
Begin
print'a'
End
Elseifa<b
Begin
print'b'
End
Else
Begin
print'代碼'
End
Oracle 採用下面這種寫法:
IFtestvalue>100THEN
dbms_output.put_line('100+');
ELSIFtestvalue=100THEN
dbms_output.put_line('100');
ELSE
dbms_output.put_line('100-');
ENDIF;
DB2, MYSQL 是下面這種寫法: ( 與 Oracle 區別在於那個 ELSIF )
IFp_val>100THEN
INSERTINTOoutput_debugVALUES('100+');
ELSEIFp_val=100THEN
INSERTINTOoutput_debugVALUES('100');
ELSE
INSERTINTOoutput_debugVALUES('100-');
ENDIF;
㈤ 在MYSQL存儲過程中case語句里嵌套IF語句行嗎
你的case內的if中的 getchar()應該只執行一次,用變數保存,如case『S':改為: 在switch(in)前面加個 char ch; case 'S':printf("目前無法判斷,請輸入第二個字元!\n"); ch = getchar(); if(ch=='a') printf("Saturday."); else if (ch=='u') //...
㈥ mysql存儲過程中if的嵌套
前幾日寫存儲過程,使用嵌套if語句的時候,碰到一個奇怪的問題,多方找原因無果。後發現是一個很sb的問題。。。
if condition1 then
if condition1.1 then
do something1.1;
else if condition1.2 then
do something1.2;
else -- 報錯的地方
do something1.3;
endif;
else
do something2.2;
endif;
如上,else那裡一直在報錯。
使用了排除法,把else那塊去掉,仍報錯。
整個中間的if那段去掉,編譯成功。
else if和else去掉,編譯成功。
else if去掉,編譯成功。
好吧,else if的問題。elseif應該是沒有空格的!!!
排除法是個好方法,細心是個好習慣😂😂😂。。。