sybase procedures and cursors

How to view stored procedure spec?

 

sp_help ${stored_procedure_name}

 

How to view the source of stored procedure?

 

sp_helptext ${stored_procedure_name}

 

 

Super simple procedure example

 

 

DECLARE @ricCode VARCHAR(20)

 

BEGIN

      SELECT @ricCode = '9779.HK'

      PRINT @ricCode

END

 

 

Simple cursor example—key sqls are highlighted

 

use DRMS

go --sybase sqls are sparated by go, which database are you using. There is no ; in sybase

 

CREATE UNIQUE INDEX ExchangeAccountParam_IDX on ExchangeAccountParam  ( id, parameter )

go

 

DECLARE attrCursor CURSOR

FOR SELECT parameter, value FROM ExchangeAccountParam WHERE id = 4 for update

go -–this go could contain nothing else, only this cursor declare

 

DECLARE @ricCode     VARCHAR(20),

        @brokerId    VARCHAR(20),

        @securityId  INTEGER

   

    OPEN attrCursor 

 

    FETCH attrCursor INTO @ricCode, @brokerId

       

    WHILE (@@sqlstatus = 0)

    BEGIN

        --Get securityId from ricCode

        SELECT @securityId = id FROM ETSalternativeIdentifier WHERE altId = @ricCode

           

        IF @securityId  IS NULL

            SELECT @ricCode, @brokerId, @securityId, 'NULL securityId--Give up!'

        ELSE IF @brokerId = 'HM091'

        BEGIN -- if there are several sqls in this block, must be surrounded by BEGIN/END

            SELECT @ricCode, @brokerId, @securityId, 'Insert HKG-MM,HM091!'

            INSERT INTO QuoterConfigParam VALUES (35, @securityId, @ricCode, 'HKG-MM,HM091')

        END       

        ELSE IF @brokerId = 'HM092'

        BEGIN

            SELECT @ricCode, @brokerId, @securityId, 'Insert TCMECS,HM092!'

            INSERT INTO QuoterConfigParam VALUES (35, @securityId, @ricCode, 'TCMECS,HM092')

        END 

        ELSE IF @brokerId = 'HM093'

        BEGIN

            SELECT @ricCode, @brokerId, @securityId, 'Insert TCMECS,HM093!'

            INSERT INTO QuoterConfigParam VALUES (35, @securityId, @ricCode, 'TCMECS,HM093')

        END 

       

        FETCH attrCursor INTO @ricCode, @brokerId

    END       

    CLOSE attrCursor

go

 

DEALLOCATE CURSOR attrCursor

go -- destroy the cursor

 

 

 

for update and for read only

 

select * from test for update

for update means I am going to change the content of this line, add a lock at it!

 

select * from test for read only

for read only means I simply need to read the line, no lock is needed.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值