Sybase 存储过程的创建和执行
--返回值为int的存储过程
create proc testReturn
@tname varchar(12) ,
@tid int output
as
begin
set @tid = (select testid from Mytest where testname=@tname)
return
end
--返回值为varchar的存储过程
create proc testReturnT
@tid int ,
@tname varchar(12) output
as
begin
set @tname = (select testname from Mytest where testid=@tid)
return
end
--可以正确执行
declare @tid int
exec testReturn 'testname', @tid output
select @tid
--本意是想直接输出输出参数
declare @tname varchar(12)
exec @tname = testReturnT 3,@tname output
select @tname
--异常:Implicit conversion from datatype 'INT' to 'VARCHAR' is not allowed. Use the CONVERT function to run this query.
--正确的执行方法
declare @tname varchar(12)
declare @tid int
exec @tid = testReturnT 3,@tname output
select @tid
select @tname
--正确执行
declare @tname varchar(12)
exec testReturnT 3,@tname output
select @tname
--注意:Sybase存储过程执行之后 返回值的存储过程成功与否的Int值
Oracle存储过程的创建和执行
--创建
create PROCEDURE testReturn
(tid in number ,
tname out NOCOPY varchar2 )
as
begin
select testname into tname from testtable where testid =tid;
end testReturn;
SQL存储过程的创建和执行
--创建
CREATE PROCEDURE procReturn
@tid int ,
@tname varchar(12) output
AS
select @tname = testname from test1 where testid=@tid
RETURN
--执行
exec procReturn 2,@tname output