我用JSP+ORACLE做的一个系统,其中有项功能是在网数据库添加内容时的XTIME字段,网里放的时候第一条纪录初始一个时间(如2007年04月20日10点),而第二条纪录放进去是2007年04月20日16点,第三条纪录放进去是2007年04月21日10点,第四条纪录是2007年04月21日16点.......以此类推,按天循环,就是每天2次,哪位高手能帮我改一下或者是写个时间序列.
大致代码如下:
String NewVals,InsertSQL,Columns;
int prov=4;String XTIME="2007-04-20-10"
Columns="content,prov,sendtime,xuhao,fenlei,XTIME";
NewVals="'"+address+"','"+prov+"',sysdate,ny.nextval,'"+StartTime+"',
'"+XTIME+"";
InsertSQL="INSERT INTO SMS_LH_CONTENT("+Columns+") VALUES ("+IsoConvertGb(NewVals)+")";
大致代码如下:
String NewVals,InsertSQL,Columns;
int prov=4;String XTIME="2007-04-20-10"
Columns="content,prov,sendtime,xuhao,fenlei,XTIME";
NewVals="'"+address+"','"+prov+"',sysdate,ny.nextval,'"+StartTime+"',
'"+XTIME+"";
InsertSQL="INSERT INTO SMS_LH_CONTENT("+Columns+") VALUES ("+IsoConvertGb(NewVals)+")";
解决方案 »
- 部署产品时,连接ORACLE数据报如下错误,速度求解……
- 请教Oracle定时任务的interval的两种设置表示什么意思?
- 求助SQL语句汇总求合问题
- insert语句问题
- 如何仅仅保存COMMIT后前面最后一条记录?
- oracle8i for windowsNT实用指南上第四章的source code。看不懂。
- 求一条sql语句!请高手帮忙!
- 怎么把sqlserver中某个表的数据倒入到oracle中的表中??两个表的结构相同.
- 有人用过ERWIN么
- Oracle恢复表数据到任意时间点以前(求大神解答)
- 着急啊!!如何根据表名从系统表里面取出主键对应的字段名称??
- oracle 的system表空间使用率特别高,这是怎么回事?
不考虑异常,可以这么做SQL> create or replace package pk_myprocess
2 is
3 function get_p_date return date;
4 function rollback_date return date;
5 end pk_myprocess;
6 /Package createdSQL> create or replace package body pk_myprocess
2 is
3 last_date date;
4 function get_p_date return date
5 is
6 v_pdate date;
7 begin
8 if last_date = to_date(to_char(sysdate,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss') then
9 v_pdate := to_date(to_char(sysdate,'yyyy-mm-dd')||' 16:00:00','yyyy-mm-dd hh24:mi:ss');
10 else
11 v_pdate := to_date(to_char(sysdate,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss');
12 last_date := v_pdate;
13 end if;
14 return v_pdate;
15 end get_p_date;
16 function rollback_date return date
17 is
18 v_pdate date;
19 begin
20 last_date := nvl(last_date,sysdate - 1);
21 if last_date = to_date(to_char(last_date,'yyyy-mm-dd')||' 16:00:00','yyyy-mm-dd hh24:mi:ss') then
22 v_pdate := to_date(to_char(last_date,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss');
23 else
24 v_pdate := to_date(to_char(last_date - 1,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss');
25 last_date := v_pdate;
26 end if;
27 return v_pdate;
28 end rollback_date;
29
30 end pk_myprocess;
31 /Package body createdSQL> create table test_a(id number,edit_date date,p_date date);SQL> insert into test_a values(1,sysdate,pk_myprocess.get_p_date);1 row insertedSQL> commit;Commit completeSQL> insert into test_a values(2,sysdate,pk_myprocess.get_p_date);1 row insertedSQL> commit;Commit complete
SQL> select id,to_char(edit_date,'yyyy-mm-dd hh24:mi:ss') as edit_date,
2 to_char(p_date,'yyyy-mm-dd hh24:mi:ss') as p_date from test_a; ID EDIT_DATE P_DATE
---------- ------------------- -------------------
1 2007-04-26 11:14:16 2007-04-26 10:00:00
2 2007-04-26 11:14:16 2007-04-26 16:00:00
2 is
3 function get_p_date return date;
4 function rollback_date return date;
5 end pk_myprocess;
6 /Package createdSQL> create or replace package body pk_myprocess
2 is
3 last_date date;
4 function get_p_date return date
5 is
6 v_pdate date;
7 begin
8 last_date := nvl(last_date,trunc(sysdate));
9 if last_date = to_date(to_char(last_date,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss') then
10 v_pdate := to_date(to_char(last_date,'yyyy-mm-dd')||' 16:00:00','yyyy-mm-dd hh24:mi:ss');
11 else
12 if last_date < to_date(to_char(last_date,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss') then
13 v_pdate := to_date(to_char(last_date ,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss');
14 else
15 v_pdate := to_date(to_char(last_date + 1,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss');
16 end if;
17 end if;
18 last_date := v_pdate;
19 return v_pdate;
20 end get_p_date;
21 function rollback_date return date
22 is
23 v_pdate date;
24 begin
25 last_date := nvl(last_date,sysdate - 1);
26 if last_date = to_date(to_char(last_date,'yyyy-mm-dd')||' 16:00:00','yyyy-mm-dd hh24:mi:ss') then
27 v_pdate := to_date(to_char(last_date,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss');
28 else
29 v_pdate := to_date(to_char(last_date - 1,'yyyy-mm-dd')||' 10:00:00','yyyy-mm-dd hh24:mi:ss');
30 end if;
31 last_date := v_pdate;
32 return v_pdate;
33 end rollback_date;
34
35 end pk_myprocess;
36 /Package body createdSQL> drop table test_a;Table droppedSQL> create table test_a(id number,edit_date date,p_date date);Table createdSQL> insert into test_a values(1,sysdate,pk_myprocess.get_p_date);1 row insertedSQL> commit;Commit completeSQL> insert into test_a values(2,sysdate,pk_myprocess.get_p_date);1 row insertedSQL> insert into test_a values(3,sysdate,pk_myprocess.get_p_date);1 row insertedSQL> select id,to_char(edit_date,'yyyy-mm-dd hh24:mi:ss') as edit_date,
2 to_char(p_date,'yyyy-mm-dd hh24:mi:ss') as p_date from test_a; ID EDIT_DATE P_DATE
---------- ------------------- -------------------
1 2007-04-27 17:31:19 2007-04-27 10:00:00
2 2007-04-27 17:31:20 2007-04-27 16:00:00
3 2007-04-27 17:31:20 2007-04-28 10:00:00SQL>
我用这个到网页就不知道为什么不对了 在数据库就可以
我在网业里都是显示4/27/2007 10:0:0 不管多少条 以后都是这个时间
你懂JSP吗 这是我在网业中用的插入语句 XTIME就是调用的这个函数
你帮我看看是哪错了
Columns="content,prov,sendtime,xuhao,fenlei,xtime";
NewVals="'"+address+"','"+prov+"',sysdate,ny.nextval,'"+StartTime+"',pk_myprocess.get_p_date";
InsertSQL="INSERT INTO SMS_LH_CONTENT("+Columns+") VALUES ("+IsoConvertGb(NewVals)+")";