Skip to content
walter-weinmann edited this page Nov 24, 2018 · 3 revisions

PL/SQL versus SQL

The object for the sqlparse is either an SQL object or a PL/SQL block. The SQL object consists of a list of SQL statements. The PL/SQL block also consists of a list of SQL statements but is bracketed with BEGIN and END in a block. The SQL statements must be terminated with a semicolon with the exception of the SQL object, which consists of only one SQL statement. PL/SQL blocks can be nested at any depth. Not all SQL statements are allowed for both SQL and PL/SQL blocks. For example, the PL/SQL block must not contain DDL statements and the SQL object must not contain COMMIT or ROLLBACK.

Statements only valid in an SQL object

The following SQL statements are only allowed in one SQL object because they are DDL statements:

  • alter_user_def
  • create_index_def
  • create_role_def
  • create_table_def
  • create_user_def
  • drop_index_def
  • drop_role_def
  • drop_table_def
  • drop_user_def
  • grant_def
  • revoke_def
  • truncate_table
  • view_def

Statements only valid in an PL/SQL block

The following SQL statements are pure PL/SQL statements:

  • assignment_statement
  • close_statement
  • commit_statement
  • cursor_def
  • fetch_statement
  • function_ref
  • open_statement
  • procedure_call
  • rollback_statement
  • WHENEVER NOT FOUND
  • WHENEVER SQLERROR

SQL statements valid everywhere

The following DML statements are valid both in the SQL object and in the PL/SQL block:

  • delete_statement_positioned
  • delete_statement_searched
  • insert-statement
  • update_statement_positioned
  • update_statement_searched