APEX 5:将表读入textarea

时间:2016-06-27 14:22:01

标签: oracle plsql textarea oracle-apex-5

我有一张看起来像这样的表。

 `referenceID, IP1, IP2, IP3, subnetmask`

我现在需要将具有特定referenceID的IP放入Textarea或Displayonly字段,在

之前和之后添加一些纯文本

例如:

*/ 
*/this goes infront of the ips  
<ip1><ip2><ip3><subnet> 
<2ip1><2ip2><2ip3><2subnet>  
*/this text comes after the ips`

问题是,我无法找到方法,选择所有字符串和ips到textarea(或仅显示)。

到目前为止我尝试过的方法,只会导致错误,例如&#34;错误的列数&#34;或PL / SQL要求我选择一个位置来选择这些INTO。

感谢任何解决方案或帮助。

1 个答案:

答案 0 :(得分:0)

您可以尝试这样做(基于this answer):

SELECT 'this goes infront of the ips' || 
       replace(SYS_CONNECT_BY_PATH (x_text, '~'), '~', CHR(10)) ||
       CHR(10) || 'this text comes after the ips' AS textarea
  FROM (SELECT IP1 || ',' || IP2 || ',' || IP3 || ',' || subnetmask AS x_text,
               ROW_NUMBER () OVER (ORDER BY referenceID) AS x_rownumber,
               COUNT (*) OVER () AS x_count
          FROM yourtable
          WHERE referenceID > 0)
WHERE x_rownumber = x_count
START WITH x_rownumber = 1
CONNECT BY x_rownumber = PRIOR x_rownumber + 1

如果您使用的是Oracle 11.2或更高版本,则应使用以下内容(基于another answer):

SELECT 'this goes infront of the ips' || CHR(10) ||
       LISTAGG(IP1 || ',' || IP2 || ',' || IP3 || ',' || subnetmask, CHR(10)) 
       WITHIN GROUP (ORDER BY referenceID) ||
       CHR(10) || 'this text comes after the ips' AS textarea
FROM yourtable
WHERE referenceID > 0

注意:referenceID > 0只是用于将查询限制为特定referenceID的示例子句,yourtable应替换为表的名称。