sql查询中,我如果想把一个二进制的字段转义成中文意思,该执行什么语句呢?
例如:现在这个字段的名字是name1,它里面的值是0000,0001,1001,1101......等等,
如果是0代表没有,如果第一位是1就代表含义1,如果第二位是1就代表含义2,以此类推,现在我想在查询中体现出数字所代表的中文含义,也就是说如果值是“1001”,查询的结果我想显示出“含义1含义4”。有什么好方法么? 
问题补充:现在只有查询权限,没有其余的权限,如修改表等。

解决方案 »

  1.   

    SQL> select * from test_convert;
     
             ID NAME
    ----------- --------------------------------------------------------------------------------
              1 10000101110010101
              2 0000101110010101
     
    SQL> 
    SQL>  with t1 as (select rownum rn from dual connect by rownum<=(select max(length(name)) from test_convert)),
      2   t2 as (select b.id,substr(b.name,a.rn,1) name,rn from t1 a,test_convert b where substr(b.name,a.rn,1) is not null)
      3   select id,replace(wm_concat('含义'||rn),',','') from t2 where name='1' group by id;
     
             ID REPLACE(WM_CONCAT('含义'||RN),
    ----------- --------------------------------------------------------------------------------
              1 含义1含义6含义8含义10含义15含义17含义13含义9
              2 含义5含义7含义8含义12含义16含义14含义9
     
    SQL>
      

  2.   

    写个函数吧,解决不了排序问题.
    SQL> create or replace function func_conver(i_str in varchar2)return varchar2
      2  as
      3  v_str varchar2(4000);
      4  begin
      5   v_str:=null;
      6   for i in 1..length(i_str)
      7   loop
      8     if substr(i_str,i,1)=1 then
      9        v_str:=v_str||'含义'||i;
     10     end if;
     11   end loop;
     12   return v_str;
     13  end;
     14  /
     
    Function created
     
    SQL> select id,func_conver(name) from test_convert;
     
             ID FUNC_CONVER(NAME)
    ----------- --------------------------------------------------------------------------------
              1 含义1含义6含义8含义9含义10含义13含义15含义17
              2 含义5含义7含义8含义9含义12含义14含义16
     
    SQL> 
      

  3.   


      1  with t as(
      2   select '0000' name from dual
      3   union all
      4   select '0101' from dual
      5   union all
      6   select '1000' from dual
      7   union all
      8   select '0011' from dual
      9  )
     10  select
     11  (case when mod(to_number(name,'0000'),10)=1 then '含义1' end)||
     12  (case when mod(floor(to_number(name,'0000')/10),10)=1 then '含义2' end)||
     13  (case when mod(floor(to_number(name,'0000')/100),10)=1 then '含义3' end)||
     14  (case when mod(floor(to_number(name,'0000')/1000),10)=1 then '含义4' end) name
     15* from t
    SQL> /NAME
    ----------------------------含义1含义3
    含义4
    含义1含义2