17,377
社区成员
发帖
与我相关
我的任务
分享
CTime t;
t=CTime::GetCurrentTime();
CString daystamp;
daystamp.Format("%d-%d-%d",t.GetYear(),t.GetMonth(),t.GetDay());
SELECT to_char(updatetime,'yyyy-mm-dd') as updatetime, sum(test_date) as test_date FROM
test where to_char(updatetime,'yyyy-mm-dd')='"+daystamp+"' group by to_char(updatetime,'yyyy-mm-dd')
,这样到该语句就运行不下去了, 将"="更改为">"和"<"均不行。SELECT to_char(updatetime,'yyyy-mm-dd') as updatetime, sum(test_date) as test_date FROM test
where to_char(updatetime,'yyyy-mm-dd')='2012-07-25' group by to_char(updatetime,'yyyy-mm-dd')
SELECT to_char(updatetime,'yyyy-mm-dd') as updatetime, sum(test_date) as test_date FROM test
where to_date(to_char(updatetime,'yyyy-mm-dd'),'yyyy-mm-dd')=to_date('"+daystamp+"','yyyy-mm-dd') group by to_char(updatetime,'yyyy-mm-dd')
SELECT to_char(updatetime,'yyyy-mm-dd') as updatetime, sum(test_date) as test_date FROM test
where to_date(to_char(updatetime,'yyyy-mm-dd'),'yyyy-mm-dd')=to_date('2012-08-03','yyyy-mm-dd') group by to_char(updatetime,'yyyy-mm-dd')
该处运行正常。execute immediate 'SELECT to_char(updatetime,''yyyy-mm-dd'') as updatetime,
sum(test_date) as test_date
FROM test
where to_char(updatetime,''yyyy-mm-dd'')='||daystamp||'
group by to_char(updatetime,''yyyy-mm-dd'')'
SELECT to_char(updatetime,'yyyy-mm-dd') as updatetime, sum(test_date) as test_date FROM test
where to_date(to_char(updatetime,'yyyy-mm-dd'),'yyyy-mm-dd')=to_date('"||daystamp||"','yyyy-mm-dd') group by to_char(updatetime,'yyyy-mm-dd')
--还是sql语句没写好吧,
--c++里的sql查询字符串
"SELECT to_char(updatetime,'yyyy-mm-dd') as updatetime,
sum(test_date) as test_date
FROM test
where to_char(updatetime,'yyyy-mm-dd')='"+daystamp+"'
group by to_char(updatetime,'yyyy-mm-dd')"
--oracle里的sql ,动态sql
execute immediate 'SELECT to_char(updatetime,''yyyy-mm-dd'') as updatetime,
sum(test_date) as test_date
FROM test
where to_char(updatetime,''yyyy-mm-dd'')='+daystamp+'
group by to_char(updatetime,''yyyy-mm-dd'')'
set serveroutput on;
declare
v_time1 varchar2(20) :='2012-03-04 12:03:04';
v_time2 varchar2(20) :='2012.03.05';--你的字符串應像這種或'2012-03-05'或'2012/03/05'都可以的
begin
dbms_output.put_line('v_time1:'||to_date(v_time1,'yyyy-mm-dd'));
exception
when others then
dbms_output.put_line('v_time1:日期格式轉換出錯');
dbms_output.put_line('v_time2:'||to_date(v_time2,'yyyy-mm-dd'));
end;
/
--看这个例子你可能就明白了
SQL> set serveroutput on;
SQL> declare
2 v_time1 varchar2(20) :='2012-03-04 12:03:04';
3 v_time2 varchar2(20) :='2012.03.05';
4 begin
5 dbms_output.put_line('v_time1:'||to_date(v_time1,'yyyy-mm-dd'));
6 exception
7 when others then
8 dbms_output.put_line('v_time1:日期格式轉換出錯');
9 dbms_output.put_line('v_time2:'||to_date(v_time2,'yyyy-mm-dd'));
10 end;
11 /
v_time1:日期格式轉換出錯
v_time2:05-3月 -12
已順利完成 PL/SQL 程序.