PL / SQL FETCH到数据字符串中

问题描述 投票:0回答:1

我是oracle表单的新手,我有一个问题,希望您能帮助我解决。

我的问题是有一种方法可以将获取的数据放入数据字符串中?例如,在这里我使用dbms_output,但是有没有办法将所有行放入用';'分隔的数据字符串中?因此理想情况下,结果应类似于“工程师,经理,数据库分析师”。

谢谢

DECLARE 
 Job_desc varchar(100);

CURSOR cur_job is 
      SELECT job_id
from job a  where a.salary='10000';
BEGIN 
   OPEN cur_job; 
   LOOP 
   FETCH cur_job into job_desc;
      EXIT WHEN cur_job%notfound; 
      dbms_output.put_line(job_desc || ';'); 
   END LOOP; 
oracle plsql oracle10g oracleforms
1个回答
0
投票

因为它是Forms,您将执行以下操作(基于Scott的EMP表):

declare
  job_desc varchar2(100);
begin
  for cur_r in (select distinct job 
                from emp
                where sal > 1000
               )
  loop
    job_desc := job_desc ||';'|| cur_r.job;
  end loop;
end;

现在取决于您要对job_desc执行的操作:

  • 在屏幕上作为消息显示(两个连续的message调用;否则,它将显示在状态行中]

    end loop;
    message(job_desc);
    message(job_desc);
    

    (或者,查看警报的工作方式)

  • 将其放入块项目:

    end loop;
    :block.job_description := job_desc;
    

    但是,对于此选项,您宁愿直接将作业放入项目中,而不是直接放入变量中,然后再放入项目中。


我不知道Forms 10是否支持listagg;如果是这样,它将更加简单:

select listagg(job, ';') within group (order by null) job_desc
from (select distinct job
      from emp
      where sal > 1000
     );

如果没有,xmlagg起作用:

select rtrim (xmlagg (xmlelement (e, job || ', ') order by job).extract 
               ('//text()'), ', ')
from (select distinct job
      from emp
      where sal > 1000
     );

因此,有很多选择;选择一个。

© www.soinside.com 2019 - 2024. All rights reserved.