简体   繁体   English

SAP HANA SQL:准备语句

[英]SAP HANA SQL: Prepare statement

Why can't I execute this query in SAP HANA in SQL console 为什么我不能在SQL控制台的SAP HANA中执行此查询

PREPARE stmt1
FROM select * from (select '12' as a from dummy) t1
where t1.a = ?; 

Error: 错误:

Could not execute 'PREPARE stmt1 FROM select * from (select '12' as a from dummy) t1 where t1.a = ?' 无法执行'PREPARE stmt1 FROM select * from(选择'12'作为哑元)a t1其中t1.a =?' in 3 ms 339 µs . 在3 ms 339 µs内。 SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "PREPARE": line 1 col 1 (at pos 1) SAP DBTech JDBC:[257]:sql语法错误:“ PREPARE”附近的语法不正确:第1行第1行(在pos 1)

I need using prepare statement in stored procedure. 我需要在存储过程中使用prepare语句。

PREPARE simply is not valid SQLScript syntax. PREPARE根本不是有效的SQLScript语法。 Not sure why you think you have to use this in a stored procedure. 不知道为什么您认为必须在存储过程中使用它。 In SAP HANA stored procedures you can simply write your SQL statements including any variables. 在SAP HANA存储过程中,您可以简单地编写包含任何变量的SQL语句。 Eg 例如

select * from (select '12' as a from dummy) t1
where t1.a = :variable_name; 

is technically valid - even though the result is only assigned to the default result set. 在技​​术上是有效的-即使结果仅分配给默认结果集。 Typically you would assign the result to a table variable like this: 通常,您会将结果分配给一个表变量,如下所示:

x = select * from (select '12' as a from dummy) t1
where t1.a = :variable_name;

All this is of course explained in the SAP HANA documentation for SQLScript . 当然,所有这些在SQLSAP HANA文档中都有说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM