在oracle中定界的Blob数据

时间:2017-05-28 14:15:06

标签: oracle blob

我在oracle表中有+分隔的BLOB数据。

数据:

2342-34-34+83898oov+4ncjj+jdjjd11kj+20-12-2017

我想提取这些数据并将其存储在数组中

预期输出:

 Array[1]   Array[2]    Array[3]
2342-34-34  83898oov    4ncjj

我们有没有办法在oracle中实现这一点而无需在DB之外提取数据?

注意:每个记录的分隔符文本数量各不相同。

1 个答案:

答案 0 :(得分:0)

Oracle安装程序

CREATE TABLE test ( data BLOB );

INSERT INTO test VALUES ( UTL_RAW.CAST_TO_RAW( '2342-34-34+83898oov+4ncjj+jdjjd11kj+20-12-2017' ) );

示例数据

SELECT x.COLUMN_VALUE AS value
FROM   test t,
       TABLE( split_clob( blob_to_clob( data ), '+' ) ) x;

查询1 - 作为行

VALUE    
----------
2342-34-34
83898oov  
4ncjj     
jdjjd11kj 
20-12-2017

<强>输出

SELECT DBMS_LOB.SUBSTR( str, delimiter1 - 1, 1 ) AS A1,
       DBMS_LOB.SUBSTR( str, delimiter2 - delimiter1 - 1, delimiter1 + 1 ) AS A2,
       DBMS_LOB.SUBSTR( str, delimiter3 - delimiter2 - 1, delimiter2 + 1 ) AS A3
FROM   (
  SELECT str,
         DBMS_LOB.INSTR( str, '+', 1, 1 ) AS delimiter1,
         DBMS_LOB.INSTR( str, '+', 1, 2 ) AS delimiter2,
         DBMS_LOB.INSTR( str, '+', 1, 3 ) AS delimiter3
  FROM   (
    SELECT BLOB_TO_CLOB( data ) AS str
    FROM   test
  )
);

查询2 - 作为列

A1         A2         A3       
---------- ---------- ----------
2342-34-34 83898oov   4ncjj     

<强>输出

.xlsx