Reputation: 3610
Is there any way I could filter the text column on oracle's all_views table?
For example:
SELECT *
FROM ALL_VIEWS
WHERE UPPER(TEXT) LIKE '%FOO%';
Exception:
ORA-00932: inconsistent datatypes: expected NUMBER got LONG
00932. 00000 - "inconsistent datatypes: expected %s got %s"
Edit:
DESC ALL_VIEWS
Name Null Type
---------------- -------- --------------
OWNER NOT NULL VARCHAR2(30)
VIEW_NAME NOT NULL VARCHAR2(30)
TEXT_LENGTH NUMBER
TEXT LONG()
TYPE_TEXT_LENGTH NUMBER
TYPE_TEXT VARCHAR2(4000)
OID_TEXT_LENGTH NUMBER
OID_TEXT VARCHAR2(4000)
VIEW_TYPE_OWNER VARCHAR2(30)
VIEW_TYPE VARCHAR2(30)
SUPERVIEW_NAME VARCHAR2(30)
Upvotes: 15
Views: 31974
Reputation: 1
If you are on a pre 12c (text_vc
only exists in 12.1+) and you can sufficiently scan your views through the first 4000 characters the following query will work.
with parsed_all_views as (
select owner, view_name, text_length, TEXT as VARCHAR_TEXT
from xmltable( '/ROWSET/ROW' passing dbms_xmlgen.getXMLType(
'select TEXT, owner, view_name, text_length '
||' from all_views WHERE owner = ''**YOUR_SCHEMA_NAME**'' '
) columns TEXT varchar2(4000), owner varchar2(32), view_name
varchar2(32), text_length varchar2(32))
)
select * from parsed_all_views where upper(VARCHAR_TEXT) like '%DISTINCT%'
Upvotes: 0
Reputation: 105
Search on TEXT_VC instead of TEXT
SELECT *
FROM ALL_VIEWS
WHERE UPPER(TEXT_VC) LIKE '%FOO%';
Upvotes: 4
Reputation: 885
On Oracle Developer run and export to Excel
SELECT view_name, text from all_views where owner = 'MyDb'
Import the Excel file to SQL Server (to [ALL_VIEWS] table)
SELECT [VIEW_NAME], [TEXT] FROM [MyDb].[dbo].[ALL_VIEWS] WHERE [TEXT] LIKE '%FOO%'
Upvotes: 0
Reputation: 15473
You can't convert to a clob on the fly via a select statement unfortunately. to_lob function works with INSERT statements, but that would mean you'd need to setup a separate table and do inserts into using to_lob.
You can do assignment conversions to varchar in pl/sql, and most of the time you'll find that the text_length in all_views is < 32767, so this will cover "most" cases, although its not a nice as just selecting:
declare
l_search varchar2(1000) := 'union';
l_char varchar2(32767);
begin
for rec in (select * from all_views where text_length < 32767)
loop
l_char := rec.text;
if (instr(l_char, l_search) > 0) then
dbms_output.put_line('Match found for ' || rec.owner || '.' || rec.view_name);
end if;
end loop;
end;
Here I'm searching the text field for the string 'union'.
Hope that helps.
Upvotes: 20
Reputation: 67722
You can't manipulate LONG columns easily in SQL unfortunately.
For your present problem, as a workaround, you could use the *_DEPENDENCIES
views to find all views dependent upon a table:
SELECT *
FROM all_dependencies
WHERE type = 'VIEW'
AND referenced_owner = 'TABLE_OWNER'
AND referenced_name = 'YOUR_TABLE';
Upvotes: 14