How to obtain the SQL statement that does not use the bound variable in the oracledeskpool

Source: Internet
Author: User
The website provides the remove_constants function to check the SQL running status in the shared pool. The solution is to change the query condition value to a common tag, for example, select * fr.

The website provides the remove_constants function to check the SQL running status in the shared pool. The solution is to change the query condition value to a common tag, for example, select * fr.

The website provides the remove_constants function to check the SQL running status in the shared pool. The solution is to change the query condition value to a common tag, for example: replace select * from t where object_id = 1 with select * from t where object_id = @.

SQL> drop table find_no_bind purge;
SQL> create table t as select * from dba_objects where 1 = 2;

-- Create a record table
SQL> create table find_no_bind as select SQL _text from v $ sqlarea;
SQL> alter table find_no_bind add SQL _text_copy varchar2 (1000 );

-- Create a replacement function and replace the placeholder @
Create or replace function
SQL> remove_constants (p_query in varchar2) return varchar2
As
Rochelle query long;
Rochelle char varchar2 (1 );
Rochelle in_quotes boolean default FALSE;
Begin
For I in 1 .. length (p_query)
Loop
L_char: = substr (p_query, I, 1 );
If (l_char = ''' and l_in_quotes)
Then
Rochelle in_quotes: = FALSE;
Elsif (l_char = ''' and NOT l_in_quotes)
Then
Rochelle in_quotes: = TRUE;
L_query: = l_query | '''#';
End if;
If (NOT l_in_quotes) then
L_query: = l_query | l_char;
End if;
End loop;
Rochelle query: = translate (Rochelle query, '123 ','@@@@@@@@@@');
For I in 0 .. 8 loop
Rochelle query: = replace (l_query, lpad ('@', 10-i ,'@'),'@');
Rochelle query: = replace (l_query, lpad ('', 10-i ,''),'');
End loop;
Return upper (l_query );
End;
/


-- Clear the share pool first. The formal environment cannot do this.

SQL> alter system flush shared_pool;


SQL> begin
For I in 1 .. 1000 loop
Execute immediate 'select * from t where OBJECT_ID = '| I;
End loop;
End;
/


SQL> update find_no_bind set SQL _text_copy = remove_constants (SQL _text );

SQL> commit;


SQL> col SQL _text_copy format a40
SQL> select SQL _text_copy, count (*)
2 from find_no_bind
3 group by SQL _text_copy
4 having count (*)> 10;
SQL _TEXT_COPY COUNT (*)
--------------------------------------------------
SELECT * from t where OBJECT_ID = @ 1000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.