當前位置:首頁 » 操作系統 » ifthen資料庫實驗

ifthen資料庫實驗

發布時間: 2022-03-30 12:32:36

❶ if then 後面能否寫sql語句,如果能怎樣寫

if 條件一 then
sql="select * from bbbb"
else
sql="select * from aaaa"
end if
這樣就行了

深入的話,可以寫成這樣
sql="select * from news where news_class="
if 條件一 then
sql=sql&"1"
else
sql=sql&"2"
end if

if request("move")="next" then

sql="select top 1 * from news where newsid >"&strnewsid
rs.open sql,conn,1,1
strnewsid=rs("newsid")
strnewsid=strnewsid+1

else

sql="select top 1 * from news where newsid <"&strnewsid
rs.open sql,conn,1,1
strnewsid=rs("newsid")
strnewsid=strnewsid+1

end if
這樣可以嗎?

❷ sql中if then的使用

if 後面沒then
引用sql聯機叢書
IF...ELSE
在執行 Transact-SQL 語句時強加條件。如果條件滿足(布爾表達式返回 TRUE 時),則在 IF 關鍵字及其條件之後執行 Transact-SQL 語句。可選的 ELSE 關鍵字引入備用的 Transact-SQL 語句,當不滿足 IF 條件時(布爾表達式返回 FALSE),就執行這個語句。

語法
IF Boolean_expression
{ sql_statement | statement_block }
[ ELSE
{ sql_statement | statement_block } ]

另外你這個觸發器能執行?
set @q = old.filmreview_id
while(old.filmreview_id!=MAX(filmreview_id))
這兩行我怎麼看都不符合sql語法啊

資料庫的if條件語句怎麼用

if @page = 1
select id from tablename where id >=(select id from tablename where page =@page) and id<=(select id from tablename where page =@page+1)
else
select id from tablename where id >=(select id from tablename where page =@page) and id<=(select max(id) from tablename)

❹ 有熟悉sqlite的么 在sqlite中沒有if then的語句 那麼需要if的地方該怎麼寫啊

sqlite明文資料庫,一般用的時候盡量不用資料庫邏輯處理數據,在程序里處理邏輯問題,資料庫僅作為存儲

❺ 資料庫中什麼時候用if else語句

sql中沒有if語句,但有case語句,而且是所有資料庫都支持的, 語法是case when 條件1 then 結果1 when 條件2 then

❻ 關於mysql if then用法

不知你用的是什麼查詢分析器。
我記得 select count(*) into @cnt from table1 where map_id = 114 and `type` = 400 ;

if @cnt > 0 then update table1 set `count` = 25 where map_id = 114 and `type` = 400;
else
insert table1 (map_id,`count`,`type`) values (114,25,400);
end if ;

而且好像if then endif只能在procere或是function里用吧

❼ .請問在SQl語句中實現IF-THEN-ELSE結構 sqlserver可以不,oracle中是怎麼實現的,還有DB2 以及mysql中分

我覺得你要的是 case when then when then else end 方法, 樓上說的都不對

case sex when 『1』 then 『男' when '2' then '女' else '其他' end-----簡單case函數
case when sex=1 then『男' when sex=2 then 『女' else 『其他' end --------case搜索函數

你就知道這2種方式 是一回事, 就是一個條件 處理

❽ postgresql中使用if else語句

1、首先在postgresql資料庫中復製表的時候,必須先建立表結構,然後通過insert into語句來實現。

❾ SQL資料庫 游標實驗

我也是菜鳥,寫了一個你瞧瞧。

select*fromaaax;
銀行ys貸款金額jerq貸款日期貸款年限nxgs公司名稱
工行 3 2017-5-8 15 塞德斯公司
建行 5 2018-6-9 12 塞德斯公司
中國銀行 6 2016-6-8 5 塞德斯公司
中國銀行 66 2016-6-8 77 dfgfdgh
建行 34 2016-6-8 55 dfgfdgh
declare
v_yhvarchar2(100);
v_jenumber;
v_rqvarchar2(100);
v_nxvarchar2(100);
v_gsvarchar2(100);
vv_gsvarchar2(100);
vv_sumnumber;
cursoremp_cursorisselect*fromaaa;
cursoremp_cursor2isselectgs,sum(je)fromaaagroupbygs;
begindbms_output.enable(500000);
openemp_cursor2;loopfetchemp_cursor2intovv_gs,vv_sum;exitwhenemp_cursor2%notfound;
DBMS_OUTPUT.PUT_LINE(vv_gs||'總貸款金額為'||vv_sum||'萬元,具體情況為如下:');
openemp_cursor;
loop
fetchemp_cursorintov_yh,v_je,v_rq,v_nx,v_gs;
exitwhenemp_cursor%notfound;
ifvv_gs=v_gsthen
DBMS_OUTPUT.PUT_LINE(v_yh||','||v_rq);endif;
endloop;
closeemp_cursor;endloop;closeemp_cursor2;
end;

效果

熱點內容
空壓機980密碼是多少 發布:2024-09-26 01:21:33 瀏覽:295
緩存命中率cdn 發布:2024-09-26 01:20:58 瀏覽:915
excel2007如何加密 發布:2024-09-26 01:11:40 瀏覽:953
php獲取當前用戶 發布:2024-09-26 01:10:52 瀏覽:306
繼續訪問取消 發布:2024-09-26 01:09:35 瀏覽:49
JIT編譯典型流程 發布:2024-09-26 01:08:43 瀏覽:204
碼流264和265影響存儲 發布:2024-09-26 00:54:42 瀏覽:884
微博密碼如何改 發布:2024-09-26 00:54:36 瀏覽:550
wifi密碼linux 發布:2024-09-26 00:53:56 瀏覽:184
華為如何設置雙屏幕密碼 發布:2024-09-26 00:44:26 瀏覽:321