Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Error "inconsistent datatypes: expected CHAR got LONG"

I'm trying to run the following query to find views containing a given keyword:

select  *
from    ALL_VIEWS
where   OWNER = 'SALESDBA'
        and TEXT like '%rownum%';

I'm getting the following error message:

ORA-00932: inconsistent datatypes: expected CHAR got LONG
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:
Error at Line: 4 Column: 13

if I just select from ALL_VIEWS than I see the query (TEXT) in the TEXT field.

What am I doing wrong here?

like image 626
developer82 Avatar asked Dec 17 '14 10:12

developer82


2 Answers

You could use TEXT_VC as the column to check criteria against. For example:

select  *
from    ALL_VIEWS
where   OWNER = 'SALESDBA'
        and TEXT_VC like '%rownum%';

I hope this helps.

like image 180
MeL Avatar answered Nov 23 '22 00:11

MeL


Your problem is that TEXT is of type LONG - although Oracle deprecated this type a long, long time ago, they're still using it in their own views :-(

To convert a LONG to a (searchable) CLOB, you can use the TO_LOB() function (see Oracle documentation for TO_LOB().

Unfortunately, this doesn't work for simple SELECT statements. You'll have to create an intermediary table:

create table search_all_views as 
select  av.owner, av.view_name, to_lob(text) as text_clob
from    ALL_VIEWS av;

Then, you can search using that table:

select * 
from search_all_views
where text_clob like '%rownum%';
like image 24
Frank Schmitt Avatar answered Nov 23 '22 02:11

Frank Schmitt