Converting Long to Varchar2

前端 未结 2 976
眼角桃花
眼角桃花 2020-12-18 07:38

I am trying to insert into varchar2 column from a long column. here is the below example, TEXT.TEXT_COL = VARCHAR2(4000) and NOTE.TEXT_NOTE = LONG.

2条回答
  •  -上瘾入骨i
    2020-12-18 08:27

    Converting from long to varchar2 right away using a single statement is not possible, as long has certain restrictions.

    You can either Create a temporary table or use PL/SQL code to solve your problem:

    • Temporary Table:

      CREATE TABLE TABLE2 AS SELECT TO_LOB(COLUMN1) COLUMN FROM TABLE1;

    • PL/SQL Code:

      DECLARE
        VAR1 LONG;
        VAR2 VARCHAR2(4000);
      BEGIN
        SELECT TEXT INTO VAR1 FROM USER_VIEWS WHERE ROWNUM = 1;  
        VAR2 := SUBSTR(VAR1, 1, 4000);
        DBMS_OUTPUT.PUT_LINE(VAR2);
      END;
      

提交回复
热议问题