0
我想在我的Teradata宏SQL中使用變量。如何在Teradata SQL宏中使用變量
我想我可以做類似如下:
REPLACE MACRO DbName.MyMacro
(
MacroNm VARCHAR(50)
)
AS
(
/* Variable to store last time the macro was run */
DECLARE V_LAST_RUN_DATE TIMESTAMP;
/* Get last run date and store in V_LAST_RUN_DATE */
SELECT LastDate
INTO V_LAST_RUN_DATE
FROM DbName.RunLog
WHERE MacroNm = :MacroNm;
/* Update the last run date to now and save the old date in history */
EXECUTE MACRO DbName.RunLogUpdater(
:MacroNm
,V_LAST_RUN_DATE
,CURRENT_TIMESTAMP
);
);
然而,沒有工作,所以我想到了這一點,而不是:
REPLACE MACRO DbName.MyMacro
(
MacroNm VARCHAR(50)
)
AS
(
/* Variable to store last time the macro was run */
CREATE VOLATILE TABLE MacroVars AS
(
SELECT LastDate AS V_LAST_RUN_DATE
FROM DbName.RunLog
WHERE MacroNm = :MacroNm;
)
WITH DATA ON COMMIT PRESERVE ROWS;
/* Update the last run date to now and save the old date in history */
EXECUTE MACRO DbName.RunLogUpdater(
:MacroNm
,SELECT V_LAST_RUN_DATE FROM MacroVars
,CURRENT_TIMESTAMP
);
);
我可以做什麼我尋找一個存儲過程,但我想避免性能。
你對此有什麼想法?
還有什麼我可以嘗試嗎?
乾杯
添
出於好奇,存儲過程會導致哪些性能問題? – lins314159 2010-04-22 23:30:35