您好,登錄后才能下訂單哦!
這篇文章主要介紹“oracle基礎知識有哪些”,在日常操作中,相信很多人在oracle基礎知識有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”oracle基礎知識有哪些”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
1.創建表空間
--創建表空間CREATE TABLESPACE fund DATAFILE 'e:\ORADATA\fundd_file.dbf' SIZE 40M;
2.創建用戶
--創建用戶及密碼CREATE USER test_userIDENTIFIED BY test123456 DEFAULT TABLESPACE fund;
3.給用戶賦權
--授權GRANT CONNECT,RESOURCE TO test_user;
4.創建表
--創建表CREATE TABLE Fund(FundNo VARCHAR2(20),CompanyId VARCHAR2(20),FundName VARCHAR2(20),Price NUMBER(10,2),FundType NUMBER(1,0),Invest NUMBER(1,0),BuyLimit NUMBER(5,0),IsChange NUMBER(1,0),YearRate NUMBER(6,5),ApplyDate DATE,State NUMBER(1,0));
5.給表添加主鍵及外鍵約束
--刪除已有的主鍵--ALTER TABLE Fund DROP CONSTRAINT PK_Fund;--添加主鍵約束ALTER TABLE Fund ADD CONSTRAINT PK_Fund_FundNo PRIMARY KEY(FundNo);--添加外鍵約束ALTER TABLE Fund ADD CONSTRAINT FK_Fund_CompanyId FOREIGN KEY(CompanyId) REFERENCES FundCompany(CompanyId);
6.給表及字段添加注釋
--給表添加注釋COMMENT ON TABLE Fund IS '基金表';--給表字段添加注釋COMMENT ON COLUMN Fund.FundNo IS '基金代碼ID,主鍵';COMMENT ON COLUMN Fund.CompanyId IS '基金公司ID,外鍵引用FundCompany表的CompanyId';COMMENT ON COLUMN Fund.FundName IS '基金名稱';COMMENT ON COLUMN Fund.Price IS '基金凈值';COMMENT ON COLUMN Fund.FundType IS '基金類型,1表示開放式,2表示封閉式';COMMENT ON COLUMN Fund.Invest IS '投資方向,1股票,2債券,3貨幣,4混合';COMMENT ON COLUMN Fund.BuyLimit IS '購買下限';COMMENT ON COLUMN Fund.IsChange IS '是否可轉換,0表示不可轉換,1表示可轉換';COMMENT ON COLUMN Fund.YearRate IS '年利率,必須是0-1之間的數字';COMMENT ON COLUMN Fund.ApplyDate IS '申請日期';COMMENT ON COLUMN Fund.State IS '基金狀態,0表示正常,1表示凍結';
7.創建函數
CREATE OR REPLACE FUNCTION FUNC_NEXTID(I_SQ IN VARCHAR2,I_TITLE IN VARCHAR2,I_LEN IN NUMBER) RETURN VARCHAR2 ASV_SQ VARCHAR2(100);V_KEY VARCHAR2(100);BEGINSELECT I_SQ || '.NEXTVAL' INTO V_SQ FROM DUAL;SELECT I_TITLE || LPAD(V_SQ, I_LEN, 0) INTO V_KEY FROM DUAL;RETURN V_KEY;END;
8.創建序列
--為基金公司表(FundCompany)主鍵創建序列CREATE SEQUENCE SQ_COMPANYIDINCREMENT BY 1 --每次加1START WITH 1 --從1開始NOMAXVALUE --沒有最大值NOCYCLE --一直累加不循環CACHE 10;
9.創建觸發器
CREATE OR REPLACE TRIGGER TR_FundBEFORE INSERT ON FundFOR EACH ROWBEGIN:NEW.FUNDNO := FUNC_NEXTID('V', 'SQ_FundNo.NEXTVAL', 6);END;
10.創建程序包(包體中包括了函數及過程)
包:
/*--------------------------------------------------創建包說明--包名:FundAccountManager_pack--功能描述:創建過程或函數分別實現,基金賬戶開戶、基金賬戶信息查詢。--原創:釣魚君--日期:2016/3/10--QQ:954739353--------------------------------------------------*/CREATE OR REPLACE PACKAGE FundAccountManager_pack IS--活期賬戶開戶FUNCTION FUNC_ADD_CURRENTACCOUNT(I_CURRENTPASSWORD VARCHAR2,I_DEPOSITSUM NUMBER,I_CARDTYPE NUMBER,I_CARDNO VARCHAR2,I_NAME VARCHAR2,I_ADDRESS VARCHAR2,I_PHONE VARCHAR2,I_SEX NUMBER,I_OPENACCDATE DATE,I_STATE NUMBER) RETURN NUMBER;--理財賬戶開戶FUNCTION FUNC_ADD_FINANCINGACCOUNT(I_FINANCEPASSWORD VARCHAR2,I_MONEYTYPE NUMBER,I_ACCOUNTBALANCE NUMBER,I_ENABLEBALANCE NUMBER,I_CONGEALFUND NUMBER,I_STATE NUMBER,I_CURRENTACCOUNT VARCHAR2)RETURN NUMBER;--基金賬戶開戶FUNCTION FUNC_ADD_FUNDACCOUNT(I_FINANCINGACCOUNT VARCHAR2,I_COMPANYID VARCHAR2,I_CARDTYPE NUMBER,I_CARDNO VARCHAR2,I_NAME VARCHAR2,I_SEX NUMBER,I_ADDRESS VARCHAR2,I_PHONE VARCHAR2,I_POSTNUM VARCHAR2,I_EMAIL VARCHAR2,I_CREATEDATE DATE,I_CONGEALSTATE NUMBER) RETURN NUMBER;--基金賬戶信息查詢PROCEDURE PRO_QUERY_FUNDACCOUNT(O_RESULT OUT SYS_REFCURSOR,I_FINANCINGACCOUNT IN VARCHAR2);END FundAccountManager_pack;
包體:
CREATE OR REPLACE PACKAGE BODY FundAccountManager_pack IS----活期賬戶開戶/*--------------------------------------------------創建包說明--包名:FundAccountManager_pack--功能描述:創建過程或函數分別實現,基金賬戶開戶、基金賬戶信息查詢。--原創:釣魚君--日期:2016/3/10--QQ:954739353--------------------------------------------------*/FUNCTION FUNC_ADD_CURRENTACCOUNT(I_CURRENTPASSWORD VARCHAR2,I_DEPOSITSUM NUMBER,I_CARDTYPE NUMBER,I_CARDNO VARCHAR2,I_NAME VARCHAR2,I_ADDRESS VARCHAR2,I_PHONE VARCHAR2,I_SEX NUMBER,I_OPENACCDATE DATE,I_STATE NUMBER) RETURN NUMBER ISERR_CURRENTACCOUNT EXCEPTION;PRAGMA EXCEPTION_INIT(ERR_CURRENTACCOUNT, -1);/*違反唯一主鍵約束為-1*/BEGININSERT INTO CURRENTACCOUNT(CURRENTPASSWORD,DEPOSITSUM,CARDTYPE,CARDNO,NAME,ADDRESS,PHONE,SEX,OPENACCDATE,STATE)VALUES(I_CURRENTPASSWORD,I_DEPOSITSUM,I_CARDTYPE,I_CARDNO,I_NAME,I_ADDRESS,I_PHONE,I_SEX,I_OPENACCDATE,I_STATE);IF SQL%FOUND THENRETURN 1;END IF;EXCEPTIONWHEN ERR_CURRENTACCOUNT THENRETURN 0;WHEN OTHERS THENRETURN - 1;END FUNC_ADD_CURRENTACCOUNT;--理財賬戶開戶FUNCTION FUNC_ADD_FINANCINGACCOUNT(I_FINANCEPASSWORD VARCHAR2,I_MONEYTYPE NUMBER,I_ACCOUNTBALANCE NUMBER,I_ENABLEBALANCE NUMBER,I_CONGEALFUND NUMBER,I_STATE NUMBER,I_CURRENTACCOUNT VARCHAR2)RETURN NUMBER ISERR_FINANCINGACCOUNT EXCEPTION;PRAGMA EXCEPTION_INIT(ERR_FINANCINGACCOUNT, -1);BEGININSERT INTO FINANCINGACCOUNT(FINANCEPASSWORD,MONEYTYPE,ACCOUNTBALANCE,ENABLEBALANCE,CONGEALFUND,STATE,CURRENTACCOUNT)VALUES(I_FINANCEPASSWORD,I_MONEYTYPE,I_ACCOUNTBALANCE,I_ENABLEBALANCE,I_CONGEALFUND,I_STATE,I_CURRENTACCOUNT);IF SQL%FOUND THENRETURN 1;END IF;EXCEPTIONWHEN ERR_FINANCINGACCOUNT THENRETURN 0;WHEN OTHERS THENRETURN - 1;END FUNC_ADD_FINANCINGACCOUNT;--基金賬戶開戶FUNCTION FUNC_ADD_FUNDACCOUNT(I_FINANCINGACCOUNT VARCHAR2,I_COMPANYID VARCHAR2,I_CARDTYPE NUMBER,I_CARDNO VARCHAR2,I_NAME VARCHAR2,I_SEX NUMBER,I_ADDRESS VARCHAR2,I_PHONE VARCHAR2,I_POSTNUM VARCHAR2,I_EMAIL VARCHAR2,I_CREATEDATE DATE,I_CONGEALSTATE NUMBER) RETURN NUMBER ISERR_FUNDACCOUNT EXCEPTION;PRAGMA EXCEPTION_INIT(ERR_FUNDACCOUNT, -1);V_COUNT NUMBER;BEGIN--約束條件檢查SELECT COUNT(FINANCINGACCOUNT)INTO V_COUNTFROM FUNDACCOUNTWHERE FINANCINGACCOUNT = I_FINANCINGACCOUNTAND COMPANYID = I_COMPANYID;IF V_COUNT = 0 THENINSERT INTO FUNDACCOUNT(FINANCINGACCOUNT,COMPANYID,CARDTYPE,CARDNO,NAME,SEX,ADDRESS,PHONE,POSTNUM,EMAIL,CREATEDATE,CONGEALSTATE)VALUES(I_FINANCINGACCOUNT,I_COMPANYID,I_CARDTYPE,I_CARDNO,I_NAME,I_SEX,I_ADDRESS,I_PHONE,I_POSTNUM,I_EMAIL,I_CREATEDATE,I_CONGEALSTATE);IF SQL%FOUND THENRETURN 1;END IF;ELSERETURN - 1;END IF;EXCEPTIONWHEN ERR_FUNDACCOUNT THENRETURN 0;WHEN OTHERS THENRETURN - 1;END FUNC_ADD_FUNDACCOUNT;--基金賬戶的查詢PROCEDURE PRO_QUERY_FUNDACCOUNT(O_RESULT OUT SYS_REFCURSOR,I_FINANCINGACCOUNT IN VARCHAR2) ASBEGINOPEN O_RESULT FORSELECT *FROM FUNDACCOUNT TWHERE T.FINANCINGACCOUNT = I_FINANCINGACCOUNT;END PRO_QUERY_FUNDACCOUNT;END FundAccountManager_pack;
到此,關于“oracle基礎知識有哪些”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。