oracle——笔记——存储过程简介
create table emp2 ( empno number(4), ename varchar2(10), job varchar2(9), mgr number(4), hiredate date, sal number(7,2), comm number(7,2), deptno number(2) ); ----------------------------------------------------------------------------------------------------------- insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7369, 'SMITH', 'CLERK', 7902, to_date('17-12-1980', 'dd-mm-yyyy'), 800.00, null, 20); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7499, 'ALLEN', 'SALESMAN', 7698, to_date('20-02-1981', 'dd-mm-yyyy'), 1600.00, 300.00, 30); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7521, 'WARD', 'SALESMAN', 7698, to_date('22-02-1981', 'dd-mm-yyyy'), 1250.00, 500.00, 30); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7566, 'JONES', 'MANAGER', 7839, to_date('02-04-1981', 'dd-mm-yyyy'), 2975.00, null, 20); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7654, 'MARTIN', 'SALESMAN', 7698, to_date('28-09-1981', 'dd-mm-yyyy'), 1250.00, 1400.00, 30); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7698, 'BLAKE', 'MANAGER', 7839, to_date('01-05-1981', 'dd-mm-yyyy'), 2850.00, null, 30); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7782, 'CLARK', 'MANAGER', 7839, to_date('09-06-1981', 'dd-mm-yyyy'), 2450.00, null, 10); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7788, 'SCOTT', 'ANALYST', 7566, to_date('19-04-1987', 'dd-mm-yyyy'), 3000.00, null, 20); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7839, 'KING', 'PRESIDENT', null, to_date('17-11-1981', 'dd-mm-yyyy'), 5000.00, null, 10); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7844, 'TURNER', 'SALESMAN', 7698, to_date('08-09-1981', 'dd-mm-yyyy'), 1500.00, 0.00, 30); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7876, 'ADAMS', 'CLERK', 7788, to_date('23-05-1987', 'dd-mm-yyyy'), 1100.00, null, 20); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7900, 'JAMES', 'CLERK', 7698, to_date('03-12-1981', 'dd-mm-yyyy'), 950.00, null, 30); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7902, 'FORD', 'ANALYST', 7566, to_date('03-12-1981', 'dd-mm-yyyy'), 3000.00, null, 20); insert into emp2 (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) values (7934, 'MILLER', 'CLERK', 7782, to_date('23-01-1982', 'dd-mm-yyyy'), 1300.00, null, 10); ============================================================================================================================= create table dept2 ( deptno number(2), dname varchar2(14), loc varchar2(13) ); ---------------------------------------------------- insert into dept2 (DEPTNO, DNAME, LOC) values (10, 'ACCOUNTING', 'NEW YORK'); insert into dept2 (DEPTNO, DNAME, LOC) values (20, 'RESEARCH', 'DALLAS'); insert into dept2 (DEPTNO, DNAME, LOC) values (30, 'SALES', 'CHICAGO'); insert into dept2 (DEPTNO, DNAME, LOC) values (40, 'OPERATIONS', 'BOSTON'); ============================================================ create table salgrade2 ( grade number, losal number, hisal number ); -------------------------------------------------- insert into salgrade2 (GRADE, LOSAL, HISAL) values (1, 700, 1200); insert into salgrade2 (GRADE, LOSAL, HISAL) values (2, 1201, 1400); insert into salgrade2 (GRADE, LOSAL, HISAL) values (3, 1401, 2000); insert into salgrade2 (GRADE, LOSAL, HISAL) values (4, 2001, 3000); insert into salgrade2 (GRADE, LOSAL, HISAL) values (5, 3001, 9999); ======================================================== select * from emp2; select * from dept2; select * from salgrade2; ===================================== select * from emp2; --employee2 员工表 select * from dept2; --department2 部门表 select * from salgrade2; -- salary grade2 工资等级表 ----------------------------------------------------- emp2 empno 员工编号 ename 员工姓名 job 工作/工种 mgr manager上级编号 hiredate 入职日期 sal salary 工资 comm 奖金/津贴 deptno 部门编号 --------------------- dept2 deptno 部门号 dname 部门名称 loc 所在地 --------------------------- salgrade2 grade 等级 losal lowest salary 最低工资 hisal high salary 最高工资 ============================================= 存储过程: 存储过程,sql语句的集合 一次编译,多次运行 select * from emp; 语法语义检查 权限检查 生成执行计划
create or replace procedure insertUser(uName in varchar2) is I integer; begin for I in 1..100 loop insert into db_emp2(empno,ename) values(I,uName||I); end loop; commit; end; ---调用: begin insertUser('user'); end;