函数: 1 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 关键字与要拼接的表名之间必须要记得加空格。
时间: 2024-10-01 07:31:22