1. 程式人生 > >【安博培訓筆記】Oracle賓館管理系統-TI_綜合專案20130917

【安博培訓筆記】Oracle賓館管理系統-TI_綜合專案20130917

------------------------------------------------------------------
--實現主鍵自增


create table t28(
       id number primary key,
       name varchar2(20)
)


insert into t28(name) values('zhangsan');


create sequence seq_name222; 


create or replace trigger tir_t28 
before insert or update on t28 for each row
begin
  select seq_name222.nextval 
         into :new.id from dual;
end;


create or replace trigger tir_t28 
before insert on t28 for each row
begin
  select seq_name222.nextval 
         into :new.id from dual;
end;


select * from t28;
update t28 set name = 'shihua' where id = 1;




-------------------------------------------
/*賓館管理系統-綜合專案
第一部分 案例描述
案例目的
  學習並鞏固oracle資料庫程式設計技術,包括儲存過程、觸發器、索引、檢視、序列、同義詞、事務、遊標等,培養學生對資料庫設計和程式的能力。
案例難度
  ★★★★
案例覆蓋技能點
1、  儲存過程
2、  觸發器
3、  索引
4、  檢視
5、  序列、同義詞
6、  事務
7、  遊標
8、  函式
推薦案例完成時間
   2天
適用課程和物件
  Oracle資料庫設計
第二部分  需求和開發環境
使用技術和開發環境
  Oracle 10g
專案背景
隨著我國改革開放的深入,賓館服務業的競爭日益激烈,一個賓館要想立於不敗之地,就必須提高整體競爭能力,變革賓館的管理模式,提高管理水平,實施資訊化建設無疑是實現這一目的的必由之路和明智之舉。目前,我國賓館服務業的資訊化管理進展緩慢,在激烈的競爭中,如何能把握機會,保持自己的優勢,立於不敗之地呢?這就需要提供最好的服務,提供最完善的設施和最先進的技術。一個成功的賓館,其經營者不僅要提高服務水平和服務質量,從而提高客房佔有率和回頭率,還要有好的工作效率,並控制成本。在資訊時代,更重要的是還必須要有一個完善的資訊管理系統,以方便客人和更好地管理賓館。
資訊管理系統就是我們常說的MIS(Management Information System),在強調管理,強調資訊的現代社會中它變得越來越普及。傳統的登記表的做法極大的影響了工作流程效率和資料的正確性、完整性、安全性,已經逐漸落後於時代。利用軟體管理系統代替手工的賓館管理,將會大大提高工作效率。
案例需求
賓館的主要活動首先可分為四個部分,即預訂管理、入住管理、消費管理和退房結算管理。
 
預訂管理主要包括登記客人的預訂資訊,查詢預訂資訊,同時還需要注意預訂資訊不能出現衝突現象,例如兩個客人都預訂了同一天的同一個房間,這是不允許的;此外,在快到預訂時確定的客人預抵時間時,接待人員要打電話證明客人是否能按時入住,如果不能,就會把預訂單作廢,或者稱為失效;


除了按流程劃分的這四個部分之外,還有兩個部分:客房管理和使用者管理。;這兩部分資訊需要在客人入住以前提前設定好。
*/
/*1.  使用者許可權管理
使用者管理是管理系統的使用者,主要包括前臺接待人員、前臺收銀員、餐廳服務員等,他們的許可權按其身份不同而不同。
 
表名  hotel_t_User(使用者表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
userid  使用者編號  Number  非空  主鍵(自增)
username  使用者名稱稱  VARCHAR2(20)  非空  
userpassword  密碼  VARCHAR2(20)  非空  
truename  真實姓名  VARCHAR2(20)  非空 */ 


drop table hotel_t_User;
Create table hotel_t_User(
    userid number primary key not null,--自增
    username varchar2(20) not null,
    userpassword varchar2(20) not null,
    truename varchar2(20) not null
);
select * from hotel_t_user;
---------------


---------------------------
drop sequence seq_hotel_t_User;
create sequence seq_hotel_t_User;


drop trigger tir_hotel_t_User;
create or replace trigger tir_hotel_t_User 
before  insert or update  on hotel_t_User for each row
begin
  select seq_hotel_t_User.nextval 
         into :new.userid from dual;
end;
---------------
insert into hotel_t_User(username,userpassword,truename) 
       values('shihua','shihua','shihua');
---------------------
/*表名  hotel_t_Role(角色表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
roleid  使用者編號  NUMBER  非空  主鍵(自增)
rolename  使用者名稱稱  VARCHAR2(20)  非空*/


create table hotel_t_Role(
       roleid number primary key not null,--自增
       rolename varchar2(20) not null
);  


drop sequence seq_hotel_t_Role;
create sequence seq_hotel_t_Role;


drop trigger tir_hotel_t_Role;
create or replace trigger tir_hotel_Role 
before  insert or update  on hotel_t_Role for each row
begin
  select seq_hotel_t_Role.nextval 
         into :new.roleid  from dual;
end;


/*表名  hotel _t_Right(許可權表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
rightid  許可權編號  NUMBER  非空  主鍵(自增)
rightname  許可權名  VARCHAR2(50)  非空  */


create table hotel_t_Right(
       rightid number primary key not null,--自增
       rightname varchar2(20) not null
);


create sequence seq_hotel_t_Right;
create or replace trigger tir_hotel_Right 
before  insert or update  on hotel_t_Right for each row
begin
  select seq_hotel_t_Right.nextval 
         into :new.Rightid  from dual;
end;


/*表名  hotel_t_Roleright(角色許可權表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
rrid  編號  NUMBER  非空  主鍵(自增)
roleid  使用者編號  NUMBER  非空  外來鍵
rightid  許可權編號  NUMBER  非空  外來鍵*/


create table hotel_t_Roleright(
       rrid number primary key not null,--自增
       roleid number not null references hotel_t_Role(roleid),
       rightid number not null references hotel_t_Right(rightid)
);


create sequence seq_hotel_t_Roleright;
create or replace trigger tir_hotel_Roleright 
before  insert or update  on hotel_t_Roleright for each row
begin
  select seq_hotel_t_Roleright.nextval 
         into :new.rrid  from dual;
end;
/*表名  hotel_t_Userrole(使用者角色表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
urid  編號  NUMBER  非空  主鍵(自增)
roleid  使用者編號  NUMBER  非空  外來鍵
rightid  許可權編號  NUMBER  非空  外來鍵*/


create table hotel_t_Userrole(
       urid number primary key not null,--自增
       roleid number not null references hotel_t_Role(roleid),
       rightid number not null references hotel_t_Right(rightid)
);


create sequence seq_hotel_t_Userrole;
create or replace trigger tir_hotel_Userrole 
before  insert or update  on hotel_t_Userrole for each row
begin
  select seq_hotel_t_Userrole.nextval 
         into :new.urid  from dual;
end;
/*主要功能模組涉及的資料表的關係圖:
 
2.  客房基本資訊管理
客房管理主要是按客房的條件不同,對客房進行分類(例如分成標準間和豪華間),每一類制定一個標價,但實際上這個標價很少按照執行,為了迎合客人心理,各個賓館一般都會對標價進行打折,即便這樣,有的客人可能還不滿意,或者是打折後出現零錢的現象,賓館一般會給接待人員一個讓價的權利,但是這個讓價不能是無限度的,因此還需要對每類房間定一個最低價
表名  hotel_t_Roomtype(客房型別表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
typeid  型別編號  NUMBER  非空  主鍵(自增)
typename  型別名稱  VARCHAR2(20)  非空  
mardedprice  標價  NUMBER(12,2)  空  
scale  折扣比率  NUMBER(5,4)  空  
lowestprice  最低折扣價  NUMBER(12,2)  空 */ 


create table hotel_t_Roomtype(
        typeid NUMBER primary key not null, --自增
        typename VARCHAR2(20)  not null,  
        mardedprice NUMBER(12,2),  
        scale NUMBER(5,4),
        lowestprice NUMBER(12,2)
)


create sequence seq_hotel_t_Roomtype;
create or replace trigger tir_hotel_Roomtype 
before  insert or update  on hotel_t_Roomtype for each row
begin
  select seq_hotel_t_Roomtype.nextval 
         into :new.typeid  from dual;
end;


/*表名  hotel_t_Room(客房資訊表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
roomid  房號  VARCHAR2(10)  非空  主鍵
typeid  型別編號  NUMBER  空  外來鍵
layer  樓層  VARCHAR2(20)  空  
bednumber  床位數  NUMBER  空  
state  狀態  NUMBER  非空  0表示空閒,1表示入住,2表示預留,預設為0*/


create table hotel_t_Room(--(客房資訊表)
--列名  描述  資料型別(精度範圍)  空/非空  約束條件
roomid VARCHAR2(10) primary key,--  非空  主鍵
typeid NUMBER references hotel_t_Roomtype(typeid),--  空  外來鍵
layer VARCHAR2(20),--  空  
bednumber NUMBER,--  空  
state NUMBER default 0 check(state in (0,1,2)) not null  --0表示空閒,1表示入住,2表示預留,預設為0
);
/*3.  預訂管理模組
預訂管理主要包括登記客人的預訂資訊,查詢預訂資訊,同時還需要注意預訂資訊不能出現衝突現象,例如兩個客人都預訂了同一天的同一個房間,這是不允許的;此外,在快到預訂時確定的客人預抵時間時,接待人員要打電話證明客人是否能按時入住,如果不能,就會把預訂單作廢,或者稱為失效;


表名  hotel_t_Predestine(預訂資訊表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
predid  預訂單號  CHAR(16)  非空  主鍵
roomid  房號  VARCHAR2(10)  非空  
whenpred  預訂時間  DATE  非空  
whopred  預訂人  VARCHAR2(20)  非空  
phone  聯絡方式  VARCHAR2(20)  非空  
arrivetime  預抵時間  DATE  非空  
leavetime  預離時間  DATE  非空  
trueprice  房價  NUMBER(12,2)    
state  狀態  NUMBER  非空  取值範圍為0、1和2,0表示有效,1表示入住,2表示失效,預設為0*/


create table hotel_t_Predestine(--(預訂資訊表)
--列名  描述  資料型別(精度範圍)  空/非空  約束條件
predid CHAR(16) primary key not null,--  非空  主鍵
roomid VARCHAR2(10) not null,--  非空  
whenpred DATE not null,--  非空  
whopred VARCHAR2(20) not null,--  非空  
phone VARCHAR2(20) not null,--  非空  
arrivetime DATE not null,--  非空  
leavetime DATE not null,--  非空  
trueprice NUMBER(12,2) not null,    
state NUMBER default 0 check(state in (0,1,2)) not null--  取值範圍為0、1和2,0表示有效,1表示入住,2表示失效,預設為0*/
);


/*4.  入住管理模組
入住管理主要包括安排客人入住到空閒狀態的房間、登記入住單資訊,查詢在店客人資訊,以及客史查詢(查詢以前在本賓館住宿過的客人資訊),同時也需要避免和其他客人的預訂資訊衝突,例如入住的客人預計要等到10號退房,而其他客人已經預訂了9號的這個房間,這種情況也是不允許的;
表名  hotel_t_Lodge(入住資訊表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
lodgeid  入住單號  CHAR(16)  非空  主鍵
roomid  房號  VARCHAR2(10)  非空  外來鍵
guestname  客人姓名  VARCHAR2(20)  非空  
guestsex  性別  CHAR(1)  非空  “男”或“女”
cardtype  證件類別  VARCHAR2(20)  空  
cardnumber  證件號碼  VARCHAR2(30)  空  
birthday  出生日期  DATE  空  
guestaddress  地址  VARCHAR2(50)  空  
phone  聯絡方式  VARCHAR2(20)  空  
arrivetime  入住時間  DATE  非空  
leavetime  預離或退房時間  DATE  非空  
trueprice  房價  NUMBER(12,2)  非空  
payinadvance  押金  NUMBER(12,2)  空  預設為0
predid  預訂單號  CHAR(16)  空  
serverman  接待人員  VARCHAR2(20)  空*/  


create table hotel_t_Lodge(--(入住資訊表)
--列名  描述  資料型別(精度範圍)  空/非空  約束條件
lodgeid CHAR(16) primary key not null,-- 非空  主鍵
roomid VARCHAR2(10) not null references hotel_t_Room(Roomid),--  非空  外來鍵
guestname VARCHAR2(20) not null,--  非空  
guestsex CHAR(1) default 0 check(guestsex in (0,1)) not null,--  非空  “男”或“女”
cardtype VARCHAR2(20),--  空  
cardnumber VARCHAR2(30),--  空  
birthday DATE,--  空  
guestaddress VARCHAR2(50),--  空  
phone VARCHAR2(20),--  空  
arrivetime DATE not null,--  非空  
leavetime DATE,--  非空  
trueprice NUMBER(12,2),--  非空  
payinadvance NUMBER(12,2) default 0,--  空  預設為0
predid CHAR(16),--  空  
serverman VARCHAR2(20)--  空
);
/*5.  消費管理模組
消費管理主要包括登記客人的消費資訊和查詢消費資訊,消費資訊主要包括客人在賓館的用餐費和電話費等;
表名  hotel_t_Consume(消費資訊表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
consid  消費編號  NUMBER  非空  主鍵(自增)
consname  消費專案  VARCHAR2(20)  非空  
consmoney  消費金額  NUMBER(12,2)  非空  
constime  消費時間  DATE    
lodgeid  入住單號  CHAR(16)  非空  外來鍵*/


create table hotel_t_Consume(--(消費資訊表)
--列名  描述  資料型別(精度範圍)  空/非空  約束條件
consid NUMBER primary key not null,--  非空  主鍵(自增)
consname VARCHAR2(20) not null,--  非空  
consmoney NUMBER(12,2) not null,-- 非空  
constime DATE,
lodgeid CHAR(16) not null references hotel_t_Lodge(lodgeid)-- 非空  外來鍵
);


create sequence seq_hotel_t_Consume;
create or replace trigger tir_hotel_Consume 
before  insert or update  on hotel_t_Consume for each row
begin
  select seq_hotel_t_Consume.nextval 
         into :new.consid  from dual;
end;
6.  退房結算管理
退房結算管理主要指客人在退房時,收銀員計算客人在賓館的所有費用,包括住宿費和消費管理中的餐費和電話費等,然後將這些費用的和與客人入住時交納的押金進行對比,最後多退少補,完成退房結算手續。退房手續辦完後,房間就變成了空閒房,其他客人可以入住了。






上機推薦步驟:
1.  使用者管理:
1)  建立相關的資料表及其約束,由於資料量都不大不需要建立所有
Create table hotel_t_User(
    userid number primary key not null,--自增
    username varchar2(20) not null,
    userpassword varchar2(20) not null,
    truename varchar2(20) not null
);


create sequence seq_hotel_t_User;
create or replace trigger tir_hotel_t_User 
before  insert or update  on hotel_t_User for each row
begin
  select seq_hotel_t_User.nextval 
         into :new.userid from dual;
end;
insert into hotel_t_User(username,userpassword,truename) 
       values('shihua','shihua','shihua');
2)  編寫一個儲存過程,用來使用者登入時驗證使用者
儲存過程驗證使用者登陸資訊 
select count(*) from hotel_t_User where userid =&userid and username ='&userpassword';


declare 
  cc number;
begin
  select count(1) into cc from hotel_t_User where userid =&userid and username ='&userpassword';
  if cc>0 then
    dbms_output.put_line('登陸成功');
  else
    dbms_output.put_line('登陸失敗');
  end if;
exception
  when no_data_found then
    dbms_output.put_line('登陸失敗');
end;
2.  客戶基本資訊管理:
1)  建立相關的資料表及其約束,由於資料量都不大不需要建立所有
--客房基本資訊管理
create table hotel_t_Roomtype(
        typeid NUMBER primary key not null, --自增
        typename VARCHAR2(20)  not null,  
        mardedprice NUMBER(12,2),  
        scale NUMBER(5,4),
        lowestprice NUMBER(12,2)
)
create sequence seq_hotel_t_Roomtype;
create or replace trigger tir_hotel_Roomtype 
before  insert or update  on hotel_t_Roomtype for each row
begin
  select seq_hotel_t_Roomtype.nextval 
         into :new.typeid  from dual;
end;


--客房資訊表
create table hotel_t_Room(
roomid VARCHAR2(10) primary key not null,--  非空  主鍵
typeid NUMBER references hotel_t_Roomtype(typeid),--  空  外來鍵
layer VARCHAR2(20),--  空  
bednumber NUMBER,--  空  
state NUMBER default 0 check(state in (0,1,2)) not null  --0表示空閒,1表示入住,2表示預留,預設為0
);
客房基本資訊管理
客房管理主要是按客房的條件不同,對客房進行分類(例如分成標準間和豪華間),每一類制定一個標價,但實際上這個標價很少按照執行,為了迎合客人心理,各個賓館一般都會對標價進行打折,即便這樣,有的客人可能還不滿意,或者是打折後出現零錢的現象,賓館一般會給接待人員一個讓價的權利,但是這個讓價不能是無限度的,因此還需要對每類房間定一個最低價
表名hotel_t_Roomtype(客房型別表)
列名描述資料型別(精度範圍)空/非空約束條件
typeid型別編號 NUMBER非空 主鍵(自增)
typename型別名稱 VARCHAR2(20)非空
mardedprice標價NUMBER(12,2)空
scale折扣比率 NUMBER(5,4)空
lowestprice最低折扣價NUMBER(12,2)空




表名hotel_t_Room(客房資訊表)
列名描述資料型別(精度範圍)空/非空約束條件
roomid房號 VARCHAR2(10)非空主鍵
typeid型別編號 NUMBER空 外來鍵
layer樓層 VARCHAR2(20)空
bednumber床位數 NUMBER空
state狀態 NUMBER非空 0表示空閒,1表示入住,2表示預留,預設為0
2)  基於客房表和客房型別表建立檢視
grant create any view to kaifa;


CREATE VIEW v_room AS
SELECT hotel_t_Roomtype.typeid,typename,mardedprice,scale,lowestprice, 
       roomid,layer,bednumber,state
FROM   hotel_t_Roomtype,hotel_t_Room
WHERE  hotel_t_Roomtype.typeid = hotel_t_Room.typeid;


select * from v_room;
3.  預定管理
1)  建立表及其相關約束
create table hotel_t_Predestine(--(預訂資訊表)
predid CHAR(16) primary key not null,--  非空  主鍵
roomid VARCHAR2(10) not null,--  非空  
whenpred DATE not null,--  非空  
whopred VARCHAR2(20) not null,--  非空  
phone VARCHAR2(20) not null,--  非空  
arrivetime DATE not null,--  非空  
leavetime DATE not null,--  非空  
trueprice NUMBER(12,2) not null,    
state NUMBER default 0 check(state in (0,1,2)) not null--  取值範圍為0、1和2,0表示有效,1表示入住,2表示失效,預設為0*/
);
表名  hotel_t_Predestine(預訂資訊表)
列名  描述  資料型別(精度範圍)  空/非空  約束條件
predid  預訂單號  CHAR(16)  非空  主鍵
roomid  房號  VARCHAR2(10)  非空  
whenpred  預訂時間  DATE  非空  
whopred  預訂人  VARCHAR2(20)  非空  
phone  聯絡方式  VARCHAR2(20)  非空  
arrivetime  預抵時間  DATE  非空  
leavetime  預離時間  DATE  非空  
trueprice  房價  NUMBER(12,2)    
state  狀態  NUMBER  非空  取值範圍為0、1和2,0表示有效,1表示入住,2表示失效,預設為0*/
insert into hotel_t_Predestine values (0000000000000000,11,sysdate,'shihua','18615396007',sysdate+10,sysdate+34,100,0);
insert into hotel_t_Predestine values (0000000000000001,12,sysdate,'shihua','18615396007',sysdate+10,sysdate+34,100,1);
insert into hotel_t_Predestine values (0000000000000002,13,sysdate,'shihua','18615396007',sysdate+10,sysdate+34,100,2);
select * from hotel_t_Predestine;


2)  建立觸發器:實現插入、修改預訂資訊時保證預訂房價不得低於房價最低價
create or replace trigger tri_predestine_3_2
before insert or update of Trueprice on hotel_t_Predestine
for each row
declare
    mintrueprice   hotel_t_Predestine.Trueprice%type;
begin
  select min(trueprice) into mintrueprice from hotel_t_Predestine;
  if :new.trueprice < mintrueprice then
    raise_application_error(-20001,'預訂房價低於房價最低價');
  end if;
end;
3)  建立觸發器:實現預定時或修改預定時查詢要預定的房間在預定的時間段有沒有與其他的預定有衝突
select * from hotel_t_Predestine where roomid = &roomid;
select * from hotel_t_Predestine where roomid = &roomid;
select * from hotel_t_Predestine where roomid = &roomid;


create or replace trigger predestine_room_tri
before insert or update on hotel_t_predestine for each row 
declare
 p_roomcount number;
begin
 select count(*) into p_roomcount
  from HOTEL_T_PREDESTINE 
  where roomid = :new.roomid and (arrivetime<:new.arrivetime or leavetime>:new.leavetime);
 if p_roomcount>0 then
    raise_application_error(-20002,'該房間已經預定');
  end if;
end;


      
4)  建立一個查詢預訂資訊的檢視,以提高查詢結果的可讀性
create or replace view v_Predestine as
select * from hotel_t_Predestine where state in(0);
5)  建立一個查詢預訂歷史資訊的檢視
create or replace view v_Predestine as
select * from hotel_t_Predestine where state in(1,2);
6)  建立一個儲存過程,當快要到客人預訂的預抵時間時(預設提前兩個小時),將房間狀態設為預留,可以提醒接待人員與客人聯絡確認是否入住。該儲存過程的呼叫應該是每隔一段時間就呼叫一次,人為來操作肯定是不現實的,在資料庫中可以通過作業來實現
create or replace procedure remind_proc
is
  p_roomid  hotel_t_predestine.roomid%type;
  p_arrivetime hotel_t_predestine.arrivetime%type;
begin
  select roomid,arrivetime-2/24 into p_roomid,p_arrivetime
  from hotel_t_predestine;
  if p_arrivetime=sysdate then
    update hotel_t_room set state = 2 where roomid = p_roomid;
  end if;
end;
declare
       job_num number;
begin
          dbms_job.submit(job_num,'remind_proc;',sysdate,'Sysdate+1/1440');
          commit;
end;


7)  建立使預訂單失效的儲存過程
create or replace procedure predestine_state_proc(
p_predid varchar2
)
is
begin
  update hotel_t_predestine set state = 2 where 
  predid = p_predid;
end;


-------------------
ALTER proc [dbo].[儲存過程名]
 as
 begin
   declare 遊標名字 cursor for select 列名 from 表名 where 條件--先申明遊標指向查詢出的結果,一列,或者多列都可以,條件自定
   declare 變數名  varchar(400)--儲存取到的值
   open 遊標名 --開啟遊標
   while @@FETCH_STATUS=0--取值
     begin
     fetch next FROM 遊標名 into 變數名--這樣就將遊標指向下一行,得到的第一行值就傳給變量了
     -------------------------------------------
     --需要執行的操作,例如修改某表中的欄位
     update 表名
     set 列名=值
     where (修改表中的列)=變數名
     -------------------------------------------
 end
  close 遊標名--關閉遊標


  deallocate  遊標名--釋放遊標
end
-------------------
create or replace procedure pro_Predestine
is
   v_leavetime hotel_t_Predestine.leavetime%type;
begin
   select leavetime into v_leavetime from hotel_t_Predestine where empno=v_id;
   dbms_output.put_line(v_ename||'   '||v_sal);   
end;
4.  入住管理
1)  建立表及其相關約束
2)  建立插入入住資訊的觸發器
create or replace trigger lodge_insert_tri
before insert or update on HOTEL_T_LODGE for each row
declare 
  r_state HOTEL_T_ROOM.State%type;
  l_roomid HOTEL_T_LODGE.roomid%type;
begin
  dbms_output.put_line(:new.roomid);
  l_roomid := :new.roomid;
  select state into r_state
  from HOTEL_T_ROOM 
  where roomid = l_roomid;
  if r_state=0 then
   raise_application_error(-20003,'可以插入入住資訊');
  else
    raise_application_error(-20004,'不可以插入入住資訊');
  end if;
end;


3)  建立辦理續住手續的觸發器
create or replace trigger continue_lodge_tri
before update on hotel_t_lodge for each row
declare 
  l_leavetime hotel_t_lodge.leavetime%type;
begin
  l_leavetime := :new.leavetime; 
  if l_leavetime <= :old.leavetime then
    raise_application_error(-20005,'辦理續住手續錯誤');
    rollback;
  else
    raise_application_error(-20006,'辦理續住手續正確');
    commit;
  end if;
end;


4)  建立檢視在店客人的檢視
create view lodgenow_view as
select *
from hotel_t_lodge
where to_char(sysdate,'yyyy-mm-dd') < to_char(leavetime,'yyyy-mm-dd');


5)  建立檢視客人入住歷史的檢視
create view lodgeever_view as
select *
from hotel_t_lodge
where to_char(sysdate,'yyyy-mm-dd') >= to_char(leavetime,'yyyy-mm-dd');


6)  在入住歷史表上,基於客人姓名和入住時間建立簡單非聚集組合索引
--入住歷史表
create table hotel_t_lodgehistory(
    lodgeid char(16) primary key not null,
    roomid varchar2(10) not null, 
    guestname varchar2(20) not null,
    guestsex char(2) check(guestsex in('男','女')) not null,
    cardtype varchar2(20),
    cardnumber varchar2(30),
    birthday date,
    guestaddress varchar2(50),
    phone varchar2(20),
    arrivetime date not null,
    leavetime date not null,
    trueprice number(12,2) not null,
    payinadvance number(12,2) default 0,
    predid char(16),
    serverman varchar2(20)
);
------------------------
create index guestname_arrivetime_index
on hotel_t_lodge(guestname,arrivetime);
----------------
5.  消費管理
1)  建立消費資訊表及其約束
2)  建立查詢客人消費資訊的檢視
create index guestname_arrivetime_index
on hotel_t_lodge(guestname,arrivetime);


6.  退房結算管理
1)  建立結算儲存過程(該儲存過程首先根據客人的退房時間計算住宿的天數,然後用入住單上的房價乘以入住天數後得到住宿的房費;再分別計算出客人的其他消費合計,兩項相加得到應收帳款,用應收帳款減去客人入住時交的押金,得到客人需要補交的金額,最後把這些資訊輸出。)
create or replace procedure accounts_proc(
a_roomid varchar2,a_guestname varchar2
)
is
  lodgedayprice number(12,2);
  c_consmoney number(12,2);
  shouldmoney number(12,2);
  paymoney number(12,2);
  l_payinadvance number(12,2);
  
begin
  
  select (leavetime-arrivetime)*trueprice into lodgedayprice
  from hotel_t_lodge
  where roomid = to_number(a_roomid) and guestname = a_guestname;
  select consmoney into c_consmoney
  from hotel_t_consume htc,hotel_t_lodge htl
  where htc.lodgeid = htl.lodgeid and
  roomid = a_roomid and guestname = a_guestname;
  shouldmoney := c_consmoney + lodgedayprice;
  select payinadvance into l_payinadvance
  from hotel_t_lodge;
  paymoney :=shouldmoney - l_payinadvance;
  dbms_output.put_line('補交的金額為:'||paymoney);
end;


2)  建立退房儲存過程(先是把當前時間修改為客人的退房時間,然後是將客人退掉的房間狀態改為“空閒”,最後將該客人的入住資訊轉存到入住歷史表,再將該資訊從入住表中刪除)
create or replace procedure leavetime_proc(
  a_roomid varchar2,a_guestname varchar2
)
is
  r_lodgeid hotel_t_lodge.lodgeid%type;
  r_roomid hotel_t_lodge.roomid%type;
  r_guestname hotel_t_lodge.guestname%type;
  r_guestsex hotel_t_lodge.guestsex%type;
  r_cardtype hotel_t_lodge.cardtype%type;
  r_cardnumber hotel_t_lodge.cardnumber%type;
  r_birthday hotel_t_lodge.birthday%type;
  r_guestaddress hotel_t_lodge.guestaddress%type;
  r_phone hotel_t_lodge.phone%type;
  r_arrivetime hotel_t_lodge.arrivetime%type;
  r_leavetime hotel_t_lodge.leavetime%type;
  r_trueprice hotel_t_lodge.trueprice%type;
  r_payinadvance hotel_t_lodge.payinadvance%type;
  r_predid hotel_t_lodge.predid%type;
  r_sercerman hotel_t_lodge.serverman%type;
begin
  update hotel_t_lodge set leavetime = sysdate where roomid = to_number(a_roomid) and guestname = a_guestname;
  update HOTEL_T_ROOM set state = 0 where roomid = a_roomid;
  select lodgeid,roomid,guestname,guestsex,cardtype,cardnumber,birthday,guestaddress,phone,
  arrivetime,leavetime,trueprice,payinadvance,predid,serverman into r_lodgeid,r_roomid,r_guestname,r_guestsex,
  r_cardtype,r_cardnumber,r_birthday,r_guestaddress,r_phone,r_arrivetime,r_leavetime,r_trueprice,r_payinadvance,
  r_predid,r_sercerman
  from hotel_t_lodge htl;
  insert into HOTEL_T_LODGEHISTORY values(r_lodgeid,r_roomid,r_guestname,r_guestsex,r_cardtype,r_cardnumber,
  r_birthday,r_guestaddress,r_phone,r_arrivetime,r_leavetime,r_trueprice,r_payinadvance,r_predid,
  r_sercerman);
  delete from hotel_t_Consume where lodgeid = r_lodgeid;
  delete from hotel_t_lodge where lodgeid = r_lodgeid;
  commit;
end;


第三部分  考核評價點
序號  功能列表  功能描述  分數  說明
1  資料表的建立和資料的準備  正確建立相關資料表,插入正確的資料  20  必做
2  儲存過程  完成計算總分的儲存過程  30  必做
3  觸發器  完成插入成績表,並算出總分的觸發器  40  必做
4  符合規範  命名、書寫格式規範  10  必做
5        必做



相關推薦

培訓筆記Oracle賓館管理系統-TI_綜合專案20130917

------------------------------------------------------------------ --實現主鍵自增 create table t28(        id number primary key,        name v

培訓筆記Java1 Java面向物件_PPT練習20130920

package com.ambow.java20130917; public class Student { private String name; private int age; private int banji; private String love;

培訓筆記Java2 陣列、字串、常用工具類_課下作業2_20130920

1. 假如有以下email資料“[email protected],[email protected],[email protected],..”現需要把email中的使用者部分和郵件地址部分分離,分離後以鍵值對應的方式放入HashMap p

培訓技術Oracle4 事務和資料庫物件20130910

Oracle4 事務和資料庫物件 回顧 SQL 支援的操作符包括算術、比較、邏輯、集合和連線操作符 SQL 函式可大致分為: 單行函式:日期、字元、數字、轉換、其他 聚合函式 分析函式 目標 事務 使用同義詞 使用序列 理解並使用檢視 理解並使用索引 事務管理 例如,銀行轉

培訓技術Oracle8 觸發器20130912

Oracle8 觸發器 回顧 子程式是命名的 PL/SQL 塊,儲存在資料庫中,可帶引數並可在需要時隨時呼叫 有兩種型別的PL/SQL子程式,即過程和函式 過程使用者執行特定的任務,函式用於執行任務並返回值 程式包是對相關型別、變數、常量、遊標、異常、過程和函式等物件的封裝

培訓技術Java2 陣列、字串、常用工具類20130918

教學目標 熟練使用一維陣列存取資料,瞭解多維陣列的使用 熟練掌握String與StringBuffer操作的幾個常見函式 熟練使用包裝類、Math類、日期類、Random類、System和Runtime類 什麼是陣列? 陣列是用來儲存一組相同資料型別資料的資料結構 陣列是一

卓學習筆記Android Studio第3課——EditText控制元件

EditText和TextView很相似,主要不同的是EditText是使用者可以在上面編輯本文的,而TextView只能用app本身去改變和顯示。做了一個簡單的登入介面:xml程式碼如下<?xml version="1.0" encoding="utf-8"?>

U1結業機試題新聞內容管理系統:解析XML文件讀取Html模版生成網頁文件

repl att not 一個 class 新的 create hashmap exception 一、作業要求: 1.在xml文件中創建新聞節點news,包含標題、作者、日期、正文等信息 2.創建HTML模板文件 3.讀取xml中所有新聞信息,並使用新聞信息替換模板文件中

知了堂學習筆記Eclipse,Myeclipse連接MySQL數據庫和Oracle數據庫

let ets 最好 lec 代碼 htm ner pro 密碼 一.連接MySQL數據庫   1.由於Eclipse,Myeclipse都沒有連接MySQL數據的架包,我們需要自行下載MySQL連接架包 mysql-connector(官方鏈接:http://dev.my

筆記Oracle SQL語句 | 基礎篇

when 自然 本地數據庫 指向 ise abort ted names pda 整理了一下Oracle SQL的基本語句,主要針對Oracle的使用者(Oracle數據庫維護和管理員的常用語句之後整理),可作為一個大綱參考,對某些語句或函數並未深入的詳解,只是簡單列出,留

Oracle筆記Oracle因安裝時未設定字符集導致中文亂碼的解決方案

在Centos6.5上安裝Oracle11g沒有設定字符集,採用的是作業系統預設字符集:WE8MSWIN1252,將字符集修改為:ZHS16GBK。 [[email protected] ~]$ sqlplus / as sysdba SQL*Plus: Rel

SQL Server學習筆記事務、鎖定、阻塞、死鎖

body sqlserve distrib reset reads cli ast function pre http://blog.csdn.net/sqlserverdiscovery/article/details/7712068 Column nameData

安全牛學習筆記XSS的簡述

cookie 服務器 漏洞 安全 xss 1.Cross Site SCripting 攻擊者往Web頁面裏插入惡意Script代碼,當用戶瀏覽該頁時,嵌入其中Web裏面的Script代碼會被執行,從而達到惡意攻擊用戶的目的。

安全牛學習筆記XSS的利用

xss 惡意代碼 漏洞 反射型XSS1.概念 通過社會工程學等手段誘騙用戶點擊某個精心構造的鏈接,該鏈接會將惡意的js代碼提交給 有漏洞的服務器網站,並由服務器返回給受害者的客戶端執行。 2.POC -<scri

安全牛學習筆記Web掃描器(1)

安全 web 漏洞 1.偵察httrack可將目標網站的網頁全部爬取下來,減少偵察過程中與目標服務器發生的交互。 2.Nikto(1).檢測對象 掃描軟件版本 搜索存在安全隱患的文件 配置漏洞

安全牛學習筆記OSI網絡模型

http ssh stmp 安全 OSI網絡模型 物理層規定比特在物理介質中的傳輸方式,解決物理傳輸過程中的問題。 代表設備:中繼器,集線器(多端口中繼器) 數據鏈路層 在不可靠的網絡環境中進行可靠的數據傳輸。解決數據傳輸中可能出現的

安全牛學習筆記搜索引擎

安全、web、滲透、信息安全 搜索引擎 shodan爬取banner信息。搜索聯網設備。 常用關鍵字: netcity country CNport oshostname實例:cisco 200 ok 思科設備default password 默認密碼

安全牛學習筆記服務掃描

安全、web、滲透、信息安全 1.簡述 識別開放端口上的應用 識別目標操作系統 提高攻擊效率 2.分類 Banner信息獲取 服務識別 操作系統識別snmp分析 防火墻識別 3.Banner (1).含義

安全牛學習筆記Kali Linux 安裝-持久加密USB安裝、熟悉環境、熟悉BASH命令

security+ linux 信息安全 持久加密USB安裝-1LUKS: linux UNified Key Setup 磁盤分區加密規範 不依賴於操作系統的磁盤級加密 Windows——DoxBox 後端:dm-crypt 前端:cryptsetup 微軟的bitlocker將鏡像

安全牛學習筆記網絡配置、更新升級、安裝軟件包、瀏覽器插件

信息安全;網絡配置[email protected]:~# dhclient eth0 //用來通過 dhcp 協議配置本機的網絡接口[email protected]:~# ifconfig 查看現在的ip地址[email protected]:~# ifc