简体   繁体   中英

SAP HANA SQL: Prepare statement

Why can't I execute this query in SAP HANA in SQL console

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 = ?' in 3 ms 339 µs . SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "PREPARE": line 1 col 1 (at pos 1)

I need using prepare statement in stored procedure.

PREPARE simply is not valid SQLScript syntax. 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. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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