现在我急需吧oracle数据库中的long类型转换成varchar2或者char也行,怎么转换呀。谢谢!

解决方案 »

  1.   

    对于long这个类型,很是讨厌,原来处理的时候也是出现问题。
    我原来用的方式是先转clob,然后再转varchar
    SQL> desc a01
    Name Type         Nullable Default Comments 
    ---- ------------ -------- ------- -------- 
    COL1 VARCHAR2(20) Y                         
    COL2 VARCHAR2(2)  Y        'Y'              
    COL3 LONG         Y                         
     
    SQL> select col3 from a01;
     
    COL3
    --------------------------------------------------------------------------------
    wwwww
     
    SQL> create table a02(t varchar2(20));
     
    Table created
     
    SQL> insert into a02 (select to_lob(col3) from a01);
     
    1 row inserted
     
    SQL> commit;
     
    Commit complete
     
    SQL> select * from a02;
     
    T
    --------------------
     
    SQL> create table a002(t clob);
     
    Table created
     
    SQL> insert into a002 (select to_lob(col3) from a01);
     
    1 row inserted
     
    SQL> commit;
     
    Commit complete
     
    SQL> select * from a002;
     
    T
    --------------------------------------------------------------------------------
    wwwww
     
    SQL> truncate table a02;
     
    Table truncated
     
    SQL> insert into a02 (select * from a002);
     
    1 row inserted
     
    SQL> commit;
     
    Commit complete
     
    SQL> select * from a02;
     
    T
    --------------------
    wwwww
     
    SQL> 
      

  2.   

    增加一个varchar2字段,然后写语句考过去,或者创建一个表,然后insert table    select 也行一个简单的示范
    SQL> create table toms(str long);表已创建。SQL> insert into toms values('test');已创建 1 行。SQL> commit;提交完成。SQL> select str from toms;STR
    -------------------------
    testSQL> set serveroutput on
    SQL> declare
      2   v_buf varchar2(32767);
      3  begin
      4    select str into v_buf from toms where rownum=1;
      5    dbms_output.put_line(v_buf);
      6  end;
      7  /
    testPL/SQL 过程已成功完成。SQL>