(I've found this which partly answers the question, the declare way would look neater though given that my sql is will be used in oracle and mssql:) Binding variables in dynamic PL/SQL
I have some dynamic sql which I'm executing using syntax like the below:
EXECUTE IMMEDIATE plsql_block USING employeeid, sortname;
and I can then access those variables inside the dynamic sql using :1, :2, etc. Can I use named parameters instead? something like
EXECUTE IMMEDIATE plsql_block USING employeeid => employeeid
and then access them inside the dynamic sql using :employeeid rather than relying on position?
If not my thought is to do something like this at the beginning of the sql:
declare employeeid varchar(15 := :1;
and then I can change my dynamic sql to my hearts content without worrying about positioning.
Is there a better way?
thanks