我是靠谱客的博主 个性含羞草,最近开发中收集的这篇文章主要介绍sybase procedures and cursorsHow to view stored procedure spec? How to view the source of stored procedure? Super simple procedure exampleSimple cursor example—key sqls are highlighted ,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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.

最后

以上就是个性含羞草为你收集整理的sybase procedures and cursorsHow to view stored procedure spec? How to view the source of stored procedure? Super simple procedure exampleSimple cursor example—key sqls are highlighted 的全部内容,希望文章能够帮你解决sybase procedures and cursorsHow to view stored procedure spec? How to view the source of stored procedure? Super simple procedure exampleSimple cursor example—key sqls are highlighted 所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部