Oracle SQLPlus setting environment variable based on variable

大憨熊 提交于 2019-12-30 22:53:27

问题


I want to set the environment variable long based on the size of the XML data I'm trying to retrieve. The idea is something like this:

var XML_DATA_SIZE number;

SELECT TRIM(LENGTH(xmltype.getClobVal(xml_data))) 
  INTO :XML_data_size 
  FROM xml_tab 
 WHERE key = '1234';

print XML_DATA_SIZE
set long XML_DATA_SIZE
set pagesize 0
set line 2000

set termout off
spool XMLDATA.xml
select xml_data from xml_tab where key = '1234';
spool off

This yields an error: SP2-0268: long option not a valid number, and the XML file only contains 80 characters.


回答1:


Instead of

set long XML_DATA_SIZE

try

set long &XML_DATA_SIZE

[EDIT]:

Apologies, I had fiddled around with some other options which messed up my test. Try this:

define xml_data_size=0
column xml_data_size new_value xml_data_size noprint

select trim(length(xmltype.getClobVal(xml_data))) xml_data_size from xml_tab where key = '1234';

set long &xml_data_size
sho long
set pagesize 0
...
...


来源:https://stackoverflow.com/questions/4027182/oracle-sqlplus-setting-environment-variable-based-on-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!