【问题标题】:Stored Procedure with parameters/variables - how to get result from procedure execution?带有参数/变量的存储过程 - 如何从过程执行中获取结果?
【发布时间】:2011-09-18 03:59:37
【问题描述】:

关于存储过程的问题:
如何从声明为输出变量的存储过程中检索变量的值。 运行程序为:

EXEC pn_investment_type_eqt {args}

这里是存储过程:

create proc pn_investment_type_eqt
(
 @product_type varchar(10),
 @country varchar(10),
 @fi_treatment varchar(1)= '',
 @investment_type varchar(10) output,
 @investment_description varchar(50) output
)
as
 set nocount on

if @country <> 'US'
   select @country = 'FOREIGN'

if ( @fi_treatment not in ('Y','N') )
   select @fi_treatment = 'N'

if not exists(select 1 from d_investment_type_eqt
              where product_type = @product_type and isNull(country,'') = isNull(@country,'') and fi_treatment = @fi_treatment and row_status='A' )
begin
  select @country = 'ANY'
end

if exists ( select 1 from d_investment_type_eqt
            where product_type = @product_type and isNull(country,'') = isNull(@country,'') and fi_treatment = @fi_treatment and row_status='A' )
begin
   select @investment_type= investment_type , @investment_description = description
   from d_investment_type_eqt
   where product_type = @product_type and isNull(country,'') = isNull(@country,'') and fi_treatment = @fi_treatment and row_status='A'

end
 else
   return (-1)

我需要获取@investment_type 和@investment_description 的值。

我无法更改程序。

我正在使用 Spring 2.0 的 jdbcTemplate 的自定义实现(sql、mapper、args)

数据库是 Sybase

我怎样才能从这个存储过程中得到结果?

【问题讨论】:

  • "if @country 'US' select @country = 'FOREIGN'"... 这适用于 so 多个级别! :o)

标签: java sql spring stored-procedures sybase


【解决方案1】:

看看这个sybase-in-and-out-parameters的帖子,它可能对你有进一步的帮助。

【讨论】:

  • 谢谢,我试试。 (CallableStatement)
【解决方案2】:

我决定使用下一个设计

declare @investment_type_value varchar(10)
declare @investment_description_value varchar(50)
SET @investment_type_value = '3041'

EXEC global..pn_investment_type_eqt 'CVPFDST', 'US', 'N', @investment_type = @investment_type_value output , @investment_description = @investment_description_value OUTPUT
select  investment_type = @investment_type_value, investment_description = @investment_description_value
GO

它让我有可能检索变量值。

【讨论】:

    猜你喜欢
    • 2018-03-24
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 2021-03-27
    相关资源
    最近更新 更多