Oracle 函数中动态执行语句
时间:2021-07-01 10:21:17
帮助过:2人阅读
create or replace function fn_test(tablename
in varchar2)
return number is
2 sqls
varchar2(
100);
3 rtn
number(
10):
=0;
4 begin
5 --获取学生表的记录条数
6 --select count(*) into rtn from student;
7
8 sqls:
=‘select count(*) from ‘ || tablename;
9 execute immediate sqls
into rtn;
10 dbms_output.put_line(
‘记录条数 rtn=‘|| rtn);
11 return(rtn);
12 end fn_test;
SQL:
1 select fn_test(‘student‘) from dual;
注意项:在拼接SQL语句的时候,查询语句 from 关键字与要拼接的表名之间必须要记得加空格。
Oracle 函数中动态执行语句
标签: