oracel 查询 请教:select * from table1 where 1=1 and table1.s1 = ?;

[复制链接]
查看11 | 回复3 | 2010-11-9 09:37:11 | 显示全部楼层 |阅读模式
在java中,sql传值,如果 ? 有值,则返回:select * from table1 where 1=1 and table1.s1 = ?;如果?为空,则返回select * from table1 where 1=1;
关键是sql语句拼串不知道如何写,请高手指教
不是啊,
我的要求是?值必须传入,如果?为空,则不需要这个查询条件,而不是 table1.s1 = null。
盼高手回答!

回复

使用道具 举报

千问 | 2010-11-9 09:37:11 | 显示全部楼层
string strsql,strS1;//strS1 代表?值的来源strS1="";//赋初始值strS1=这里是值的来源;//赋值strsql="select * from table1 where 1=1";if (strS1 !=""){ strsql=strsql+" and table1.s1 = ?"; }把strS1的值替换语句中的?
回复

使用道具 举报

千问 | 2010-11-9 09:37:11 | 显示全部楼层
StringBuffer str = new StringBuffer("select * from table1 where 1=1");if(? !=null){str.append(" and table1.s1 = ?");}
回复

使用道具 举报

千问 | 2010-11-9 09:37:11 | 显示全部楼层
(1=1 and table1.s1 = ?)or(1=1 and table1.s1 = null)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行