在Oracle 9i中检索一行中一行的多行

时间:2019-03-05 13:20:26

标签: oracle oracle9i

使用Oracle 9i

描述mtitem0(表)

Materailcd          Char(10),
Technicalspecs   VarChar2(1000)

查询:

Select Materailcd, TechnicalSpecs
From Mtitem0
Where Materailcd  = '0100000121'

MATERIALCD TECHNICALSPECS
---------- ---------------------------------------
0100000121 INDUSTRIAL GRADE SALT
               SPECIFICATIONS:-
               A) MOISTURE  MAX: 4.0
                PERCENT BY MASS.
               B) MATTER INSOLUBLES IN WATER MAX:0.50 

我想在一行中检索“ TechnicalSpecs”列,如下所示:

MATERIALCD       TECHNICALSPECS
--------------------       ---------------------------------------
0100000121          INDUSTRIAL GRADE SALT SPECIFICATIONS:-  A) MOISTURE  MAX: 4.0  PERCENT BY MASS.

请给我一个主意,并在这方面帮助我.....

致谢
康复者

2 个答案:

答案 0 :(得分:0)

我没有访问oracle 9i的权限,但是我相信下面的代码可以正常工作。你能试一下让我知道吗

 select Materailcd     , ltrim(sys_connect_by_path(TechnicalSpecs,','),',') as staff
    from   ( select Materailcd
                  , TechnicalSpecs
                  , row_number() over (partition by Materailcd order by TechnicalSpecs) as seq
             from Mtitem0 )
    where  connect_by_isleaf = 1
    connect by seq = prior seq +1 and Materailcd = prior Materailcd
    start with seq = 1;  

答案 1 :(得分:0)

我想您在TECHNICALSPECS栏中有换行符。只需将它们替换为一个空格即可。

Select Materailcd, replace(TechnicalSpecs, chr(10),' ') TechnicalSpecs
From Mtitem0
Where Materailcd  = '0100000121'

如果它是从Windows客户端输入的,则您可能还会有CR字符,因此为了安全起见,也请删除这些字符:

Select Materailcd, replace(replace(TechnicalSpecs, chr(10),' '),chr(13)) TechnicalSpecs
From Mtitem0
Where Materailcd  = '0100000121'