将Long转换为varchar

时间:2016-02-08 20:45:44

标签: sql oracle

我正在尝试将Long的值转换为varchar到目前为止我已接近它转换为Long - > CLOB - > VARCHAR2:

INSERT into ALL_POSTAL_CODES (ZIP_CODE,LATITUDE,LONGITUDE,ISO_COUNTRY,CITY,STATE, TIME_ZONE)
Select  ZIP_CODE,
        LATITUDE,
        TO_CHAR(SUBSTR(TO_LOB(LONGITUDE))),
        'USA',
        CITY,
        STATE,
        TIME_ZONE
from POSTAL_CODES

但是我遇到了一些语法错误:

Error report -
SQL Error: ORA-00932: inconsistent datatypes: expected - got LONG
00932. 00000 -  "inconsistent datatypes: expected %s got %s"
*Cause:    
*Action:

1 个答案:

答案 0 :(得分:0)

我创建了一个Temp表来解决这个问题,因为没有优雅的解决方案

CREATE TABLE t1
  AS
  SELECT ZIP_CODE,
           to_lob(LONGITUDE) as LONGITUDE
    FROM POSTAL_CODES;

update ALL_POSTAL_CODES AP
Set AP.LONGITUDE = 
( select P.LONGITUDE
    from
    T1 P
    where 
    P.ZIP_CODE = AP.ZIP_CODE
     and
      rownum = 1 
    )
    where exists (
      select 
        null
      from 
        T1 P
      where 
        P.ZIP_CODE = AP.ZIP_CODE
      );

Drop table T1;