不能使用'LIKE%'||我的查询没有像我预期的那样返回所有行

时间:2016-08-05 06:41:23

标签: sql asp.net oracle plsql

我在c#中有一个查询(带有Oracle命令和Oracle参数)。我想使用用户从数据库获取数据时输入的输入。

这是我的疑问:

0

用户可以搜索只输入一个输入或所有输入,或者不输入任何输入。

注意:我听说过,'like%'不适用于具有空列的行。但是我的数据库必须有空列。我需要建议。我能做什么?

4 个答案:

答案 0 :(得分:2)

对于每个参数,如果给出了用户输入,则评估 BitmapPool bitmapPool = Glide.get(activity).getBitmapPool(); int microSecond = 6000000;// 6th second as an example VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond); FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888); Glide.with(activity) .load(videoPath) .asBitmap() .override(50,50)// Example .videoDecoder(fileDescriptorBitmapDecoder) .into(holder.ivFirstUpload); 。否则用户输入LIKE

IS NULL

答案 1 :(得分:1)

这里解决的问题是解决方案;

"SELECT USER_ID, FIRSTNAME, LASTNAME FROM USERS WHERE (USER_ID LIKE :userid || '%' OR USER_ID IS NULL) AND (FIRSTNAME LIKE :firstname || '%' OR FIRSTNAME IS NULL) AND(LASTNAME LIKE :lastname || '%' OR LASTNAME IS NULL) AND (DEPARTMENT LIKE :department || '%' OR DEPARTMENT IS NULL) AND (TEAM LIKE :team || '%' OR TEAM IS NULL) AND (SUBTEAM LIKE :subteam || '%' OR SUBTEAM IS NULL) AND (MACHINE LIKE :machine || '%' OR MACHINE IS NULL)"

答案 2 :(得分:-1)

如果用户输入为空缺失值,请尝试此

SELECT USER_ID, FIRSTNAME, LASTNAME FROM USERS 
WHERE (USER_ID LIKE :userid || '%'  OR :userid='')
AND (FIRSTNAME LIKE :firstname || '%'    OR :firstname ='')
AND (LASTNAME LIKE :lastname || '%'   OR :lastname='')
AND (DEPARTMENT LIKE :department || '%'   OR :department='')
AND (TEAM LIKE :team || '%'   OR :team='')
AND (SUBTEAM LIKE :subteam || '%'   OR :subteam='')
AND (MACHINE LIKE :machine || '%'  OR :machine='')

答案 3 :(得分:-1)

那么也许你可以比较NVL(..,'x')?

SELECT USER_ID, FIRSTNAME, LASTNAME FROM USERS 
 WHERE (nvl(USER_ID   ,'¬') LIKE nvl(:userid     , '¬')|| '%' )
   AND (nvl(FIRSTNAME ,'¬') LIKE nvl(:firstname  , '¬')|| '%' )
   AND (nvl(LASTNAME  ,'¬') LIKE nvl(:lastname   , '¬')|| '%' )
   AND (nvl(DEPARTMENT,'¬') LIKE nvl(:department , '¬')|| '%' )
   AND (nvl(TEAM      ,'¬') LIKE nvl(:team       , '¬')|| '%' )
   AND (nvl(SUBTEAM   ,'¬') LIKE nvl(:subteam    , '¬')|| '%' )
   AND (nvl(MACHINE   ,'¬') LIKE nvl(:machine    , '¬')|| '%' )
;