EXECUTE procedure - Run a parsed SQL statement
The EXECUTE function executes a parsed SQL statement.
Syntax
Parameters
- c
- An input argument of type INTEGER that specifies the cursor ID of the parsed SQL statement to be executed.
- ret
- An output argument of type INTEGER that returns the number of rows processed if the SQL command is DELETE, INSERT, or UPDATE; otherwise it returns 0.
Authorization
EXECUTE privilege on the DBMS_SQL module.
Usage notes
This procedure can be invoked using function invocation syntax in a PL/SQL assignment statement.
Examples
Example 1: The following
anonymous block inserts a row into the "DEPT" table.
SET SERVEROUTPUT ON@
CREATE TABLE dept (
deptno DECIMAL(2) NOT NULL CONSTRAINT dept_pk PRIMARY KEY,
dname VARCHAR(14) NOT NULL,
loc VARCHAR(13),
CONSTRAINT dept_dname_uq UNIQUE( deptno, dname )
)@
BEGIN
DECLARE curid INTEGER;
DECLARE v_sql VARCHAR(50);
DECLARE v_status INTEGER;
CALL DBMS_SQL.OPEN_CURSOR(curid);
SET v_sql = 'INSERT INTO dept VALUES (50, ''HR'', ''LOS ANGELES'')';
CALL DBMS_SQL.PARSE(curid, v_sql, DBMS_SQL.native);
CALL DBMS_SQL.EXECUTE(curid, v_status);
CALL DBMS_OUTPUT.PUT_LINE('Number of rows processed: ' || v_status);
CALL DBMS_SQL.CLOSE_CURSOR(curid);
END@
This example results in the following output:
SET SERVEROUTPUT ON
DB20000I The SET SERVEROUTPUT command completed successfully.
CREATE TABLE dept
( deptno DECIMAL(2) NOT NULL CONSTRAINT dept_pk PRIMARY KEY,
dname VARCHAR(14) NOT NULL,
loc VARCHAR(13),
CONSTRAINT dept_dname_uq UNIQUE( deptno, dname ) )
DB20000I The SQL command completed successfully.
BEGIN
DECLARE curid INTEGER;
DECLARE v_sql VARCHAR(50);
DECLARE v_status INTEGER;
CALL DBMS_SQL.OPEN_CURSOR(curid);
SET v_sql = 'INSERT INTO dept VALUES (50, ''HR'', ''LOS ANGELES'')';
CALL DBMS_SQL.PARSE(curid, v_sql, DBMS_SQL.native);
CALL DBMS_SQL.EXECUTE(curid, v_status);
CALL DBMS_OUTPUT.PUT_LINE('Number of rows processed: ' || v_status);
CALL DBMS_SQL.CLOSE_CURSOR(curid);
END
DB20000I The SQL command completed successfully.
Number of rows processed: 1