簡體   English   中英

從 Oracle 19 CLOB 列中提取數據的問題

[英]Issue Extracting Data from Oracle 19 CLOB column

我在從 Oracle 19c 中的 CLOB 列中提取數據時遇到問題。

我的查詢是:

select TRANS_SETTINGS, x.Value
  cross join xmltable(
  xmlnamespaces(default 'http://tempuri.org/GenericSettingsDataSet.xsd')
  '/GenericSettingsDataSet/ConfigSettings'
  passing xmltype(TRANS_SETTINGS)
  columns Value CLOB path 'Value'
  ) x
from FS_STD_CONT_TRANS
  WHERE TRANS_SETTINGS LIKE '%\\Instem\%'
;

結果:

TRANS_SETTINGS|VALUE|
--------------+-----+
  • 表=FS_STD_CONT_TRANS
  • 列=TRANS_SETTINGS
  • 列類型=CLOB

我需要的值是:

Value>\\Instem\alcon\PQ\Submit\ABC Labs</Value>

下面是 CLOB xml

<GenericSettingsDataSet xmlns="http://tempuri.org/GenericSettingsDataSet.xsd">
  <ConfigSettings>
    <Key>ActionToggle_FilterFiles</Key>
    <SubKey />
    <Value>True</Value>
    <Required>true</Required>
    <Description>Indicates if the list of files and folders involved in the transfer is to be filtered using the substitution tokens and regex matching settings in the transfer template.</Description>
    <DefaultValue>True</DefaultValue>
    <EditorType>6</EditorType>
    <SettingType>1</SettingType>
    <DisplayName>Filter File List</DisplayName>
    <IsVisible>false</IsVisible>
    <CategoryKey>TransferActions</CategoryKey>
  </ConfigSettings>
  <ConfigSettings>
    <Key>ActionToggle_TransferCompressedFiles</Key>
    <SubKey />
    <Value>False</Value>
    <Required>true</Required>
    <Description>Transfer compressed versions of files.</Description>
    <DefaultValue>False</DefaultValue>
    <EditorType>6</EditorType>
    <SettingType>1</SettingType>
    <DisplayName>Transfer Compressed Files</DisplayName>
    <IsVisible>true</IsVisible>
    <CategoryKey>TransferActions</CategoryKey>
  </ConfigSettings>
  <ConfigSettings>
    <Key>ActionToggle_OverwriteFiles</Key>
    <SubKey />
    <Value>False</Value>
    <Required>true</Required>
    <Description>Overwrite destination files on transfer.</Description>
    <DefaultValue>False</DefaultValue>
    <EditorType>6</EditorType>
    <SettingType>1</SettingType>
    <DisplayName>Overwrite Files</DisplayName>
    <IsVisible>true</IsVisible>
    <CategoryKey>TransferActions</CategoryKey>
  </ConfigSettings>
  <ConfigSettings>
    <Key>ActionToggle_DeleteDestination</Key>
    <SubKey />
    <Value>False</Value>
    <Required>true</Required>
    <Description>Delete all existing files from destination before transfer.</Description>
    <DefaultValue>False</DefaultValue>
    <EditorType>6</EditorType>
    <SettingType>1</SettingType>
    <DisplayName>Delete Existing Destination Files</DisplayName>
    <IsVisible>true</IsVisible>
    <CategoryKey>TransferActions</CategoryKey>
  </ConfigSettings>
  <ConfigSettings>
    <Key>ActionToggle_RemoveFolderStructure</Key>
    <SubKey />
    <Value>False</Value>
    <Required>true</Required>
    <Description>If enabled, will remove the folder structure when exporting to the external location.</Description>
    <DefaultValue>False</DefaultValue>
    <EditorType>6</EditorType>
    <SettingType>1</SettingType>
    <DisplayName>Remove Folder Structure</DisplayName>
    <IsVisible>true</IsVisible>
    <CategoryKey>TransferActions</CategoryKey>
  </ConfigSettings>
  <ConfigSettings>
    <Key>NetworkLocationKey</Key>
    <SubKey />
    <Value>\\Instem\alcon\PQ\Submit\ABC Labs</Value>
    <Required>true</Required>
    <Description>Network location for the file transfer.
The following placeholders are accepted: %STUDY_ID% (Study ID), %SPON_ID% (Sponsor ID) and %CONTRIB_ID% (Contributor ID).</Description>
    <DefaultValue />
    <EditorType>5</EditorType>
    <SettingType>1</SettingType>
    <DisplayName>Network Location</DisplayName>
    <IsVisible>true</IsVisible>
    <CategoryKey>ExternalLocation</CategoryKey>
  </ConfigSettings>
  <Categories>
    <Key>TransferActions</Key>
    <Required>false</Required>
    <Description>Actions that can be performed at various stages as part of the transfer process.</Description>
    <DisplayName>Transfer Actions</DisplayName>
    <IsVisible>true</IsVisible>
  </Categories>
  <Categories>
    <Key>FileSelection</Key>
    <Required>false</Required>
    <Description>Settings that control the files that are included in the transfer.</Description>
    <DisplayName>File Selection</DisplayName>
    <IsVisible>true</IsVisible>
  </Categories>
  <Categories>
    <Key>ExternalLocation</Key>
    <Required>false</Required>
    <Description>Settings that configure the remote target address or any other information required for the transfer.</Description>
    <DisplayName>External Location</DisplayName>
    <IsVisible>true</IsVisible>
  </Categories>
  <Categories>
    <Key>SENDActions</Key>
    <Required>false</Required>
    <Description>submit Workflow actions that can be performed on the incoming data.</Description>
    <DisplayName>SEND Processing</DisplayName>
    <IsVisible>true</IsVisible>
  </Categories>
</GenericSettingsDataSet>

您的代碼中有一些 sintax 錯誤。 嘗試這個:

Select 
    x.A_VALUE
From 
    FS_STD_CONT_TRANS,
    xmltable(
        xmlnamespaces(default 'http://tempuri.org/GenericSettingsDataSet.xsd'),
                '/GenericSettingsDataSet/ConfigSettings'
        passing xmltype(TRANS_SETTINGS)
                columns A_VALUE CLOB path 'Value'
    ) x
WHERE x.A_VALUE LIKE '%\\Instem\%';

您的FROM位於錯誤的位置,並且您在xmlnamespaces子句后缺少逗號。 但是有了這些修復,您的查詢將返回:

select x.Value
from FS_STD_CONT_TRANS
  cross join xmltable(
  xmlnamespaces(default 'http://tempuri.org/GenericSettingsDataSet.xsd'),
  '/GenericSettingsDataSet/ConfigSettings'
  passing xmltype(TRANS_SETTINGS)
  columns Value CLOB path 'Value'
  ) x
  WHERE TRANS_SETTINGS LIKE '%\\Instem\%'
;

VALUE
---------------------------------
True
False
False
False
False
\\Instem\alcon\PQ\Submit\ABC Labs

因為您正在過濾整個 CLOB,而不是特定值。 您可以改為過濾值,如@dr 的回答:

select x.Value
from FS_STD_CONT_TRANS
  cross join xmltable(
  xmlnamespaces(default 'http://tempuri.org/GenericSettingsDataSet.xsd'),
  '/GenericSettingsDataSet/ConfigSettings'
  passing xmltype(TRANS_SETTINGS)
  columns Value CLOB path 'Value'
  ) x
  WHERE value LIKE '%\\Instem\%'
;

VALUE
---------------------------------
\\Instem\alcon\PQ\Submit\ABC Labs

但您可能實際上想要查找與 NetWorkLocationKey 對應的值,無論它是否以Instem開頭:

select x.Value
from FS_STD_CONT_TRANS
  cross join xmltable(
  xmlnamespaces(default 'http://tempuri.org/GenericSettingsDataSet.xsd'),
  '/GenericSettingsDataSet/ConfigSettings[Key="NetworkLocationKey"]'
  passing xmltype(TRANS_SETTINGS)
  columns Value CLOB path 'Value'
  ) x
;

VALUE
---------------------------------
\\Instem\alcon\PQ\Submit\ABC Labs

db<>小提琴

正如@OldProgrammer 評論的那樣,將該值提取為 CLOB 似乎很奇怪 - 該值看起來會被限制為遠小於 4k,因此可以作為正確的六倍體 varchar2 處理。 也許您不得不處理可能更長的其他鍵的值 - 如果您對鍵進行過濾,這將不是必需的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM