实现 int 类型(比如id)的模糊查询

LMS项目的user id 的模糊查询  做不出来  网上找到的解法

http://zhidao.baidu.com/question/434223706.html


where student_id like 'p%',但是'p%'是查不了的啊,该怎么办?哪位大神教教?

我来帮他解答


2012-6-6 22:40
满意回答
用%p%,如果只是p%就是p开头了学号而不是包含p的学号了
追问
我想我解释错我的问题了,我的意思是比如现在在一个过程中我输入p=2011,我想查询所有开头为2011的学号
回答
学号的数据库字段类型是int吗?是的话要cast(student_id as string)
追问
我想我解释错我的问题了,我的意思是比如现在在一个过程中我输入p=2011,我想查询所有开头为2011的学号。也就是p是参数,可以有很多值
回答
是啊,你输入2011,拼出来的sql语句应该是where student_id like '2011%',你直接把这sql语句运行下看看有没问题吧,可能那里拼写错了什么的sql语句要拼好再继续执行,不可能sql语句里面的p就是上面定义的p的值,sql语句只是一个string,都有手动拼起来的
追问
我把代码给你看一下吧create or replace procedure pro_GetStudentNum(p_class_id char,p_course char)as  v_num NUMBER;begin    select count(*)into v_num from score where class_id like 'p_class_id%'  and course_id=p_course and score>='60';  dbms_output.put_line('该课程大于60分的人数为:'||v_num);end pro_GetStudentNum;我在写一个过程,可以按输入的指定班级指定课程查询成绩
回答
like (p_class_id +'%'),直接用 'p_class_id%'就是'p_class_id%不能读取参数了


原文地址:https://www.cnblogs.com/jilodream/p/4222786.html