我从前台传到后台几个数据:标题 title,名字 name,开始时间 starttime,结束时间endtime
然后我想写个数据库查询,查标题,名字,时间。 时间是开始时间和结束时间范围内的,标题,名字开始和结束时间都有可能为空这个该怎么写啊
然后我想写个数据库查询,查标题,名字,时间。 时间是开始时间和结束时间范围内的,标题,名字开始和结束时间都有可能为空这个该怎么写啊
解决方案 »
- ORACLE触发器如何实现一张表中INSERT了新的数据,也往另外一张表中INSERT这些数据?
- Oracle数据库操作
- 一条INSERT INTO语句的错误
- 给个问题思路一个日期下的数据全部更新
- 这几组SQL语句效率哪个高?
- 在视图里可不可以用sum(),group by......? 再现,急,高分请教
- java调用存储过程的问题,百分求助!
- 关于触发器的一个问题
- 怎样把MSSQL中的IMAGE字段倒成ORACLE中
- select index_meg_seq.nextval from table 是什么意思?
- 在线等,今天结帖。要求始终保持一个月数据,并且每个月月末数据始终保留
- 求一sql语句
create or replace procedure p_test
(
in_title varchar2,
in_name varchar2,
in_starttime varchar2,
in_endtime varchar2
out_cursor out sys_refcursor
)
as
str_sql varchar2(1000);
begin
str_sql := 'select * from table_name where 1 = 1 ';
if in_title is not null then
str_sql := str_sql || ' and title = ''' || in_title || '''';
end if;
if in_name is not null then
str_sql := str_sql || ' and name = ''' || in_name || '''';
end if;
if in_starttime is not null then
str_sql := str_sql || ' and time >= ''' || in_starttime || '''';
end if;
if in_endtime is not null then
str_sql := str_sql || ' and time <= ''' || in_endtime || '''';
end if;
open out_cursor for str_sql;
end p_test;
case when start_date is null or end_date is null then NULL else end_date-start_date end as period
end from tbl;没哟编译过,不知道有没有问题
with tb1 as(
select 'title1' title,'name1' name,sysdate time from dual
)
select * from tb1 where title=nvl('title1',title) and name=nvl('name1',name) and time<=nvl(sysdate,time) and time>=nvl(to_date(null),time);
select * from tb1 where title=nvl(传入的title,title) and name=nvl(传入的name,name) and time<=nvl(传入的starttime,time) and time>=nvl(传入的endtime,time);
with tb1 as(
select 'title1' title,'name1' name,sysdate time from dual
)
select * from tb1
where title=nvl(传入的title,title) and
name=nvl(传入的name,name) and
time<=nvl(传入的starttime,time) and
time>=nvl(传入的endtime,time);
--test--
select * from tb1
where title=nvl('title1',title) and
name=nvl('name1',name) and
time<=nvl(sysdate,time) and
time>=nvl(to_date(null),time);
不过为什么LZ不在后台重新组织句SQL去执行呢,这样写法很怪