简体   繁体   中英

SQL To remove new line of column length more than 4000(CLOB Datatype)

I have a column with data such as -

COL                  STR
1                    
                    Testing data entered. This is not true but I will like to enter more data

2                   
                    New column like Noida Limtd.Able to work with or without supervision
                    Able to lead a team and  accomplished given tasks
                    Able to assemble and disassemble finals and undercarriage.

The STR column is in clob format and has a newline as the first line in the text. To remove the newline I am using -

 translate(STR, ' '||chr(10)||chr(11)||chr(13), ' ') r

The above code is working for most data but some of the text in STR column is > 4000 and I am getting the error -

ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion  translate

I can reduce the STR column length to 4000 and translate but SUBSTR is not working.

Can you get away with using REPLACE? It has CLOB handling where TRANSLATE does not, eg

SQL> create table t ( x clob );

Table created.

SQL> insert into t values ( '123' ||rpad('x', 5000,'x'));

1 row created.

SQL> update t set x = x || x;

1 row updated.

SQL> update t set x = x || x;

1 row updated.

SQL> update t set x = x || x;

1 row updated.

SQL> update t set x = x || x;

1 row updated.

SQL> update t set x = x || x;

1 row updated.

SQL> commit;

Commit complete.

SQL> select length(x) from t;

 LENGTH(X)
----------
    160096

SQL>
SQL> select translate(x,'123','456') from t;
select translate(x,'123','456') from t
                 *
ERROR at line 1:
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 160096, maximum: 32767)


SQL>
SQL> select replace(x,'123','456') from t;

REPLACE(X,'123','456')
--------------------------------------------------------------------------------
456xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM