1.listagg
该方法拼接后是varchar2类型,有最大长度限制,在Oracle Database中,VARCHAR2 字段类型,最大值为4000;PL/SQL中 VARCHAR2 变量类型,最大字节长度为32767。
适用场景:当要拼接的字符较少时使用。
select 'select ' ||col|| ' from ' || table_name ||';' from ( select owner||'.'||table_name as table_name, listagg(to_char(column_name),'||''^C''||') within group(order by owner||'.'||table_name ) as col from all_tab_columns where owner='USE' group by owner||'.'||table_name );
2.xmlagg
该方法拼接完后是CLOB对象,最多能容纳4GB的数据,查看时可用to_char()显示。
适用场景:当要拼接的字符很多时使用。
select 'select ' ||to_char(col)|| ' from ' || table_name ||';' from ( select owner||'.'||table_name as table_name, xmlagg(xmlparse(content column_name||',' wellformed) order by column_name).getclobval() as col from all_tab_columns where owner='USE' group by owner||'.'||table_name );
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208627.html原文链接:https://javaforall.net
