title: Writing an anonymous PL/SQL block with bind variables using JDBC
body: <p>I have an Anonymous PL/SQL Block with bind variables that I want to run via JDBC.</p>
  
  <p><strong>PL/SQL block example:</strong></p>
  
  <pre><code>variable v_value number
  declare
  v_return varchar2(30);
  begin
  :v_value:=300;
  select ename into v_return from emp where empno=:v_value;
  end;
  </code></pre>
  
  <p>The corresponding Java code would make use of the escape syntax with <strong>"?"</strong> to set the variables. So this block would look like this(correct me if I'm wrong):</p>
  
  <pre><code>String block = "declare v_return varchar2(30);" +
                 "begin" + 
                 "? := 300;" +
                 "select ename into v_return from emp where empno = ?;" +
                 "end;"
  </code></pre>
  
  <p>Now, assuming that my variable is an INPUT parameter, I'll have to set the parameter like this:</p>
  
  <pre><code>// omitting the CallableStatement and conn declarations
  cs = conn.prepareCall(block);
  
  cs.setInt(parameterIndex, parameterValue);
  </code></pre>
  
  <p>The PROBLEM is that in my block I have two <strong>"?"</strong> used to replace the bound parameter :v_value. This means that when using the escape syntax only the 1'st <strong>"?"</strong> will be set. The 2'nd <strong>"?"</strong> will be left "hanging".</p>
  
  <p><strong>In such cases, when the same bind variable(s) is used multiple times in a PL/SQL block, how should I proceed with translating this in JDBC escape syntax?</strong></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/15539051/error-when-a-named-parameter-used-multiple-times-in-jdbc-pl-sql-block?rq=1">question</a> on SO that is related to my problem. What I understand from it is that I'll have to <strong>REWRITE</strong> all Anonymous PL/SQL Blocks that make use of multiple bind variable instances in the same block. Is there ANY workaround for this? Or this is it... game over... it's the way JDBC works and I'll have to make due.</p>
  
  <p><br/>
  <br/>
  Looking forward for an answer... searched for this for 2 hours with no results.</p>