next up previous
Next: Dynamic create, drop etc. Up: No Title Previous: Executing non-query statements

Executing a dynamic update

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;
/
show errors



Dr. Raj Sunderraman
7/8/1998