概述
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 所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复