Home » SQL & PL/SQL » SQL & PL/SQL » search for text in views
search for text in views [message #649291] Mon, 21 March 2016 08:43 Go to next message
desmond30
Messages: 41
Registered: November 2009
Member
I am trying to search for a particular reserved word in all of the views used in our schema, how can i do that, the text for views
in all_views is CLOB, I tried dbms_metadata

select DBMS_METADATA.GET_DDL(object_type => 'VIEW', name=>'MYVIEW',schema=> 'MYSCHEMA') from DUAL;

This still gives me the text in CLOB, How can I scan all the views in MYSCHEMA and search for the availability of a string "ABC" (Or any reserved word)?
Re: search for text in views [message #649293 is a reply to message #649291] Mon, 21 March 2016 08:52 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
extract VIEW source from code repository & grep for the reserved word
Re: search for text in views [message #649298 is a reply to message #649291] Mon, 21 March 2016 17:32 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
-- views for testing:
SCOTT@orcl> CREATE OR REPLACE VIEW test_view AS SELECT 'ABC' AS test_col FROM DUAL
  2  /

View created.

SCOTT@orcl> CREATE OR REPLACE VIEW test_view2 AS SELECT 'DEF' AS test_col FROM DUAL
  2  /

View created.

SCOTT@orcl> CREATE OR REPLACE VIEW test_view3 AS SELECT 'ABCABC' AS test_col FROM DUAL
  2  /

View created.


-- extraction:
SCOTT@orcl> BEGIN
  2    FOR r IN
  3  	 (SELECT DBMS_METADATA.GET_DDL
  4  		    (object_type => 'VIEW', name => view_name, schema => USER)
  5  		    AS view_text
  6  	  FROM	 USER_VIEWS)
  7    LOOP
  8  	 IF INSTR (r.view_text, 'ABC') > 0 THEN
  9  	   DBMS_OUTPUT.PUT_LINE (r.view_text);
 10  	 END IF;
 11    END LOOP;
 12  END;
 13  /

  CREATE OR REPLACE FORCE EDITIONABLE VIEW "SCOTT"."TEST_VIEW3" ("TEST_COL") AS

  SELECT 'ABCABC' AS test_col FROM DUAL

  CREATE OR REPLACE FORCE EDITIONABLE VIEW "SCOTT"."TEST_VIEW" ("TEST_COL") AS

  SELECT 'ABC' AS test_col FROM DUAL

PL/SQL procedure successfully completed.

Re: search for text in views [message #651047 is a reply to message #649298] Tue, 10 May 2016 08:20 Go to previous messageGo to next message
desmond30
Messages: 41
Registered: November 2009
Member
Thank you, You once helped me understand the concept of autonomous transaction when i was trying to apply it, thank you, and hope you are doing well in CA !
Re: search for text in views [message #651060 is a reply to message #649298] Tue, 10 May 2016 11:29 Go to previous message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Barbara, INSTR isn't right tool for search here. It can trigger false positives on literals containing reserved word or identifiers where keyword is part of the name. And if skipping reserved word as part of a name can be resolved by using regexp, skipping reserved word in literals is much more difficult task. But main question is if OP is really looking for Oracle reserved words. It doesn't make sense since Oracle wouldn't let creating view with reserved word in the first place. So it is either a keyword or non-Oracle reserved word.

SY.
Previous Topic: VIRTUAL Column - Function
Next Topic: sql
Goto Forum:
  


Current Time: Fri Apr 26 16:20:22 CDT 2024