declare
v_text clob;
v_owner varchar2(30);
v_view_name varchar2(30);
v_count number;
v_loc number;
v_loc_s number;
v_len number;
-- select av.view_name,av.owner from all_views av where av.owner='J1_DW' and av.view_name='V_SB_QYSDSNDSSYHQKMXB'
begin
v_loc_s :=1;
v_owner :='J1_DW';
v_view_name :='V_SB_QYSDSNDSSYHQKMXB';
SELECT length(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner))-length(replace(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),''))
into v_count
FROM dual;
dbms_output.put_line(v_count);
SELECT length(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner)) into v_len FROM dual;
for i in 1..v_count loop
-- dbms_output.put_line(i);
select instr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),1,i) into v_loc from dual;
SELECT substr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),v_loc_s,v_loc-v_loc_s) INTO V_TEXT from dual;
-- SELECT substr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),1,1),1,instr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),1,1)) INTO V_TEXT from dual;
dbms_output.put_line(replace(v_text,chr(10),''));
-- dbms_output.put_line(v_text);
v_loc_s :=v_loc;
end loop;
SELECT substr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),v_loc_s,v_len-v_loc_s+1) INTO V_TEXT from dual;
dbms_output.put_line(replace(replace(v_text,';','')||';',chr(10),''));
end;
/
v_text clob;
v_owner varchar2(30);
v_view_name varchar2(30);
v_count number;
v_loc number;
v_loc_s number;
v_len number;
-- select av.view_name,av.owner from all_views av where av.owner='J1_DW' and av.view_name='V_SB_QYSDSNDSSYHQKMXB'
begin
v_loc_s :=1;
v_owner :='J1_DW';
v_view_name :='V_SB_QYSDSNDSSYHQKMXB';
SELECT length(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner))-length(replace(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),''))
into v_count
FROM dual;
dbms_output.put_line(v_count);
SELECT length(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner)) into v_len FROM dual;
for i in 1..v_count loop
-- dbms_output.put_line(i);
select instr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),1,i) into v_loc from dual;
SELECT substr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),v_loc_s,v_loc-v_loc_s) INTO V_TEXT from dual;
-- SELECT substr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),1,1),1,instr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),chr(10),1,1)) INTO V_TEXT from dual;
dbms_output.put_line(replace(v_text,chr(10),''));
-- dbms_output.put_line(v_text);
v_loc_s :=v_loc;
end loop;
SELECT substr(dbms_metadata.get_ddl('VIEW',v_view_name,v_owner),v_loc_s,v_len-v_loc_s+1) INTO V_TEXT from dual;
dbms_output.put_line(replace(replace(v_text,';','')||';',chr(10),''));
end;
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29802484/viewspace-1770224/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29802484/viewspace-1770224/