Home » SQL & PL/SQL » SQL & PL/SQL » converting clob to varchar2 (SQL/PLSQL)
converting clob to varchar2 [message #607961] Thu, 13 February 2014 22:48 Go to next message
gautham.gn
Messages: 1
Registered: February 2014
Location: Bangalore
Junior Member
I want to compare a particular column with trigger_body in user_triggers table. But that column is having varchar2 datatype and trigger body has clob datatype. So it is throwing an error. Can u please solve it to me??

The query looks like
SELECT TR.trigger_name, 
       COL.column_name, 
       TR.trigger_body 
FROM   user_triggers TR 
       inner join user_tab_columns COL 
               ON COL.table_name = TR.table_name 
WHERE  TR.trigger_name LIKE 'TH_%' 
       AND TR.trigger_name NOT LIKE 'THC%' 
       AND TR.trigger_name NOT LIKE 'THS%' 
       AND Upper(TR.trigger_body) NOT LIKE '%' 
                                           ||Upper(COL.column_name) 
                                           ||'%' 
ORDER  BY trigger_name 


Thanks,
Gautham

*BlackSwan added {code} tags & formatting. Please do so yourself in the future.

[Updated on: Thu, 13 February 2014 23:13] by Moderator

Report message to a moderator

Re: converting clob to varchar2 [message #607974 is a reply to message #607961] Fri, 14 February 2014 00:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68644
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

It is NOT a CLOB it is a LONG and you can't anything with a LONG in SQL.
If your LONG is smaller than 32K you can write a PL/SQL function which will convert the LONG to a VARCHAR2.
If not, you have to use an external program.

Re: converting clob to varchar2 [message #607981 is a reply to message #607974] Fri, 14 February 2014 00:55 Go to previous messageGo to next message
saipradyumn
Messages: 419
Registered: October 2011
Location: Hyderabad
Senior Member



Following is alternate query for your requirement



SELECT distinct TR.trigger_name, COL.column_name
  FROM user_triggers TR, user_tab_columns COL, user_source us
 WHERE COL.table_name = TR.table_name
   and TR.trigger_name LIKE 'TH_%'
   AND TR.trigger_name NOT LIKE 'THC%'
   AND TR.trigger_name NOT LIKE 'THS%'
   and us.type like 'TRIGGER'
   and us.name = tr.trigger_name
   AND to_char(Upper(us.text)) NOT LIKE
       '%' || (Upper(COL.column_name)) || '%'
 ORDER BY trigger_name


Thanks
Sai Pradyumn
Re: converting clob to varchar2 [message #607985 is a reply to message #607981] Fri, 14 February 2014 01:09 Go to previous message
Michel Cadot
Messages: 68644
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

It will not work if "column_name" is split between 2 "text"s.
You still need PL/SQL to merge the texts into a clob.


Previous Topic: retrieve data from 4 tables
Next Topic: Convert rows into columns
Goto Forum:
  


Current Time: Wed Apr 24 01:25:40 CDT 2024