Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does dbms_sql.parse containing incorrect PL/SQL block with bind variables succeed unexpectedly?

Tags:

The PL/SQL block below fails as expected:

SQL> declare
  2    i int;
  3  begin
  4    i := dbms_sql.open_cursor;
  5    dbms_sql.parse(i,'begin dontexist; dbms_output.put(''a''); end;',1);
  6    dbms_sql.close_cursor(i);
  7  end;
  8  /
declare
*
FOUT in regel 1:
.ORA-06550: Regel 1, kolom 7:
PLS-00201: identifier 'DONTEXIST' must be declared.
ORA-06550: Regel 1, kolom 7:
PL/SQL: Statement ignored.
ORA-06512: in "SYS.DBMS_SQL", regel 1120
ORA-06512: in regel 5

Because I don't have a procedure called DONTEXIST. My question is then why does this next PL/SQL block complete successfully?

SQL> declare
  2    i int;
  3  begin
  4    i := dbms_sql.open_cursor;
  5    dbms_sql.parse(i,'begin dontexist; dbms_output.put(:a); end;',1);
  6    dbms_sql.close_cursor(i);
  7  end;
  8  /

PL/SQL-procedure is geslaagd.

The difference is the use of the bind variable instead of a constant, but I'd like to know why this makes a difference.

This is Oracle 12.1.0.2

like image 320
Rob van Wijk Avatar asked Aug 22 '17 07:08

Rob van Wijk


1 Answers

Looks like the parse is only syntactic for anon blocks with binds, and the full semantic check is deferred until execution.

Still, that's not a behaviour we want so Bug 26669757 raised.

like image 173
Connor McDonald Avatar answered Oct 11 '22 13:10

Connor McDonald