在日期获得时获得的格式既然是这样的 '02-2月 -10'
但在 seleect to_date('20100202','yyyy/mm/dd') from dual;中获得的是 2010/02/02这样的
怎么在过程中获得 2010/02/02这种格式那
在一个过程中执行如下
create or replace procedure sp_custcharstat
is
v_custno varchar2(100);
v_fundcode varchar2(100);
v_date date;
v_begindate date;
v_enddate date;
v_diffday number;
v_lastshares number(16,2);
i number;
v_count number;
type refcursor is ref cursor;
v_cursor refcursor;
v_time varchar2(10); --当前时间
tmp_table varchar2(50);
v_sql varchar2(500);
v_defaultTablespace varchar2(30) := 'crm_htable';--CRM计算默认表空间
begin
v_time := to_char(sysdate,'hh24miss');
v_begindate :=to_date('20100202','yyyy/mm/dd');
v_enddate :=to_date('20120202','yyyy/mm/dd');
v_diffday :=v_enddate-v_begindate;
tmp_table :='tpcrm_sharecurrent_'||v_time||'';
select c_value into v_defaultTablespace from tsysparameter where c_item='crmHistoryTableSpace';
--删除表
-- execute immediate 'truncate table '||tmp_table||'';
-- execute immediate 'drop table '||tmp_table||'';
--创建临时表
v_sql :='create table '||tmp_table||' tablespace '||v_defaultTablespace||' nologging as select d_cdate, c_custno ,c_fundcode ,f_lastshares from tsharecurrents ';
dbms_output.put_line(v_sql);
execute immediate v_sql;
v_sql := ' select c_custno,c_fundcode,f_lastshares from '||tmp_table||'';
for i in 0..v_diffday loop
open v_cursor for v_sql;
loop
fetch v_cursor into v_custno,v_fundcode,v_lastshares;
v_date := to_date('20100202','yyyy/mm/dd')+i;
dbms_output.put_line(v_date);
exit when v_cursor%notfound;
v_sql :='select count(*) from '||tmp_table||' t where t.c_custno = '''||v_custno||''' and t.c_fundcode = '''||v_fundcode||''' and t.d_cdate=to_date('''||v_date||''',''yyyy/mm/dd'')';
dbms_output.put_line(v_sql);
execute immediate v_sql into v_count;
if v_count = 0 then
v_sql :='insert into '||tmp_table||' as select c_custno,c_fundcode,f_lastshares from '||tmp_table||' where t.c_custno = '''||v_custno||''' and t.c_fundcode = '''||v_fundcode||''' and t.d_cdate=(to_date('''||v_date||''',''yyyy/mm/dd'')-1)';
dbms_output.put_line(v_sql);
v_custno:=null;
v_fundcode:=null;
v_lastshares:=null;
execute immediate v_sql;
commit;
end if;
end loop;
end loop;
end
/
但在 seleect to_date('20100202','yyyy/mm/dd') from dual;中获得的是 2010/02/02这样的
怎么在过程中获得 2010/02/02这种格式那
在一个过程中执行如下
create or replace procedure sp_custcharstat
is
v_custno varchar2(100);
v_fundcode varchar2(100);
v_date date;
v_begindate date;
v_enddate date;
v_diffday number;
v_lastshares number(16,2);
i number;
v_count number;
type refcursor is ref cursor;
v_cursor refcursor;
v_time varchar2(10); --当前时间
tmp_table varchar2(50);
v_sql varchar2(500);
v_defaultTablespace varchar2(30) := 'crm_htable';--CRM计算默认表空间
begin
v_time := to_char(sysdate,'hh24miss');
v_begindate :=to_date('20100202','yyyy/mm/dd');
v_enddate :=to_date('20120202','yyyy/mm/dd');
v_diffday :=v_enddate-v_begindate;
tmp_table :='tpcrm_sharecurrent_'||v_time||'';
select c_value into v_defaultTablespace from tsysparameter where c_item='crmHistoryTableSpace';
--删除表
-- execute immediate 'truncate table '||tmp_table||'';
-- execute immediate 'drop table '||tmp_table||'';
--创建临时表
v_sql :='create table '||tmp_table||' tablespace '||v_defaultTablespace||' nologging as select d_cdate, c_custno ,c_fundcode ,f_lastshares from tsharecurrents ';
dbms_output.put_line(v_sql);
execute immediate v_sql;
v_sql := ' select c_custno,c_fundcode,f_lastshares from '||tmp_table||'';
for i in 0..v_diffday loop
open v_cursor for v_sql;
loop
fetch v_cursor into v_custno,v_fundcode,v_lastshares;
v_date := to_date('20100202','yyyy/mm/dd')+i;
dbms_output.put_line(v_date);
exit when v_cursor%notfound;
v_sql :='select count(*) from '||tmp_table||' t where t.c_custno = '''||v_custno||''' and t.c_fundcode = '''||v_fundcode||''' and t.d_cdate=to_date('''||v_date||''',''yyyy/mm/dd'')';
dbms_output.put_line(v_sql);
execute immediate v_sql into v_count;
if v_count = 0 then
v_sql :='insert into '||tmp_table||' as select c_custno,c_fundcode,f_lastshares from '||tmp_table||' where t.c_custno = '''||v_custno||''' and t.c_fundcode = '''||v_fundcode||''' and t.d_cdate=(to_date('''||v_date||''',''yyyy/mm/dd'')-1)';
dbms_output.put_line(v_sql);
v_custno:=null;
v_fundcode:=null;
v_lastshares:=null;
execute immediate v_sql;
commit;
end if;
end loop;
end loop;
end
/
解决方案 »
- 表空间使用率为99%,对数据库访问性能有没有影响呢?
- was6.1 Io 异常: The Network Adapter could not establish the connection
- 怎样跟踪oracle里面的函数呢?
- 怎样把Oracle中的表数据插入到informix表中
- 难度大一点的sql语句,请教高手指教???欢迎来踩踩我!
- ORACE数据库还是打不开?
- 关于HIBERNATE查询时 “返回一个JAVA对象的”问题?
- NET MANAGER的问题
- 小弟我初学SQL,请教高手几个基础的概念问题……
- 请教proc高手:proc 连接与网络函数select 冲突的bug
- oracle分组求和 行变列问题
- expdp 导出是提示 文件操作无效 ,高手请指导。
顯示的也是默認格式,使用varchar2就可以了,如v_begindate varchar2(20);
此時你再轉換就會為你要的格式了
select to_char(sysdate,'yyyy/mm/dd') from dual;
或者: dbms_output.put_line(to_char(v_date,'yyyy/mm/dd'));
這種處理