I have a SQL table:
CREATE TABLE "text_files"
( "FILE_NAME" VARCHAR2(4000 BYTE),
"FILE_CONTENT" CLOB
);
I am trying to run the following query:
WITH rsqfc ( file_content, line, rn, max_rn, nm1, prv, depth ) AS (
SELECT file_content,
REGEXP_SUBSTR( file_content, '.+?(' || CHR(10) || '|$)', 1, 1 ),
1,
REGEXP_COUNT( file_content, '.+?(' || CHR(10) || '|$)' ) - 1,
CASE SUBSTR( file_content, 1, 4 ) WHEN 'NM1*' THEN 1 ELSE 0 END,
CASE SUBSTR( file_content, 1, 4 ) WHEN 'PRV*' THEN 1 ELSE 0 END,
CASE SUBSTR( file_content, 1, 4 ) WHEN 'NM1*' THEN 1 WHEN 'PRV*' THEN 2 ELSE 0 END
FROM text_files
UNION ALL
SELECT file_content,
REGEXP_SUBSTR( file_content, '.+?(' || CHR(10) || '|$)', 1, rn + 1 ),
rn + 1,
max_rn,
CASE SUBSTR( REGEXP_SUBSTR( file_content, '.+?(' || CHR(10) || '|$)', 1, rn + 1 ), 1, 4 ) WHEN 'NM1*' THEN nm1 + 1 ELSE nm1 END,
CASE SUBSTR( REGEXP_SUBSTR( file_content, '.+?(' || CHR(10) || '|$)', 1, rn + 1 ), 1, 4 ) WHEN 'PRV*' THEN prv + 1 ELSE prv END,
CASE SUBSTR( REGEXP_SUBSTR( file_content, '.+?(' || CHR(10) || '|$)', 1, rn + 1 ), 1, 4 ) WHEN 'NM1*' THEN 1 WHEN 'PRV*' THEN 2 ELSE depth END
FROM rsqfc
WHERE rn < max_rn
)
SELECT CASE depth
WHEN 2 THEN '2010A' || CHR( 64 + prv )
WHEN 1 THEN '1000' || CHR( 64 + nm1 )
WHEN 0 THEN '000'
END AS "LOOP",
line
FROM rsqfc;
However it gives
ORA-00932: inconsistent datatypes:expected CLOB got CHAR error
I understand that we cannot use CLOB for regex and where clause. But the content in CLOB
is more than 4000 characters and when I try to alter table with VARCHAR2(4000)
field and copy CLOB
to the new field, it doesn't copy.
It gives me
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 4436, maximum: 4000)
I cannot break the text into multiple fields. I need the whole text in 1 field.
Any help would be appreciated.