在oracle中,如何用空格分隔行?
我正在尝试将表中的行合并为一行。我尝试使用listagg,但由于varchar的限制,这不起作用在oracle中,如何用空格分隔行?,oracle,oracle11g,whitespace,concat,listagg,Oracle,Oracle11g,Whitespace,Concat,Listagg,我正在尝试将表中的行合并为一行。我尝试使用listagg,但由于varchar的限制,这不起作用 create table tmp(word VARCHAR2(4000), lvl NUMBER); insert into tmp2 values('python',1); insert into tmp2 values('java',2); select listagg(word,' ') within group(order by lvl) as list
create table tmp(word VARCHAR2(4000),
lvl NUMBER);
insert into tmp2 values('python',1);
insert into tmp2 values('java',2);
select listagg(word,' ') within group(order by lvl) as listagg_output from tmp;
输出应该类似于python java。您将如何处理这么长的字符串 无论如何,看看这个例子;如果
listag
不起作用,xmlagg
会起作用
SQL> create table test (id, col) as
2 select rownum, a.column_name
3 from user_tab_columns a cross join user_tab_columns b
4 cross join user_tab_columns c;
Table created.
SQL> select count(*) from test;
COUNT(*)
----------
9261
SQL> select listagg(col, ' ') within group (order by null) result from test;
select listagg(col, ' ') within group (order by null) result from test
*
ERROR at line 1:
ORA-01489: result of string concatenation is too long
SQL> select length(xmlagg(xmlelement(e, col, ' ').extract('//text()') order by null).GetClobVal()) length_result
2 from test;
LENGTH_RESULT
-------------
51156
SQL>
你的问题很简单:
tmp
tmp2
tmp
的查询没有返回任何结果,因为tmp
tmp
:
create table tmp(word VARCHAR2(4000),
lvl NUMBER);
insert into tmp values('python',1);
insert into tmp values('java',2);
select listagg(word,' ') within group(order by lvl) as listagg_output from tmp;
现在返回pythonjava