![]() | |
#11
| |||
| |||
|
|
I noted that the sql statement he is building would have access to any variables that are in scope within the do_something procedure..... |
|
The fact that the *function* is not in scope, even though in virtually any other language a construct such as that would be in scope, and indeed even though pl/sql itself is able to recognize some items (local variables) * as being in scope, and indeed even though pl/sql itself has at least one work around for another kind of object (types) so as to make it _appear_ to be in scope even when it isn't - the fact that the function is not in scope is a limitation of the implementation of the pl/sql language. |
so they obviously should be treated differently.
#12
| |||
| |||
|
|
Right, the local variable is visible - the function is not. *The difference is there only for direct usage of both - when using EXECUTE IMMEDIATE you're lost in both cases. |
#13
| |||
| |||
|
#14
| |||
| |||
|
|
On Feb 23, 8:02 pm, Robert Klemme <shortcut... (AT) googlemail (DOT) com> wrote: Right, the local variable is visible - the function is not. The difference is there only for direct usage of both - when using EXECUTE IMMEDIATE you're lost in both cases. Not really: you can still reference your PL/SQL variables with EXECUTE IMMEDIATE - but you need to explicitly bind them yourself (which PL/ SQL does for you automatically with native SQL): declare v sys.dual.dummy%type; x sys.dual.dummy%type := 'X'; begin execute immediate 'select dummy from sys.dual where dummy=:x' INTO v USING x; dbms_output.put_line(v); end; / |
#15
| |||
| |||
|
|
On 25.02.2009 21:39, Bobby Z. wrote: On Feb 23, 8:02 pm, Robert Klemme <shortcut... (AT) googlemail (DOT) com> wrote: Right, the local variable is visible - the function is not. *The difference is there only for direct usage of both - when using EXECUTE IMMEDIATE you're lost in both cases. Not really: you can still reference your PL/SQL variables with EXECUTE IMMEDIATE - but you need to explicitly bind them yourself (which PL/ SQL does for you automatically with native SQL): declare * v sys.dual.dummy%type; * x sys.dual.dummy%type := 'X'; begin * execute immediate 'select dummy from sys.dual where dummy=:x' * * *INTO v * * USING x; * dbms_output.put_line(v); end; / Maybe my wording was a bit too sloppy. *Of course we are not lost because there is a solution. *But: The statement in EXECUTE IMMEDIATE still does not have access to local or private variables. *Instead, you propagate their values into the statement via the bind variable mechanism. *That's similar how a function gets "access" to local variables defined outside: you hand their values into the function via parameters. *No real access to local variables either. Regards * * * * robert |
![]() |
| Thread Tools | |
| Display Modes | |
| |