5

I am trying to call a PL/SQL block with ADO and VBA, but I can't pass input and/or output bind variables (probably aka parameters).

dim cn as ADODB.connection
' ... open connection ...

dim plsql as string

plsql =         "declare"
plsql = plsql & "  num_in  number := ?;"
plsql = plsql & "  num_out number; "
plsql = plsql & "begin"
plsql = plsql & "  num_out := num_in * 5;"
plsql = plsql & "  ? := num_out;"
plsql = plsql & "end;"

dim cm as ADODB.command
set cm = new ADODB.command
set cm.activeConnection = cn
cm.commandText = plsql
cm.commandType = adCmdText

cm.parameters.append cm.createParameter(, adDouble, adParamInput,, 5)
cm.parameters.append cm.createParameter(, adDouble, adParamOutput   )

cm.execute  ' FAILS HERE

msgBox(cm.parameters(2))

The snippet above fails at the cm.execute line with an ORA-01008: not all variables bound

I'd appreciate any help towards a solution for my problem.

3
  • I' not sure Oracle allows you to define variables inside the anonymous PL/SQL block like that. What are you trying to do? Mar 3, 2010 at 20:06
  • This is obviously a trimmed down version of what I actually want to achieve. The real thing is to instantiate a PL/SQL object type, to pass the instance to a procedure, and then to evaluate a few methods and memeber on the object type afterwards. Mar 3, 2010 at 20:18
  • Very good question...the infinitely weird ways in which oracle and ado get in conflict are infinitely many...
    – mic.sca
    Oct 26, 2011 at 13:42

1 Answer 1

6

It seems as though the statement cannot start with a declare. (Thanks to Thomas Jones-Low for his valuable comment).

So, the statement must be enclosed in another begin .. end block:

' additional begin so that the statement does not start with a declare:
plsql =         "begin "

plsql = plsql & "declare"
plsql = plsql & "  num_in  number := ?;"
plsql = plsql & "  num_out number; "
plsql = plsql & "begin"
plsql = plsql & "  num_out := num_in * 5;"
plsql = plsql & "  ? := num_out;"
plsql = plsql & "end;"

' closing the additional begin:
plsql = plsql & "end;"

Now, it works as expected.

1
  • geez, you saved my day! Good Job! thank you! Totally stupid behaviour. How did you come to this solution?
    – mic.sca
    Oct 26, 2011 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.