ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle procedure输入参数为date日期小记

oracle procedure输入参数为date日期小记

原创 Linux操作系统 作者:wisdomone1 时间:2012-11-21 17:39:48 0 删除 编辑
create or replace procedure proc_tuning(in_order_id int,in_order_date date,out_refcursor out sys_refcursor)
is
v_sql varchar2(4000);
begin
  v_sql:='select * from t_orderbill where ';
  if in_order_id is null and in_order_date is null then
    open   out_refcursor for 'select * from t_orderbill ';
  else
 
   if in_order_id is not null then
     v_sql:=v_sql||' order_id= '||chr(39)||in_order_id||chr(39);
   end if;
  
   if in_order_date is not null then
     v_sql:=v_sql||' and order_date='||'to_date('||''''||in_order_date||''''||','||''''||'yyyy-mm-dd'||''''||')';
   end if;
   v_sql:=v_sql||'and 1=1';
   open out_refcursor for v_sql;
  end if;
end proc_tuning;
 
小结:
   1,输入参数还是会传递的是字符串,而非date,最终还要用to_date转化
           2,故输入参数用char还是更好,这样只用一次转化

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

请登录后发表评论 登录
全部评论
提供针对oracle初学者及进阶的数据库培训,欢迎大家咨询: 微信: wisdomone 微信公众号: lovedb 工作经历: 中国普天 北京科蓝 北京云和恩墨 北京神州新桥

注册时间:2008-04-04

  • 博文量
    2189
  • 访问量
    12690140