解决方案 »

  1.   

    可以考虑自己写个function
    问题在具体点可以么
      

  2.   

    其实我是想用一个函数能把这个实现,就是取一个字段(item)里的名称部分,就是“[”前的部分,没有“[”的取“{”前的部分,“[”和“{”都没有的,就取item本身,就不用截取了。
      

  3.   

    CREATE OR REPLACE PROCEDURE idsp(item IN VARCHAR2) IS
      v_bkt_pos NUMBER;
      v_bce_pos NUMBER;
    BEGIN
      SELECT instr(item, '['), instr(item, '{') INTO v_bkt_pos, v_bce_pos FROM dual;
      IF v_bkt_pos = 0
      THEN
        IF v_bce_pos = 0
        THEN
          dbms_output.put_line(item);
        ELSE
          dbms_output.put_line(substr(item, 1, v_bce_pos - 1));
        END IF;
      
      ELSE
        dbms_output.put_line(substr(item, 1, v_bkt_pos - 1));
      END IF;
    END;自己转成function吧。
      

  4.   

    第一个else里面掉了对大括号的判断,需要加上,。
      

  5.   

    case when 规格 is not null and 型号 is not null then substr(col,0,instr(col,'[')-1)
         when 规格 is null then substr(col,0,instr(col,'{')-1)
         when 型号 is null then substr(col,0,instr(col,'[')-1)
         else col
    end
               
      

  6.   

    select
      DECODE( 
        instr(item, '[')
        , 0
        , ( 
          DECODE( 
            instr(item, '{')
            , 0
            , item
            , substr(item, 0, instr(item, '{') - 1)
          )
        ) 
        , substr(item, 0, instr(item, '[') - 1)
      ) 
    from
      table
      

  7.   

    使用decode判断列值的数据,根据值判断返回对应的结果
      

  8.   

    with tmp as 
         ( select '名称[规格]{型号}' as str from dual
           union all select '名称[规格]' from dual
           union all select '名称{型号}' from dual  
           union all select '名称' from dual) 
    select substr(str,1,case when instr(str,'[') > 0 then instr(str,'[') - 1
                             when instr(str,'{') > 0 then instr(str,'{') - 1 
                             else length(str) end ) as a  
      from tmp   
      

  9.   

    with t as
     (select 's2s[aa]{xx}' str
        from dual
      union all
      select 's..s2s[aa]' str
        from dual
      union all
      select 's2s{xx}' str
        from dual
      union all
      select 'xxs2?s' str
        from dual)
    select substr(str,
                  1,
                  decode(regexp_instr(str, '[\[|\{]'),
                         0,
                         length(str),
                         regexp_instr(str, '[\[|\{]') - 1))
      from t;
      

  10.   

    可以使用substr和instr来截取sql语句