PLSQL CLOBS变成变量

时间:2012-09-17 16:33:15

标签: oracle plsql oracle10g oracle11g plsqldeveloper

我正在尝试将CLOB保存到变量中以执行提取等操作。我有这段代码:

DECLARE
  clob_rec CLOB;
  n_rec NUMBER:=100;
BEGIN
  SELECT LOB INTO clob_rec FROM table1 WHERE ID = 1234;
  n_rec := clob_rec.EXTRACT('//XPTO/text()', 'xmlns:XPTO').getNumVal();
END;

我想将XML中的多个值保存到n_rec等各种变量中。如何获得“对象实例(CLOB)”来执行extract()等函数或方法?

1 个答案:

答案 0 :(得分:5)

您需要先将其转换为XMLtype:

DECLARE
  clob_rec CLOB;
  n_rec NUMBER:=100;
  x XMLType;
BEGIN
  SELECT LOB INTO clob_rec FROM table1 WHERE ID = 1234;
  x := XMLType(clob_rec);
  n_rec := x.EXTRACT('//XPTO/text()', 'xmlns:XPTO').getNumVal();
END;