oracle 建表空間,授權,建表,建存儲過程腳本

  1. -- select sysdate from dual;  
  2.   
  3. -- 以管理員身份登錄PL/SQL, create tablespace  
  4. create tablespace YourProject_table_space datafile 'D:\oracle\data\customed\YourProject.dbf' size 100M;  
  5.   
  6. -- create user and assign tablespace for this user  
  7. create user YourProject_admin_u identified by YourProject_admin_p default tablespace YourProject_table_space;  
  8.   
  9. -- grant user privilege  
  10. grant connect,resource to YourProject_admin_u;  
  11.   
  12.   
  13.   
  14. -- 以 YourProject_admin_u 身份登錄 oracle 數據庫,創建如下的表 及 存儲過程  
  15.   
  16. create table tblStatistic  
  17. (  
  18.   ID int  
  19.   ,UserID varchar2(50)  
  20.   ,UserName varchar2(50)  
  21.   ,Telephone int  
  22.   ,StatisticTypeID int --2:user login; 3:online draft; 4:audit or modify  
  23.   ,Title varchar2(500)  
  24.   ,ObjectID int -- if not have this value, fill 0  
  25.   ,OperDate Date  
  26. );  
  27.   
  28. create table tblVideo   
  29. (   
  30.   ID int   
  31.   ,Subject varchar2(50)   
  32.   ,Description varchar2(50)   
  33.   ,YoukuVideoUrl varchar2(1000)   
  34.   ,YoukuVideoID varchar(50)   
  35.   ,OperDate Date   
  36.   ,ViewCount int   
  37.   ,YoukuPlayUrl varchar2(1000)    
  38.   ,DownloadUrl varchar2(1000)   
  39. );   
  40.   
  41. -- 用戶收藏  
  42. create table tblUserFavorite  
  43. (  
  44.        ID int  
  45.        ,UserID varchar2(50)  
  46.        ,UserName varchar2(50)  
  47.        ,Telephone int  
  48.        ,ArticleID int  
  49.        ,ArticleTypeID int  
  50.        ,Title varchar2(100)  
  51.        ,Description varchar2(500)  
  52.        ,OperDate date  
  53.        ,DocTypeID int -- (0-案例, 1-合同, 2-法律)  
  54. );  
  55.   
  56. -- 用戶諮詢  
  57. create table tblUserConsultation  
  58. (  
  59.        ID int  
  60.        ,UserID varchar2(50)  
  61.        ,UserName varchar2(50)  
  62.        ,Telephone int  
  63.        ,RequestPeople varchar2(50)  
  64.        ,BusinessType varchar2(50)  
  65.        ,BusinessSubType varchar2(50)  
  66.        ,Topic varchar2(100)  
  67.        ,Content varchar2(4000)  
  68.        ,IsPublic numeric(1)  
  69.        ,OperDate date  
  70. );  
  71.   
  72. -- 用戶反饋  
  73. create table tblUserFeedback  
  74. (  
  75.        ID int  
  76.        ,UserID varchar2(50)  
  77.        ,UserName varchar2(50)  
  78.        ,Telephone int  
  79.        ,Email varchar2(100)  
  80.        ,Content varchar2(1000)  
  81.        ,OperDate date  
  82. );  
  83.   
  84. -- 文章閱讀信息  
  85. create table tblArticleRead  
  86. (  
  87.        ID int  
  88.        ,ArticleID int  
  89.        ,ArticleTypeID int  
  90.        ,ArticleType varchar2(50)  
  91.        ,ReadCount int  
  92. );  
  93.   
  94. -- 系統裝機統計  
  95. create table tblInstallDevice  
  96. (  
  97.        ID int  
  98.        ,DeviceNumber varchar2(100)  
  99.        ,InstallDate date  
  100. );  
  101.   
  102.   
  103.   
  104.   
  105. -- store procedure  
  106. -- 增加文章閱讀  
  107. create or replace procedure spAddArticleRead  
  108. (  
  109.        v_articleID int,  
  110.        v_articleTypeID int,  
  111.        v_articleType varchar2  
  112. )  
  113. as  
  114.          v_existCount int;  
  115. begin  
  116.        SELECT count(*) into v_existCount   
  117.        from tblArticleRead where ArticleID=v_articleID and ArticleTypeID=v_articleTypeID;  
  118.   
  119.       --dbms_output.put_line(v_existCount);  
  120.       if(v_existCount>=1) then  
  121.          --dbms_output.put_line('exists');  
  122.          update tblArticleRead set ReadCount=ReadCount+1 where ArticleID=v_articleID and ArticleTypeID=v_articleTypeID;  
  123.       else  
  124.          --dbms_output.put_line('not exists');  
  125.          insert into tblArticleRead  
  126.          (  
  127.                ID,ArticleID,ArticleTypeID  
  128.                ,ArticleType,ReadCount  
  129.          )  
  130.           select nvl(max(ID),0) + 1,v_articleID,v_articleTypeID  
  131.                  ,v_articleType,1  
  132.           from   tblArticleRead;  
  133.       end if;  
  134. end;  
  135.   
  136. -- 增加用戶收藏  
  137. create or replace procedure spAddMyFavorite  
  138. (  
  139.        v_UserID varchar2,  
  140.        v_UserName varchar2,  
  141.        v_Telephone varchar2,  
  142.        v_ArticleID int,  
  143.        v_ArticleTypeID int,  
  144.        v_Title varchar2,  
  145.        v_Description varchar2,  
  146.        v_DocTypeID int  
  147. )  
  148. as  
  149.          v_tmpWhere varchar2(4000);  
  150.          v_tmpSQL varchar2(4000);  
  151.          v_existCount int;  
  152. begin  
  153.          
  154.       v_tmpWhere :='';  
  155.   
  156.       if nvl(v_UserID,'X') !='X' then  
  157.           v_tmpWhere := v_tmpWhere || ' and UserID=''' || trim(v_UserID) || '''';  
  158.       end if;  
  159.         
  160.       if nvl(v_UserName,'X') !='X' then  
  161.           v_tmpWhere := v_tmpWhere || ' and UserName=''' || trim(v_UserName) || '''';  
  162.       end if;  
  163.         
  164.       if nvl(v_Telephone,'X') !='X' then  
  165.           v_tmpWhere := v_tmpWhere || ' and Telephone=''' || v_Telephone || '''';  
  166.       end if;  
  167.         
  168.       if v_ArticleID >0 then  
  169.           v_tmpWhere := v_tmpWhere || ' and ArticleID=' || v_ArticleID ;  
  170.       end if;  
  171.         
  172.       if v_ArticleTypeID >0 then  
  173.           v_tmpWhere := v_tmpWhere || ' and ArticleTypeID=' || v_ArticleTypeID;  
  174.       end if;  
  175.         
  176.       if nvl(v_Title,'X') !='X' then  
  177.           v_tmpWhere := v_tmpWhere || ' and Title =''' || trim(v_Title) || '''';  
  178.       end if;  
  179.         
  180.       if nvl(v_Description,'X') !='X' then  
  181.           v_tmpWhere := v_tmpWhere || ' and Description =''' || trim(v_Description) || '''';  
  182.       end if;  
  183.         
  184.       if v_DocTypeID >-1 then  
  185.           v_tmpWhere := v_tmpWhere || ' and DocTypeID =' || v_DocTypeID  ;  
  186.       end if;  
  187.          
  188.        --dbms_output.put_line(v_tmpWhere);  
  189.   
  190.       if(length(v_tmpWhere)>0) then                    
  191.            v_tmpWhere := ' where ' || substr(v_tmpWhere,5);  
  192.        end if;  
  193.   
  194.        v_tmpSQL :='SELECT count(*) from tblUserFavorite ' || v_tmpWhere;  
  195.        EXECUTE IMMEDIATE v_tmpSQL into v_existCount;  
  196.        --dbms_output.put_line(v_tmpSQL);  
  197.        --dbms_output.put_line(v_existCount);  
  198.   
  199.       if(v_existCount<1) then  
  200.          --dbms_output.put_line('not exists');  
  201.   
  202.            insert into tblUserFavorite  
  203.           (  
  204.                  ID,UserID,UserName,Telephone  
  205.                  ,ArticleID,ArticleTypeID,Title,Description  
  206.                  ,OperDate,DocTypeID  
  207.           )  
  208.           select nvl(max(ID),0) + 1,v_UserID,v_UserName,v_Telephone  
  209.                  ,v_ArticleID,v_ArticleTypeID,v_Title,v_Description  
  210.                  ,to_date(sysdate),v_DocTypeID  
  211.           from   tblUserFavorite;  
  212.       else  
  213.           dbms_output.put_line('您已經收藏過此項!');  
  214.           raise_application_error(-20001,'您已經收藏過此項!');     
  215.       end if;  
  216. end;  
  217.   
  218. -- 添加裝機信息  
  219. create or replace procedure spAddInstallDevice  
  220. (  
  221.        v_DeviceNumber varchar2  
  222. )  
  223. as  
  224. begin  
  225.       insert into tblInstallDevice  
  226.       (  
  227.              ID,DeviceNumber,InstallDate  
  228.       )  
  229.       select nvl(max(ID),0) + 1,v_DeviceNumber,to_date(sysdate)  
  230.       from   tblInstallDevice;  
  231. end;  
  232.   
  233. -- 添加統計信息  
  234. create or replace procedure spAddStatisticContent  
  235. (  
  236.        v_UserID varchar2,  
  237.        v_UserName varchar2,  
  238.        v_Telephone varchar2,  
  239.        v_StatisticTypeID int,  
  240.        v_Title varchar2,  
  241.        v_ObjectID int  
  242. )  
  243. as  
  244. begin  
  245.       insert into tblStatistic  
  246.       (  
  247.              ID,UserID,UserName,Telephone  
  248.              ,StatisticTypeID,Title,ObjectID  
  249.              ,OperDate  
  250.       )  
  251.       select nvl(max(ID),0) + 1,v_UserID,v_UserName,v_Telephone  
  252.              ,v_StatisticTypeID,v_Title,v_ObjectID  
  253.             --,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')  
  254.             ,to_char(sysdate)  
  255.       from   tblStatistic;  
  256. end;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章