Oracle substr intercepts nvarchar2 problem

 

 

-- Query business type
-- The data content is: 2,3,4  
-- need to intercept the first character

select ris.info_sys_guid,
         substr(ris.business_type ,1,1) business_type
    from rec_info_sys ris

The result business_type appears to be empty.

After checking that the data type is nvarchar2, it is normal to test the varchar2 type.

So convert nvarchar2 to varchar2

select ris.info_sys_guid,
       substr(utl_raw.cast_to_varchar2(utl_raw.cast_to_raw(Translate(ris.business_type USING CHAR_CS))),1,1) business_type
  from rec_info_sys ris ;


Translate(ris.business_type USING CHAR_CS) for the conversion of Chinese characters and special characters

utl_raw.cast_to_varchar2(utl_raw.cast_to_raw(ris.business_type )) Convert to varchar2, only pure English characters can be converted

The last interception starts from 1 and intercepts one bit, which is normal.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327029624&siteId=291194637