Returns the last SQL function code, indicating the type of SQL statement. For a list of valid function codes, see your Programmer's Guide to the Oracle Call Interface.
FUNCTION EXEC_SQL.Last_SQL_Function_Code
[Connid IN CONNTYPE]
RETURN PLS_INTEGER;
Connid | Is the handle to the connection you want to use. If you do not specify a connection, EXEC_SQL.Default_Connection retrieves the primary Oracle Developer connection handle from the cache. |
An integer.
Use this function immediately after parsing the SQL statement.
/*
** In this procedure, a statement is passed in and executed. If the statement is a
** select statement, then further processing is initiated to determine the column
** characteristics.
*/
PROCEDURE eslastfunccode(sqlstr VARCHAR2) IS
connection_id EXEC_SQL.CONNTYPE;
cursor_number EXEC_SQL.CursType;
--
-- The values for the function codes is dependent on the RDBMS version.
--
SELECTFUNCCODE PLS_INTEGER := 3;
sql_str VARCHAR2(256);
nColumns PLS_INTEGER := 0;
nFunc PLS_INTEGER := 0;
colName VARCHAR2(30);
colLen PLS_INTEGER;
colType PLS_INTEGER;
BEGIN
connection_id := EXEC_SQL.OPEN_CONNECTION('connection_str');
cursor_number := EXEC_SQL.OPEN_CURSOR(connection_id);
EXEC_SQL.PARSE(connection_id, cursor_number, sql_str, exec_sql.V7);
nIgnore := EXEC_SQL.EXECUTE(connection_id, cursor_number);
--
-- check what kind of function it is
--
nFunc := EXEC_SQL.LAST_SQL_FUNCTION_CODE(connection_id);
IF (nFunc != SELECTFUNCCODE) THEN
RETURN;
END IF;
--
-- proceed to obtain the column characteristics
--
LOOP
nColumns := nColumns + 1;
BEGIN
EXEC_SQL.DESCRIBE_COLUMN(connection_id, cursor_number,
nColumns, colName, colLen, colType);
TEXT_IO.PUT_LINE(' col= ' || nColumns || ' name ' || colName ||
' len= ' || colLen || ' type ' || colType );
EXCEPTION
WHEN EXEC_SQL.INVALID_COLUMN_NUMBER THEN
EXIT;
END;
END LOOP;
EXEC_SQL.CLOSE_CURSOR(connection_id, cursor_number);
EXEC_SQL.LCOSE_CONNECTION(connection_id);
END;