sybase流程式控制制

來源:互聯網
上載者:User

1.變數聲明與賦值

全域變數由系統預定義,以符號@@打頭。

局部變數聲明使用Declare語句,這個變數必須以符號@開頭,後跟一個標識符。

Declare @變數名 資料類型[,@變數名 資料類型,……]

變數賦值使用Select語句,未賦值的變數其值為Null。

舉例:

Declare @msg char(50)

Select @msg=’How are you?’

Select @msg=emp_name from employee

Where emp_id=12345678

2.SQL語句塊

Begin

Statement Block/*多個順序執行的SQL 陳述式*/

End

3.條件陳述式

If 條件運算式

語句(塊)

Else

語句(塊)

舉例:

if(select max(id) from sysobjects)<50

print ‘資料庫裡沒有使用者建立的對象‘

else

select name,type,id from sysobjects where id>50

4.迴圈語句

While 條件運算式

語句(塊)

●兩個特殊的迴圈控制語句:

Continue 執行下一次迴圈

Break 退出當前迴圈

舉例:

While(select avg(price) from titles)>$20

Begin

Update titles set price=price/2

If(select avg(price) from titles)<$40

Break

Else

Continue

End

5.其它控制語句

◇Return語句——無條件結束當前過程,並可返回給調用者的一個狀態值:Return[整數運算式]

◇Print語句

◇RaiseError語句

◇Waitfor語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.