xoxobool

成功者,永远成功,失败者,永远失败,我要面对者,走向成功!

导航

执行动态语句

create or replace function fn_test2(tablename varchar2) return number is
  rtn number ;
begin
  --通用的获取表的数据行数的函数
  --执行的语句不是固定的,是通过参数组合成的
  --如何执行动态语句
 EXECUTE IMMEDIATE'select count(1)from ' ||tablename into rtn;
-- 'insert into student values(:1,:2)' using 
  return(rtn);
  --捕获异常
 exception when others then
      --处理异常
      dbms_output.put_line('发生异常');
      return(-1);
end fn_test2;

博客整理链接:http://sillyge.blog.163.com/blog/static/1769642082011043547773/ 转载

posted on 2016-10-19 13:30  春之林木  阅读(176)  评论(0编辑  收藏  举报