SAP HANA DB에서 변수 사용하는 방법

2022. 11. 16. 14:45Programming

728x90

SAP HANA에서 SQL을 작성할 때 변수를 사용하고 싶을 때가 많다.

쿼리에 공통적으로 자주 사용하는 날짜, id값 등을 변경할 때마다 모든 쿼리를 수정해야하는 상황을 피하기 위해서다.

변수는 아래와 같이 사용하는 방법들이 있다.

 

Do begin

DECLARE target_cust varchar(25) = '123124123'; -- one value variable
 
SELECT *
FROM DATA
WHERE "CUST_ID" = :target_cust
limit 5;

end

출처: http://www.bestsaphanatraining.com/how-to-assign-a-query-to-a-sap-hana-variable-and-use-it-as-a-view.html

 

Sap Hana Tutorials and Training

Bestsaphanatraining is looking at giving sap hana solutions at various levels to everyone. On one hand, tutorial and training sites have been selected for their good and rich content anyone can learn from. Paying fee courses are providing more in depth sap

www.bestsaphanatraining.com

Do begin -- Simple use of a query syntax from a variable
-- ---------------------------------------------
-- Note : The variable is not declared anywhere
-- ---------------------------------------------
it_user_list = select b.host, b.service_name, a.state, count(*) from "PUBLIC"."M_LOG_SEGMENTS" a join "PUBLIC"."M_SERVICES" b on (a.host = b.host AND a.port = b.port) group by b.host, b.service_name, a.state;


SELECT host,service_name,state FROM :it_user_list;

end
728x90
SET 'target_cust' = '123124123';
 
SELECT *
FROM DATA
WHERE "CUST_ID" = session_context('target_cust')
limit 5;

 

반응형