I am in the process of migrating from Oracle to Postgres with Ora2pg but I find this problem that the signatures on the Postgres side do not exist
can you help me find the right solution ?
What will be equivalent of following oracle’s query in Postgres?
case
when varSqlSignature = '1239678541' then
execute immediate varSql using
/*1*/rowData.CODE_MOUVEMENT ,/*2*/rowData.TYPE_CALCUL ,/*3*/rowData.MONTANT_CALCUL
,/*9*/rowData.MONTANT_CALCUL_DV ,/*6*/rowData.DATE_CALCUL ,/*7*/rowData.CHAINE_CALCUL
,/*8*/rowData.RESULTAT_CALCUL ,/*5*/varActionType ,/*4*/varLoadDate
,/*1*/rowData.CODE_MOUVEMENT
;
2
Answers
The code you have presented has invalid syntax in Oracle.
It starts with a
CASE
expression which has the syntax:Your statement has
CASE
,WHEN
andTHEN
but no expression after theTHEN
(EXECUTE IMMEDIATE
is not an expression) and noEND
keyword;A
CASE
expression is not, on its own, a valid SQL or PL/SQL statement;Then the code goes into what should be a separate PL/SQL statement to
EXECUTE IMMEDIATE
some dynamic SQL passing some bind variables from a record and should have a;
before theEXECUTE IMMEDIATE
to separate it from the previous statement.A PL/SQL statement should be included in a
DECLARE ... BEGIN ... END;
block but this is not.The variables
varSqlSignature
,varSql
androwData
have not been declared and so we have no idea what what dynamic code would do or what the record contains as it is not included in the question.Therefore, since the statement is invalid in Oracle due to multiple reasons then the equivalent in PostgreSQL would be another invalid statement (or even the same statement).
The code you are showing must be PL/SQL, not SQL.
The incomplete code snippet you are showing would work just fine in PostgreSQL’s PL/pgSQL procedural language if you remove the
IMMEDIATE
keyword (which is just noise anyway).