I want to capture the auditing inside the stored procedure for the merge and insert statements and i have tried using Result_Scan by getting Query ID from the QUERY_HISTORY by session. But these statements are not allowed in the JavaScript procedure. Then i have created a function for getting Query ID for the latest executed SQL queries.
create or replace function GET_QUERY_ID()
RETURNS VARCHAR
AS 'SELECT QUID FROM (SELECT (QUERY_ID)::VARCHAR AS QUID FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY_BY_SESSION(CURRENT_SESSION()::NUMBER)) WHERE QUERY_TYPE IN (''INSERT'',''MERGE'') ORDER BY END_TIME DESC ) LIMIT 1';
And tried for creating another function for row count
create or replace function GET_RESULT_SCAN(P_QUERY_ID VARCHAR)
RETURNS TABLE ( INSERT_ROWS NUMBER ,UPDATED_ROWS NUMBER)
AS 'select * from (select "number of rows updated"::NUMBER as INSERT_ROWS, "number of multi-joined rows updated"::NUMBER as UPDATED_ROWS from table(result_scan(P_QUERY_ID)))';
But this is not working and these functions i can't call in the stored procedure created with JavaScript. Kindly let me know the best practice to capture the auditing on the number of rows inserted and updated in stored procedure. Assume in a stored procedure there are 5-10 SQL statements.