-----------------------------------------------------------------
-- PL/SQL: DBMS_SQL Package - Executing non-query SQL statement -
--         (Section 4.9.2)                                      - 
-- Chapter 4; Oracle Programming -- A Primer                    -
--            by R. Sunderraman                                 -
-----------------------------------------------------------------

DECLARE
  handle INTEGER;
  stmt varchar2(256);
  discount parts.price%type := 0.8;
  part_number parts.pno%type := 10506;
  nrows INTEGER;
BEGIN

  stmt := 'update parts set price = price * :fract where pno = :pnum';

  handle := DBMS_SQL.OPEN_CURSOR;
  DBMS_SQL.PARSE(handle,stmt,DBMS_SQL.V7);
  DBMS_SQL.BIND_VARIABLE(handle,':fract',discount); 
  DBMS_SQL.BIND_VARIABLE(handle,':pnum',part_number); 
  nrows := DBMS_SQL.EXECUTE(handle);
  dbms_output.put_line('Number of rows updated = ' || nrows);
  DBMS_SQL.CLOSE_CURSOR(handle);

  EXCEPTION
    WHEN OTHERS THEN
      DBMS_SQL.CLOSE_CURSOR(handle);
END;
/
