lunedì 24 luglio 2023

ODI 12c - How to Program Conditional Clauses Using ODI Substitution Methods

Come rendere una procedura ODI dinamica durante la chiamata da parte dell'Agent.Supponiamo di dover effettuare la insert in una tabella leggendo una select che occorre comporre in maniera dinamica ad ogni chiamata a seconda del valore di input. Il che vuol dire che se io ho in input ad esempio un valore leggo dalla tabella A altrimenti leggo dalla tabella B e cosi' via.

How to make an ODI procedure dynamic during the call by the Agent. Suppose we have to insert into a table by reading a select that must be composed dynamically at each call according to the input value. Which means that if I have a value as input, for example, I read from table A, otherwise I read from table B and so on.

INSERT INTO <....>

if valore di input A1 then

SELECT A1 FROM A1

if valore di input A2 then

SELECT A1 FROM A2 

...

if valore di input An-1 then

SELECT A1 FROM An-1

if valore di input An then

SELECT A1 FROM An;

O magari vogliamo rendere un pezzo di una procedura dinamico in base a quanto viene fornito in input. Per ottenere quanto indicato sopra possiamo ad esempio procedere nei seguenti modi:

Or maybe we want to make a piece of a procedure dynamic based on what is provided as input. To obtain the above we can for example proceed in the following ways:

INSERT INTO TEST1  (    JOB_ID,    CRMT_CAPDATE,    CRMT_INSDATE  )

<$

 if  (#PROJECT.JOB_ID == 1) {$> SELECT '1' JOB_ID, SYSTIMESTAMP CRMT_CAPDATE, SYSTIMESTAMP CRMT_INSDATE FROM A1 <$}

 else if  (#PROJECT.JOB_ID == 2) {$> SELECT '2' JOB_ID, SYSTIMESTAMP CRMT_CAPDATE, SYSTIMESTAMP CRMT_INSDATE FROM A2 <$}

 else if  (#PROJECT.JOB_ID == 3) {$> SELECT '3' JOB_ID, SYSTIMESTAMP CRMT_CAPDATE, SYSTIMESTAMP CRMT_INSDATE FROM A3 <$}

 else if  (#PROJECT.JOB_ID == 4) {$> SELECT '4' JOB_ID, SYSTIMESTAMP CRMT_CAPDATE, SYSTIMESTAMP CRMT_INSDATE FROM A4 <$}

 $>     

In questo caso a seconda del valore assunto dalla variabile JOB_ID viene eseguita una ed una sola delle select presenti. Avremo quindi in fase di execution la seguente sostituzione nel caso in cui in input ricevessimo JOB_ID=1: 

In this case, depending on the value assumed by the JOB_ID variable, one and only one of the selects present is performed. We will therefore have the following substitution in the execution phase if we receive JOB_ID=1 as input:

INSERT INTO TEST1  (JOB_ID,ODI_STEP,ODI_NAME) SELECT '1' JOB_ID, SYSTIMESTAMP CRMT_CAPDATE, SYSTIMESTAMP CRMT_INSDATE FROM A1      

Altro modo di scrivere quanto indicato sopra, nel caso in cui input abbiamo un varchar e non un number è il seguente, invece di utilizzare la doppia uguaglianza "==" si può utilizzare il richiamo di una funzione ODI:

INSERT INTO TEST1  (    JOB_ID,    CRMT_CAPDATE,    CRMT_INSDATE  )

<@ 

if  ("#JOB_ID".equals("A1") {@> 

SELECT '1' JOB_ID, CRMT_CAPDATE, CRMT_INSDATE  FROM A1 <@}

else if  ("#JOB_ID".equals("A2") {@> 

SELECT '1' JOB_ID, CRMT_CAPDATE, CRMT_INSDATE  FROM A2 <@}

else if  ("#JOB_ID".equals("A3") {@> 

SELECT '1' JOB_ID, CRMT_CAPDATE, CRMT_INSDATE  FROM A3 <@}

else if  ("#JOB_ID".equals("A4") {@> 

SELECT '1' JOB_ID, CRMT_CAPDATE, CRMT_INSDATE  FROM A4 <@}

 @>     


Di seguito la nota del supporto che spiega il meccanismo di scambio:

Below is the support note explaining the swap mechanism:

· How to Program Conditional Clauses Using ODI Substitution Methods ? (Doc ID 424038.1)











Nessun commento:

Posta un commento