高分求教sql查询问题

todayg 2009-07-23 10:31:35
select * from table_name a where a.name=[入参]

如果,想实现 [入参] 为空时,查询出所有的记录;[入参] 为定值时,查询出输入值的相应记录。

请问,能否实现,where条件后该如何修改?
...全文
80 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xpzhl 2009-07-23
  • 打赏
  • 举报
回复
select * from table_name a where a.name like '%$入参%'
todayg 2009-07-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lgfaichl 的回复:]
select * from table_name a where a.name=decode(param1,null,a.name,param1);
其中param1为参数!
[/Quote]

非常感谢,要的就是这个效果。
lgfaichl 2009-07-23
  • 打赏
  • 举报
回复
记得在参数加$符号哦
lgfaichl 2009-07-23
  • 打赏
  • 举报
回复
select * from table_name a where a.name=decode(param1,null,a.name,param1);
其中param1为参数!
yangzeDB 2009-07-23
  • 打赏
  • 举报
回复
有好几个月没有来CSDN 了 没有orcle环境 用MS sqlserver 帮你实现一下
yangzeDB 2009-07-23
  • 打赏
  • 举报
回复

if not object_id('Tempdb..T_20081010') is null
drop table T_20081010
Go
Create table T_20081010([ID] int,[S_ID] nvarchar(1),[P_ID] nvarchar(10))
Insert T_20081010
select 1,'a','2009-02-00' union all
select 2,'a','2009-02-28' union all
select 3,'b','2009-01-28' union all
select 4,'b','2009-01-25' union all
select 5,'b','2009-02-27' union all
select 6,'b','2009-02-26'
Go
--Select * from T_20081010

declare @P int
set @P=''
select * from T_20081010
where (case when (id=@p) then 1 when @p='' then 1 else 0 end)=1
todayg 2009-07-23
  • 打赏
  • 举报
回复
为定值都好处理,主要是,不输入条件,能否实现查询出全部记录
oracle_plsql 2009-07-23
  • 打赏
  • 举报
回复
select * from table_name a where a.name in (&入参) ______________取的是定值
oracle_plsql 2009-07-23
  • 打赏
  • 举报
回复
请问怎么加$这个符号select * from table_name a where a.name=decode(param1,null,a.name,param1);

17,078

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧