情况如下:
我有一个表(假设是A),A表中有两个字段:Keyword(关键词),ID(ID号)。我要传入一段文字comment,类型是varchar。
希望建立一个存储过程或者程序包来检测comment中是否存在keyword(关键字)。如果存在返回false,否则返回true。
请问这种应该怎么写最合理?

解决方案 »

  1.   

    把 传入的 comment 内容写入到一张表中然后在 select count(comment) from t where comment like '%keyword%'
    查询
      

  2.   


    select * from A where instr(comment,keyword)>0 ;
      

  3.   

    把commet 用translate 函数处理一下 就可以了~
      

  4.   

    CREATE OR REPLACE FUNCTION my_fun(COMMENT IN VARCHAR2 )
    RETURN BOOLEAN
    str VARCHAR2(1);
    begin
       select 'A' INTO str from A where instr(comment,keyword)>0 AND ROWNUM=1;
       IF str='A' THEN
          RETURN TRUE;
       ELSE
          RETURN FALSE;
    EXCEPTION WHEN No_Data_Found THEN
      RETURN FALSE;
    END;
      

  5.   

    申明个变量
    select count(1) into v_num from A where instr(comment,Keyword)>0
    加个判断便可
      

  6.   

    表A 中的keyword 应该不会只有一个值,所以可以建一个游标,和一个record变量,用instr进行一一的keyword比对。
    fetch cur_name into record_name ;
    select instr(record_name.keyword,'comments') into v_num from dual;
    在通过判断v_num的值是否为0 来判断是否包含了keyword。