SYBASE ASE12 5中儲存過程的建立和呼叫

2021-08-31 20:27:13 字數 4714 閱讀 5454

一、建立儲存過程(三個儲存過程:up_sendgroup2->up_sendsms_ex2->up_getsmsrepdisplay)

1、建立儲存過程up_getsmsrepdisplay

create procedure up_getsmsrepdisplay(    

@i_sessionid varchar(100),

@o_displayall varchar(100) output

)

as

begin

declare @displayone varchar(100)

declare @counter int

set @counter=1

declare cur_smsdisplay cursor for

select displayname from ncomsmsreptemp

where sessionid=@i_sessionid

open cur_smsdisplay

fetch cur_smsdisplay into @displayone

while(@@sqlstatus=0 and @counter<=3)

begin

set @displayone=ltrim(rtrim(@displayone))

if(@counter=1)

set @o_displayall=@displayone

else

set @o_displayall=@o_displayall+','+@displayone

set @counter=@counter+1

fetch cur_smsdisplay into @displayone

end

close cur_smsdisplay

if @counter>4

set @o_displayall=@o_displayall+'...'

end

2、建立儲存過程up_sendsms_ex2

create procedure [dbo].[up_sendsms_ex2]       

-- add the parameters for the stored procedure here

@sessionid varchar(100), -- ncomsmsreptemp.sessionid

@msgtext varchar(1024), -- example:this is test message!

@priority int -- values: 1=low 2=normal 3=high

as

begin

declare @smsid varchar(100)

declare @textsize int

declare @accountid varchar(100)

declare @displayallname varchar(100)

--check sp pass in arguments & set it's to default:

if (@priority<>1 and @priority<>2 and @priority<>3)

set @priority=2 --default priority is normal(2)

--prepare some fields' values:

set @smsid=newid() -- get new guid

set @textsize=len(@msgtext)

set @accountid='sysmobile' --set in table 'ncomsmsaccount',must be exists!!

--get displayallname

set @displayallname=''

execute up_getsmsrepdisplay @i_sessionid=@sessionid,@o_displayall=@displayallname output

--add sms master information:

insert into ncomsms

(smsid,

smstype,

direction,

accountid,

fromdisplay,

owner,

priority,

usetemplate,

templateid,

msgtype,

msgtext,

pushurl,

msgsize,

todisplay,

boxtype,

pirorboxtype,

writetime,

sendstate,

retrycount,

sendresult

)

select @smsid,

2, --direction: 1=receive 2=send out

@accountid, --sender's account id

ncomsmsaccount.displayname,

ncomsmsaccount.childgatecode,

@priority,

0, --use template? 0=not use 1=use a template

-1, --template id

0, --msgtype 0=autoselect 1=english 2:chinese

@msgtext,

@textsize,

@displayallname,

2, -- boxtype: 1=writing 2=sending 3=send 4=received 5=deleted

null, --piror box type

getdate(), --writetime

0, --send state 0=is ready 1=in sending queue

0, --retry count

0 --send result -1:failed 0:no_set 1:success 2:partly success

from ncomsmsaccount

where accountid=@accountid

if @@error <>0 return -1

return 1 --return success

end

3、建立儲存過up_sendgroup2

create procedure up_sendgroup2       

-- add the parameters for the stored procedure here

as

begin

declare @msgtext varchar(1024)

declare @sessionid varchar(100)

set @sessionid =newid() -- get new guid

set @msgtext =『儲存過程測試'+cast(getdate() as varchar(30))

exec dbo.up_sendsms_ex2 @sessionid,@msgtext,2

end

呼叫儲存過程up_getsmsrepdisplay如下,這是有輸入引數和返回引數的情況:

declare @sessionid varchar(100) 

declare @displayall varchar(100)

select @sessionid ="1001"

execute up_getsmsrepdisplay @i_sessionid=@sessionid ,@o_displayall=@displayall output

select @displayall

如果沒有引數,直接使用execute執行即可,比如要執行up_sendgroup2就可以直接使用

execute up_sendgroup2

Delphi7中儲存unicode的BUG?

delphi7 中儲存unicode 的bug 近日,在用 delphi7 做unicode 的程式時發現了這樣乙個問題,就是使用 tado mand 元件執行 sql語句時,如果 sql語句中有 unicode 字元,儲存在資料庫裡會出現亂碼,使用 ttntadoquery 也是一樣 使用引數方式...

在Delphi中如何獲得SQL中儲存過程的返回值

示例儲存過程 create procedure proc login username varchar 20 password varchar 20 asdeclare result int select result count from loginuser where user username...

iOS篩選出陣列中想要的資料 陣列中儲存的模型

先用乙個便於理解的方法,表達出想要的結果 首先說一下需要的資料 根據城市的名字,城市的拼音,城市的首字母篩選是否有查詢的城市 zhcity模型 模型中有name 城市名字 pinyin 城市的拼音 pinyinhead 城市首字母 乙個可變的陣列 屬性 self.resultcities 乙個正常的...