Comment utiliser des variables dans Teradata SQL Macros

Je suis désireux d'utiliser des variables à l'intérieur de ma macro SQL sur Teradata.

Je pensais que je pouvais faire quelque chose comme ce qui suit:

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  
   );  

);  

Toutefois, cela ne fonctionne pas, alors j'ai pensé à ceci à la place:

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  
   );  

);  

Je peux faire ce que je suis à la recherche d'une Procédure Stockée, mais je tiens à éviter pour la performance.

Vous avez des idées à ce sujet?

Est-il autre chose que je peux essayer?

Acclamations

Tim

  • Par curiosité, ce que les problèmes de performances de votre procédure stockée causer?
InformationsquelleAutor Tim | 2010-04-22