码迷,mamicode.com
首页 > 数据库 > 详细

oracle函数及存储过程

时间:2016-04-29 21:58:15      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

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;

 

oracle函数及存储过程

标签:

原文地址:http://www.cnblogs.com/begin-zero/p/5447486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!