收獲每一天

          -----在JAVA的路上越走越遠(yuǎn)!
          posts - 6, comments - 0, trackbacks - 0, articles - 2
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          數(shù)據(jù)庫要求
          1、建立一個(gè)表code_dam,包含以下字段
          ?? id int,自增,主鍵
          ?? code nvarchar(20), not null? (大壩編號(hào))
          ?? name nvarchar(20), not null? (大壩名稱)
          ?? remark nvarchar(200)???????? (備注)
          2、編程實(shí)現(xiàn)對(duì)表code_dam的增刪改查功能,包括:
          ?? 添加大壩編碼(添加一條記錄到數(shù)據(jù)庫,要求:大壩編號(hào)不能重復(fù),大壩名稱不能重復(fù))
          ?? 修改大壩編碼(要求:大壩編號(hào)不能重復(fù),大壩名稱不能重復(fù))
          ?? 刪除一個(gè)大壩編碼
          ?? 大壩編碼列表(code_dam表中所有的記錄,使用列表將其他功能串在一起)
          ?? 查看大壩編碼(顯示指定id的大壩編號(hào)、名稱、備注)



          //建立數(shù)據(jù)庫

          -- Create table
          create table CODE_DAM
          (
          ? ID???? INTEGER not null,
          ? CODE?? VARCHAR2(20) not null,
          ? NAME?? VARCHAR2(20) not null,
          ? REMARK VARCHAR2(200)
          )
          tablespace DAM
          ? pctfree 10
          ? initrans 1
          ? maxtrans 255
          ? storage
          ? (
          ??? initial 64K
          ??? minextents 1
          ??? maxextents unlimited
          ? );
          -- Add comments to the table
          comment on table CODE_DAM
          ? is '大壩管理';
          -- Add comments to the columns
          comment on column CODE_DAM.CODE
          ? is '大壩編號(hào)';
          comment on column CODE_DAM.NAME
          ? is '大壩名稱';
          -- Create/Recreate primary, unique and foreign key constraints
          alter table CODE_DAM
          ? add constraint ID primary key (ID)
          ? using index
          ? tablespace DAM
          ? pctfree 10
          ? initrans 2
          ? maxtrans 255
          ? storage
          ? (
          ??? initial 64K
          ??? minextents 1
          ??? maxextents unlimited
          ? );

          //自增解決辦法
          //序列
          -- Create sequence
          create sequence SEQ_CODE_DAM
          minvalue 1
          maxvalue 999999999999999999999999999
          start with 31
          increment by 1
          cache 10;
          //觸發(fā)器
          CREATE OR REPLACE TRIGGER TRG_code_dam
          BEFORE
          INSERT? ON code_dam
          FOR EACH ROW
          begin
          SELECT SEQ_code_dam.NEXTVAL
          INTO:NEW.id
          FROM DUAL;
          End TRG_code_dam;

          ?

          //相關(guān)存儲(chǔ)過程

          //查詢所有數(shù)據(jù)
          //包
          create or replace package showall is
          type mycursor is ref cursor;
          procedure GetRecords(ret_cursor out mycursor);
          end showall;
          //包體
          create or replace package body showall is
          procedure GetRecords(ret_cursor out mycursor) as
          begin
          open ret_cursor for select * from code_dam;
          end GetRecords;
          end showall;


          //刪除數(shù)據(jù)
          create or replace procedure delRecord(id_in in int)
          is
          begin
          delete from code_dam where id=id_in;
          commit;
          end;

          //插入數(shù)據(jù)
          create or replace procedure insertRecord(code_in in varchar2,name_in in varchar2,remark_in in varchar2) is
          begin
          insert into code_dam (code,name,remark) values (code_in,name_in,remark_in);
          commit;
          end;


          //更新數(shù)據(jù)
          create or replace procedure updataRecord(id_in in int,code_in in varchar2,name_in in varchar2,remark_in in varchar2)
          is
          begin
          update code_dam set code=code_in,name=name_in,remark=remark_in where id=id_in;
          commit;
          end;


          //檢查重復(fù)
          create or replace procedure checkdam
          (code_in in varchar2,name_in in varchar,name_out out varchar2)
          is
          begin
          select name into name_out from code_dam where code = code_in or name = name_in;
          end checkdam;


          //查詢單個(gè)數(shù)據(jù)
          //包
          create or replace package showdam is
          type mycursor is ref cursor;
          procedure GetRecords(id_in in int,ret_cursor out mycursor);
          end showdam;
          //包體
          create or replace package body showdam is
          procedure GetRecords(id_in in int,ret_cursor out mycursor) as
          begin
          open ret_cursor for select * from code_dam where id = id_in;
          end GetRecords;
          end showdam;

          主站蜘蛛池模板: 大厂| 买车| 易门县| 固原市| 中江县| 龙游县| 毕节市| 夏邑县| 顺义区| 乃东县| 固阳县| 筠连县| 时尚| 醴陵市| 沂水县| 本溪| 合阳县| 安宁市| 平果县| 共和县| 宝兴县| 潮安县| 黄山市| 锡林浩特市| 托里县| 静海县| 康平县| 黔西| 沾益县| 乌审旗| 什邡市| 榆树市| 永年县| 长泰县| 房山区| 沈阳市| 临清市| 成安县| 濮阳市| 陆丰市| 安多县|