Creating a SQL Profile Manually
dmann — Wed, 02/04/2009 - 16:26
The following SQL Profile adds a FIRST_ROWS every time it sees the query specified by SELECT...%. You will need to update the WHERE Clause of the SELECT below. Verify that it returns the SQL you are expecting and that the query only returns one row.
Obtain the SQL_ID of the SQL you would like to create a profile for:
It is easier to obtain the SQL_ID instead of trying to cut and paste the text of the whole statement. Often the SQL text is too cumbersome to cut and paste reliably, so why not grab it from the sqlarea?
SELECT sql_id,
sql_text
FROM gv$sqlarea
WHERE sql_text LIKE 'SELECT...%';
Implement the profile:
DECLARE
cl_sql_text CLOB;
BEGIN
SELECT sql_text
INTO cl_sql_text
FROM gv$sqlarea where sql_id = '&myid.';
DBMS_SQLTUNE.IMPORT_SQL_PROFILE(sql_text => cl_sql_text,
profile => sqlprof_attr('FIRST_ROWS'),
name => 'FIRST_ROWS_TEST',
category => 'DEFAULT',
force_match => TRUE);
end;
/
