Oracle views for examples, indexing and storing an operation procedure

1. Add View

- View: virtual table, you can use the same query as a table, predefined queries 
create [or replace] [[no ] force] view view name 
AS 
       the SELECT query 
[with the Read only]; 
- EX: 
the Create View or the replace empinfo 
AS 
  . SELECT * E, d.dname, d.loc 
  from EMP E 
  left the Join Dept D 
       ON = d.deptno e.deptno 
with Read only; 

SELECT * 
from empinfo 
WHERE SAL> 2000; 

drop View empinfo;

2. Add index

- Index: speed up queries 
create [unique] index index name on table name (column); 
- EX: 
the Create index emp_index_id on emp (ename); 

drop index emp_index_id;

3. The relevant branch of stored procedures

Procedure sp_sal Replace or Create (name in VARCHAR) 
- Create a stored procedure 
IS 
       I Number; 
       - create a variable 
the begin 
       SELECT INTO e.sal I 
       from E EMP 
       WHERE e.ename = name; 
       - query, the query result is assigned to I 
       IF I> the then 2000 
              - condition is satisfied 
              Update EMP SET SAL + SAL = 0.01 = WHERE ename name; 
       the else 
              - condition is not satisfied 
              Update EMP SET SAL + SAL = 0.1 WHERE ename = name; 
       End IF; 
       - Submit 
       commit; 
end sp_sal;

4. For the cycle stored procedure

create or replace procedure sp_for1(num in number)
is
begin
       for i in 1..num loop
           insert into dept(deptno,dname,loc) values (to_char(50+i),concat('OREEE',to_char(i)),concat('OOOO',to_char(i)));
       end loop;
       commit;
end sp_for1;

  

Guess you like

Origin www.cnblogs.com/nullnullnull/p/11209622.html