好像要在sql中使用正则,请会正则的大侠帮帮忙。

解决方案 »

  1.   

    用的是MYSQL 还是 MSSQL
    以下是MSSQL的 
    3,0,1 
    shi = 3 '室型
    ting=0  '厅型 为0不查他!
    wei =1  '卫型
    假设3,2,1|||3,1,1|||2,2,1||| 的字段名为 Housetype
    replace(Housetype,'|||',',')去掉|||并以','替换
    sql = "select * from tab where CharIndex(','+ shi + ',',',' + replace(Housetype,'|||',','))>0 and CharIndex(','+ wei + ',',',' + replace(Housetype,'|||',','))>0"hoho,没试 应该可以
    给分! 0-0
      

  2.   

    用户提交的值修改成 3,[0-9],1
    如house表中room字段存有"3,2,1|||3,1,1|||2,2,1|||"格式的数据,那么sql语句是select * from house where room regexp '3,[0-9],1';
      

  3.   

    为什么不使用模糊查找阿?like不是就可以了?就是建议把这个查找写在sql的最后;
      

  4.   

    应该说这个数据库的结构设计有些不合理,呵呵。在SQL中使用正则表达式,对数据库的性能影响很大哦~....
      

  5.   

    johnpanq(飞花逐月) 我来看看
      

  6.   

    hy_lihuan(我想早恋,可是已经晚了) ,你说得对,我少写了
      

  7.   

    Thaiki(泰麒) 如果用你的方法就要写成这样: where fieldname like '%3,1,1%' or fieldname like '%3,2,1%' or fieldname like '%3,3,1%' fieldname like '%3,4,1%'.....
    好像不行
      

  8.   

    所以要分配处理 是0的就不能找了呀 是这个意思不 楼猪 0-0
    create table test(id int,content varchar(50))
    insert test select 1,'3,2,1|||3,0,1|||2,2,1|||'
    union all select 2,'3,1,1|||3,1,2|||2,2,1|||'
    union all select 3,'3,1,1|||3,2,2|||2,2,1|||'
    union all select 4,'3,2,1|||3,2,2|||2,2,1|||'
    union all select 5,'3,2,1|||3,2,2|||3,2,1|||'
    union all select 6,'5,2,1|||3,2,2|||3,2,1|||'
    goDeclare @S Nvarchar(4000)
    declare @shi varchar(10)
    declare @tin varchar(10)
    declare @wei varchar(10)
    Select @S = '3,0,1'
    select @shi = '5' --假设查找的是5室的 手动这里的值检查一下结果
    select @tin = '0' --假设是0厅的
    select @wei = '1' --假设是1卫的
    --select * from test where content like '%3,0,1%'
    select * from test where CharIndex(','+ @shi + ',',',' + replace(content,'|||',','))>0 and CharIndex(','+ @wei + ',',',' + replace(content,'|||',','))>0 or CharIndex(','+ @tin + ',',',' + replace(content,'|||',','))>0
    --加了个 or 这样也能找0的了
    --复杂了 性能就不知道了 0-0
      

  9.   

    deninghe(毛毛虫)你太强了,这多写出来了,不给你高分不行了!还有我的是mysql 你的sql执行了以后报错。
      

  10.   

    mysql就不熟悉了 
    0-0 ^-^我也不是高手 混混