SAP HANA DB에서 변수 사용하는 방법
2022. 11. 16. 14:45ㆍProgramming
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
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;
반응형
'Programming' 카테고리의 다른 글
python virtual environments 파이썬 가상환경 세팅 (설치, activate, deactivate, 제거) (0) | 2022.11.18 |
---|---|
Python Counter, sorted로 정렬하기 (0) | 2022.11.17 |
Amazon SageMaker conda 가상환경 세팅하는 방법 (0) | 2022.11.03 |
Hadoop 하둡에서 데이터베이스, 테이블, 데이터 다루기 (0) | 2022.10.23 |
python 조합, 순열 (combinations, permutations), 프로덕트(product) (0) | 2022.09.30 |