Link to home
Create AccountLog in
Avatar of pepeorcl
pepeorcl

asked on

How do I see full definition of a view?

select text from dba_views where view_name in ('....','...');
does not give me all the text.

How can I find the whole text and definition?
Thanks
ASKER CERTIFIED SOLUTION
Avatar of DrSQL - Scott Anderson
DrSQL - Scott Anderson
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Hi,
I think ths may work for you
SQL> set long 10000
SQL> select TEXT
          FROM DBA_VIEWS
          where OWNER = '<owner_name>'  4  and VIEW_NAME  = '<view_name>' ;
Here is a link in whch it was explained in a detailed manner:
http://technopark02.blogspot.com/2007/05/oracle-how-to-get-tableview-definition.html

Thanks,
vkg_26.
set long 10000;
 
select TEXT 
          FROM DBA_VIEWS 
          where OWNER = '<owner_name>'  4  and VIEW_NAME  = '<view_name>' ;

Open in new window

SELECT dbms_metadata.get_ddl('VIEW', 'MY_TABLES')
FROM dual;
BEFORE ISSUING THE COMMAND U SHOULD SET ,SET LONG 10000

set serveroutput on

CREATE OR REPLACE PROCEDURE  put_buffer (v_buffer VARCHAR2) IS
  cnt   number;
  buf   VARCHAR2(300);
  v_length NUMBER;
BEGIN
  V_length := length(v_buffer);
   IF V_length <= 250 THEN
           DBMS_OUTPUT.PUT_LINE(v_buffer);
   ELSE
           cnt := 1;
           WHILE cnt < V_length LOOP
              IF (V_length - cnt +1) > 250 THEN
                 buf := SUBSTR(v_buffer,cnt,250);
                 DBMS_OUTPUT.PUT_LINE(buf);
                 cnt := cnt + 250;
              ELSE
                 buf := SUBSTR(v_buffer,cnt,V_length-cnt+1);
                 DBMS_OUTPUT.PUT_LINE(buf);
                 cnt := V_length;
              END IF;      
            END LOOP;
    END IF;
END put_buffer;
/

CREATE OR REPLACE PROCEDURE ddl(schema varchar2, name varchar2, type varchar2) IS
   v_t   VARCHAR2(1500);
   v_len NUMBER;
   v_buf VARCHAR2(250);
begin
   DBMS_OUTPUT.ENABLE(1000000);
   SELECT dbms_metadata.get_ddl(UPPER(type), UPPER(name), UPPER(schema)) INTO v_t    from dual;
   v_buf :='';
   v_len := length(v_t);
   for i in 1..v_len loop
      v_buf := v_buf || SUBSTR(v_t, i,1);
      if (i mod 250) = 0 then
         DBMS_OUTPUT.PUT_LINE(v_buf);
         v_buf :='';
      end if;
   end loop;
   v_buf := v_buf ||';';
   DBMS_OUTPUT.PUT_LINE(v_buf);
end ddl;
/

execute ddl('schema', 'name', 'VIEW');
"DESCRIBE viewname;" gives the full definition.  Did you need to recreate the DDL statement instead?