标签:
1、函数
create or replace function getTableCount(table_name varchar2) return number as
begin
declare sql_query varchar2(300);
t_count number;
begin
sql_query:=‘select count(*) from ‘ || table_name; //from后面有个空格
execute immediate sql_query into t_count;
return t_count;
end;
end getTableCount;
调用函数
begin
dbms_output.put_line(getTableCount(‘t_book‘));
end;
2、存储过程
create or replace procedure addbook(bookName in varchar2,bookTypeId in number,n1 out number) as
begin
declare maxId number;
n number;
begin
select count(*) into n from t_book where name1=bookName;
select count(*) into n1 from t_book;
if n>0 then
return;
end if;
select max(id) into maxId from t_book;
insert into t_book values(maxId+1,bookName,bookTypeId);
commit;
end;
end addbook;
调用
set serveroutput on;
declare num1 number;
begin
addbook(‘java11‘,1,num1);
dbms_output.put_line(num1);
end;
标签:
原文地址:http://www.cnblogs.com/begin-zero/p/5447486.html