0

在此处输入图像描述

我想搜索有java和oracle技能的名字

我知道这样的编码

select name from table_name where skills like '%java%' or skills like '%oracle%';

但我的问题是,在 servlet 中我该怎么做?

String skills=request.getParameter("skill");

我的选择查询

select name from table_name where skill like '"++"';

在这里我很困惑,我试过这样

select name from table_name where skill like '"+%skills%+"';

但不工作。

我是一个对 oracle 非常陌生的网络开发人员,请帮助我

我正在使用 oracle10g

4

2 回答 2

1

你可以试试REGEXP_LIKE

SELECT name from TABLENAME where  
WHERE REGEXP_LIKE (skills, '(Java|Oracle)');
于 2012-07-10T08:07:44.930 回答
1
    String query = "select name from table_name";
    String skills = request.getParameter("skill");
    StringBuilder likePart = new StringBuilder("");
    boolean appendOrClause = false;
    String skillsArray[] = skills == null ? null : skills.split(",");

    if(skillsArray != null && skillsArray.length > 0 ){
        for(String skill : skillsArray){
            if(skill.trim().length() > 0){
                if(appendOrClause){
                    likePart.append(" OR skills like '%" + skill.trim() + "%'");
                } else {
                    likePart.append(" where skills like '%" + skill.trim() + "%'");
                }
                appendOrClause = true;
            }
        }
        if(likePart.toString().trim().length() > 0){
            query += likePart.toString();
        }
    }
    if(query.indexOf("like") > 0 ){
        // User have skills
        // Fire query to get User Name
    } else {
        // User doesn't have any skills
        // don't Fire any query
    }
于 2012-07-10T08:31:08.493 回答