0

I have the following statement. When I don't use the substring function I get over 20 rows selected. When I use this statement I get zero. I'm just wondering what I would need to fix in this statement to achieve the same results.

SQL> select * from
  2  (select
  3  sql_fulltext, executions
  4  from v$sql
  5  order by elapsed_time desc)
  6  where substr(sql_fulltext,1,30) like '%table_name%';
3
  • 1
    Does table_name appear in the first 30 characters? Commented Sep 29, 2013 at 13:29
  • May be stupid comment, but is the string "table_name" in the first 30 characters of sql_fulltext? Commented Sep 29, 2013 at 13:29
  • No it doesn't. Here is the Q I'm trying to solve "2. Display the SQL statements (first 30 characters only) and the number of executions for all SQL commands that have been executed for those SQL statements that include the word table_name.(Hint – Escape clause)" Commented Sep 29, 2013 at 13:30

1 Answer 1

1
select * from
(select
  sql_fulltext
, substr(sql_fulltext,1,30) ShortText
, executions
from v$sql
order by elapsed_time desc)
where sql_fulltext like '%table_name%'

So select in the full name, and use ShortName for the result.

Sign up to request clarification or add additional context in comments.

2 Comments

There is no need for the derived table, the where condition can be applied directly.
Agree, @a_horse_with_no_name, but did not want to confuse the issue. Was not sure if golf_pro90 might have it there for a different reason.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.