oracle数据库里面有一个字段是vchar类型的,数据集合了很多内容啊!
如下
tmpTable
id filed1
1 ...长度(1) 高度(2).......
2 ...长度(3) 宽度(1) 高度(5)..
3 ...边长(6).......
4 ...长度:(1) 高度(8)......
5 ...正方体......我希望
输入 "长度" 和 1 就能检索出记录1,和4
输入 "高度" 和 2 就能检索出记录1
输入 "长度" 和 3 就能检索出记录2
注:
filed1字段里面的数据可能是任意的!但是如果存在"长度"内容的话格式一定是
"长度"+符号或没符号+ "(" +数字 +")"+ 空格或者没有空格
即都是:
长度:(10) 高度.....
长度(10) 高度.....
类似这样的数据

解决方案 »

  1.   

    看这行不?照着符号是:的写的
    SQL> create or replace procedure pro_tmp(v_1 varchar2, v_2 number) is
      2    cu number;
      3  begin
      4    select count(*)
      5      into cu
      6      from tmptable
      7     where instr(field1, v_1 || '(' || v_2 || ')')> 0 or instr(field1,v_1 || ':(' || v_2 || ')') > 0;
      8      if (cu > 0) then
      9       for cu in (select *
     10                    from tmptable
     11                   where instr(field1,v_1 || '(' || v_2 || ')') > 0 or instr(field1,v_1 || ':(' || v_2 || ')') > 0) loop dbms_output.put_line(cu.id||'   '|| cu.field1);
     12  end loop; else dbms_output.put_line('没有你要的数据');
     13  end if;
     14  end;
     15  ;
     16  /Warning: Procedure created with compilation errorsSQL> 
    SQL> create or replace procedure pro_tmp(v_1 varchar2, v_2 number) is
      2    cu number;
      3  begin
      4    select count(*)
      5      into cu
      6      from tmptable
      7     where instr(field1, v_1 || '(' || v_2 || ')')> 0 or instr(field1,v_1 || ':(' || v_2 || ')') > 0;
      8      if (cu > 0) then
      9       for cu in (select *
     10                    from tmptable
     11                   where instr(field1,v_1 || '(' || v_2 || ')') > 0 or instr(field1,v_1 || ':(' || v_2 || ')') > 0) loop dbms_output.put_line(cu.id||'   '|| cu.field1);
     12  end loop; else dbms_output.put_line('没有你要的数据');
     13  end if;
     14  end;
     15  /Procedure createdSQL> set serveroutput on ;
    SQL> exec pro_tmp('长度',1);1    ...长度(1) 高度(2)....... 4   ...长度:(1) 高度(8)...... PL/SQL procedure successfully completedSQL> exec pro_tmp('长度',2);没有你要的数据PL/SQL procedure successfully completedSQL> exec pro_tmp('高度',2);1    ...长度(1) 高度(2)....... 
    PL/SQL procedure successfully completedSQL> exec pro_tmp('长度',3);2   ...长度(3) 宽度(1) 高度(5).. 
    PL/SQL procedure successfully completed
      

  2.   

    SQL> select * from test;         X Y
    ---------- ----------------------------------------
             1 ...长度(1) 高度(2).......
             2 ...长度(3) 宽度(1) 高度(5)..
             3 ...边长(6).......
             4 ...长度:(1) 高度(8)......
             5 ...正方体......
    SQL> variable a varchar2(40)
    SQL> variable b numberSQL> exec :a:='长度';:b:=1;PL/SQL 过程已成功完成。SQL> select * from test where y like '%'||:a||'_('||:b||'%' or y like '%'||:a||'('||:b||'%';         X Y
    ---------- ----------------------------------------
             1 ...长度(1) 高度(2).......
             4 ...长度:(1) 高度(8)......
      

  3.   

    SQL> select * from test where y like '%'||:a||'_('||:b||'%' or y like '%'||:a||'('||:b||')%';
      

  4.   

    还是少个括号,改一下:
    SQL> select * from test where y like '%'||:a||'_('||:b||'%' or y like '%'||:a||'('||:b||')%';
      

  5.   

    上次不是有一个数据,可以用INSTR函数来实现!