oracle PLSQL CLOBS 转换成变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12463526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:06:51  来源:igfitidea点击:

PLSQL CLOBS into variables

oracleplsqloracle10goracle11gplsqldeveloper

提问by DaveQuinn

I'm trying to save a CLOBinto a variable to perform operations like extract and such. I have this code:

我正在尝试将 a 保存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;

I want to save multiple values from the XMLto various variables like n_rec. How can get an "instance of the object (CLOB)" to perform functions or methods like extract()?

我想从XML到各种变量中保存多个值,例如n_rec. 如何获得“对象的实例(CLOB)”来执行诸如此类的功能或方法extract()

回答by Jeffrey Kemp

You need to convert it to an XMLtype first:

您需要先将其转换为 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;