oracle視圖索引

reate table fleet_header(
  day date,name varchar2(20),
  route_id number(5),fleet_id number(5)
);oop

create view fleet (day,route_id)
as select day, route_id from fleet_header;code

insert into fleet values('10-10月-05',9);server

--修改視圖定義索引

create or replace view fleet as select * from fleet_header;it

--刪除視圖
drop view fleet;table

--如何在fleet_header表的name 列上建立名爲aud_index的索引
create index aud_index on fleet_header(name);date

--建立惟一索引
--如何在fleet_header表的route_id 列上建立名爲aud_index的索引
create unique index place_ind on fleet_header(route_id) route

--建立組合索引
create index comp_index on fleet_header(route_id,fleet_id)select

--建立反向鍵索引
--fleet_header表的route_id列值是一個順序增加的序號,
--須要在此列上建立索引以提升查詢速度
create index rev_ind on fleet_header(route_no) reverse;循環


--建立位圖索引
create bitmap index bit_ind on fleet_header(cat._code);

--建立位圖索引
create index ucase_name_ind on fleet_header (upper(name));
--輸入如下語句使用該索引
select * from fleet_header where upper(name)='smith';


--刪除索引
drop index emp_ind1;


----------------------------------------
--使用條件控制
----------------------------------------
create table salary_records
(
             deptcode varchar2(15),
            empcode varchar2(10),
            empsal  number
)

insert into salary_records
values('DP04','A4',0)

declare
   dptcode varchar2(15);
   emp_code varchar2(10);
   salary number;
begin
   select deptcode,empcode,empsal into dptcode,emp_code,salary
   from salary_records where empcode='&empid'

   for update of empsal;

    IF dptcode ='DP01' then
      update salary_records set empsal=salary+2000
      where empcode=emp_code;
   elsif dptcode ='DP01' then
       update salary_records set empsal=salary+1700
      where empcode=emp_code;
   elsif dptcode='DP03' then
       update salary_records set empsal=salary+2000
      where empcode=emp_code;
   end if;
commit;
end;

-----------------------------------------------
--使用循環控制
---------------------------------------------
declare
   courserec SALARY%rowtype;
   counter  number:=0;
  begin
    courserec.empsal:=&id;
    courserec.empcode:='&name';
  while counter <12
   loop
      insert into SALARY
      values(courserec.empsal,courserec.empcode);
      counter:=counter+1;
      courserec.empsal:=courserec.empsal+1;
    end loop;
  end;

-----------------------------------------------
使用順序控制
-------------------------------------------
alter table salary_records add (working_days number);

select * from salary_records

declare
     workdays number;
     salary   number;
     bonus    number;
     dept     varchar2(10);
   begin
          select  working_days,empsal,deptcode into workdays,
      salary,dept from salary_records where empcode='&empid';
     IF workdays>=29 then
     
         goto calc_raise;
        else
       DBMS_OUTPUT.PUT_LINE('工做天數少於29天');
      end if;
<<calc_raise>>
    if dept='DP01' then
           bonus :=salary*0.25;
           dbms_output.put_line(bonus);
     else
           bonus :=salary*0.10;
           dbms_output.put_line(bonus);
       end if;
   end;

 set serveroutput on /

相關文章
相關標籤/搜索