数据库 HANA 错误:无法使用参数变量

问题描述 投票:0回答:2

我正在尝试使用下面的代码将值插入到我的临时表中。

我收到了这个错误

SAP Hana 数据库错误:不能 使用参数变量:DOCENTRY: line 8 col 35 (at pos 127) 2 0

我不知道出了什么问题, 请给一些建议 谢谢

这是代码:

CREATE PROCEDURE REP_PROC11( in docentry nvarchar(2))
AS 

totalval DECIMAL (19,6);


BEGIN
CREATE local TEMPORARY  TABLE #TempItem AS (
select
'FGA000001' as "ItemCode",
'2IN' as "WhsCode",
ifnull(
(
    select 
        "U_IM1_GR"
    from "@OFNC" where "DocEntry"  = :docentry
),0) as "Qty",
'11080302' as "Account",
'S02' as "ProfitCode",
'IN-PN' as "ProfitCode2" 
from DUMMY

union all

select
'FGA000002' as "ItemCode",
'2IN' as "WhsCode",
ifnull(
(
    select 
        U_IM2_GR 
    from "@OFNC" where "DocEntry"  = :docentry
),0) as "Qty",
'11080302' as "Account",
'S02' as "ProfitCode",
'IN-FN' as "ProfitCode2" from dummy);

SELECT X.*, (X."Qty"*:totalval)/Y."TotalQty" as "Val", :totalval as "TotalVal"
FROM #TempItem X
    LEFT JOIN (SELECT SUM(X1."Qty") as "TotalQty" FROM #TempItem X1) Y ON 1 = 1
WHERE X."Qty" > 0;

drop TABLE #TempItem;
end
sql hana
2个回答
0
投票

这是 DDL 代码中 SQL 的限制 -

CREATE TEMPORARY TABLE
位。

鉴于您到目前为止的代码,您不需要使用临时变量。表,但通过使用表变量可以产生相同的结果(资源使用更少)。


0
投票

对于下一个来的人,仍然可以通过以下两步方法来完成:

--create empty table
  
CREATE local TEMPORARY  TABLE #TempItem AS (SELECT * FROM MY_TABLE WHERE 1 < 0);

 --populate it

INSERT INTO #TempItem VALUES(SELECT * FROM MY_TABLE WHERE my_field = :my_input_param)
© www.soinside.com 2019 - 2024. All rights reserved.