我从程序传递where子句参数值但是当我发送至少一个值时,我得到结果但是如果我发送所有参数为null没有输出即将到来,我想要一个查询,如果所有参数发送为null将显示数据库中的所有记录
以下是在满足一个条件时检索值的查询
SELECT *
FROM STUDENT
LEFT JOIN COURSE
ON STUDENT.COURSE_ID = COURSE.COURSE_ID
WHERE STUDENT.STD_ID = null
OR STUDENT.STD_NAME = null
OR STUDENT.STD_START_DATE = null
OR STUDENT.STD_END_DATE = null
OR STUDENT.STD_GENDER = null
OR STUDENT.COURSE_ID = null;
答案 0 :(得分:2)
尝试以下,
SELECT *
FROM STUDENT
LEFT JOIN COURSE
ON STUDENT.COURSE_ID = COURSE.COURSE_ID
WHERE STUDENT.STD_ID IS NULL
OR STUDENT.STD_NAME IS NULL
OR STUDENT.STD_START_DATE IS NULL
OR STUDENT.STD_END_DATE IS NULL
OR STUDENT.STD_GENDER IS NULL
OR STUDENT.COURSE_ID IS NULL
答案 1 :(得分:0)
得到了解决方案:
SELECT *
FROM
STUDENT S,COURSE C
WHERE
S.STD_ID like '%'||null||'%' and S.STD_NAME like '%'||null ||'%' and S.STD_START_DATE like '%'||null ||'%' and S.STD_END_DATE like '%'||null ||'%' and S.STD_GENDER like '%'||null||'%'
and S.COURSE_ID like '%'||null||'%' and S.COURSE_ID=C.COURSE_ID