ITPub博客

首页 > 数据库 > Oracle > 比较符号两边类型保持一致

比较符号两边类型保持一致

原创 Oracle 作者:shuangoracle 时间:2011-02-11 18:29:36 0 删除 编辑
今天测试的时候搞了半天才弄明白,记录一下。
create or replace procedure proc_test(startdate VARCHAR2) as
v_date date; --清理时间点
v_GTH_AGT_IN_count number; --需清理的个数
v_query_create varchar2(3000); --存放建立临时表的语句
begin
v_date := to_date(startdate, 'yyyy-mm-dd');
v_GTH_AGT_IN_count := 0;
select count(*)
into v_GTH_AGT_IN_count
from GTH_AGT_IN t
where logdate <= v_date;
if v_GTH_AGT_IN_count > 0 then
--insert
v_query_create := 'insert into test_table_his as select * from test_table t where t.logdate <= to_date(' ||
to_char(v_date, 'yyyy-mm-dd') || ',''yyyy-mm-dd'')';
EXECUTE IMMEDIATE v_query_create;
/* 上面这两句也可以使用下面这两句
v_query_create := 'insert into his_GTH_AGT_IN as select * from GTH_AGT_IN t where t.logdate <= :v_date';
execute immediate v_query_create using v_date;
*/
--delete
v_query_create := 'delete test_table t where t.logdate <= to_date(' ||
to_char(v_date, 'yyyy-mm-dd') || ',''yyyy-mm-dd'')';
EXECUTE IMMEDIATE v_query_create;
/* 上面这两句也可以使用下面这两句
v_query_create := 'delete GTH_AGT_IN t where t.logdate <= :v_date';
execute immediate v_query_create using v_date;
*/
end if;
commit;
end proc_test;
动态sql中字符串和v_date(date类型)拼接起来,导致v_date隐式转化为字符类型。一定要保证比较符号两边类型一致。
[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24496749/viewspace-1045841/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-08-25

  • 博文量
    84
  • 访问量
    242685