1 / 31

網際網路資料庫連結

網際網路資料庫連結. 2002 Oracle Web Programming. 上完這段課程,你將學會. 一般靜態網頁與互動式網頁的區別。 網際網路上大量資料的存取。 資料庫的角色與功能。 Web Server 的角色與功能。 網際網路資料庫的應用。 基本的程式寫作技巧及網頁的應用。 程式, Web Server 與資料庫間的關係。. 靜態網頁 VS. 互動式網頁. 靜態網頁與互動式網頁提供不同型態的服務。 靜態網頁能表現是單方向的資訊呈現。 互動式網頁提供的服務較 『 實用 』 。 e.g. 火車 / 飛機時刻查詢 ﹑ 課程查詢等。

ethel
Télécharger la présentation

網際網路資料庫連結

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 網際網路資料庫連結 2002 Oracle Web Programming

  2. 上完這段課程,你將學會 • 一般靜態網頁與互動式網頁的區別。 • 網際網路上大量資料的存取。 • 資料庫的角色與功能。 • Web Server的角色與功能。 • 網際網路資料庫的應用。 • 基本的程式寫作技巧及網頁的應用。 • 程式,Web Server與資料庫間的關係。

  3. 靜態網頁 VS. 互動式網頁 • 靜態網頁與互動式網頁提供不同型態的服務。 • 靜態網頁能表現是單方向的資訊呈現。 • 互動式網頁提供的服務較『實用』。 e.g.火車/飛機時刻查詢﹑課程查詢等。 • 政府資料庫的公開 →帶動互動式網頁的蓬勃發展。 • 必須清楚的掌握使用靜態與互動式網頁的時機。

  4. 資料庫 html on the fly 程 式 .... .... .... 資料庫 引擎 動態網頁的瀏覽方式 所有的網頁 靜態網頁的瀏覽方式 index.htm WEB SERVER xxx.htm image zzz.jpg yy.gif Internet BROWSER

  5. 互動式網頁 • 資料庫『輕易』的提供網際網路較具價值的互動式網路資訊。 • 儲存在資料庫的資訊: • 可以較靈活的被使用與管理, • 附加價值較高, • 在較短的時間提供不同的服務。

  6. The Environment http://web2.ntpu.edu.tw/pls/student/程式名稱 INTERNET Browser CGI程式 192.83.185.93 or Web2.ntpu.edu.tw web2.ntpu.edu.tw DATABASE SERVER WEB SERVER

  7. Where are the Programs? 資料庫管理系統 DBMS PROGRAMS TABLES DATABASE SERVER

  8. 網際網路資料庫的基本觀念 • 網際網路資料庫的特色 • 承襲HTTP stateless的特性﹐ • Browser與Web server間的連線無法持續﹐ • server執行後的狀態無法保留。 • huge access rate。

  9. 資料庫 Client 結果 TCP/IP 下20筆 資料庫 引擎 Lan-based 結果 Web-based 資料庫 Web Browser HTTP 下20筆 資料庫 引擎

  10. PL/SQL程式寫作環境 • 程式語言 vs. 程式開發軟體(工具)。 • SQL Navigator 介紹。 • PL/SQL程式在Oracle資料庫中的角色。 • PL/SQL程式在網際網路資料連結的角色。

  11. What does a program look like? PACKAGE(程式包裝) Procedures(程式)

  12. The structure of a Package SPEC 程式包裝定義 BODY 程式包裝主體

  13. SPEC:程式包裝定義區 程式包裝(package)的名稱 PACKAGE SAMPLE IS procedure demo1;procedure demo1_result( stud_no INvarchar2defaultNULL); END; 程式名稱 程式的輸入參數及格式

  14. BODY:程式包裝主體區 程式包裝(package)的名稱 PACKAGEBODY SAMPLE IS END; PROCEDURE demo1 PROCEDURE demo1_result

  15. Procedure(程式)的規格(一) PROCEDURE demo1 IS name varchar2(10); BEGIN htp.htmlopen; htp.headopen; htp.title('台北進修部'); htp.headclose; htp.bodyopen; …………………… …………………… END; 程式名稱 程式變數定義 程式開始 程式內容 程式結束

  16. Procedure(程式)的規格(二)程式變數定義 PROCEDURE demo1 IS name varchar2(10); studno number(5); today date; BEGIN 變數名稱 變數的格式 Data type

  17. Procedure(程式)的規格(三)程式內容 PROCEDURE demo1 IS BEGIN htp.htmlopen; htp.headopen; htp.title(‘台北大學’); htp.headclose; htp.p(‘<h3>學生名冊</h3>’); 、、、 htp.bodyclose; htp.htmlclose; END; htp 資料庫內建的package htmlopen、headopen、 title、、、 是 htp 裡面的 procedure

  18. Package的使用:從Browser開始 • The URL • http://web2.ntpu.edu.tw/pls/student/ package_name.procedure_name • 例如: • http://web2.ntpu.edu.tw/pls/student/sample.menu Your program 指定的Web server 路徑

  19. Practices in class • Web Form(表單)練習(無資料庫連接)。 • sample.demo1, sample.demo1_result • sample.demo2, sample.demo2_result • Web Form(表單)練習(連接到資料庫)。 • sample.demo3, sample.demo3_result • sample.demo4, sample.demo4_result

  20. Programming in PL/SQL • Variable Declaration、 Assignment and Usage • Conditional Control: • if else elsif end • Iterative Control • for loop while exit • Built-in Functions & Self-Designed functions • htp.p htp.htmlopen sysdate sum • Exception Handling

  21. Variable 變數 PROCEDURE demo4_result( deptno IN varchar2 default NULL) IS deptname varchar2(32); Sex varchar2(2); BEGIN 資料型態 Eg. 字串(長度) 變數名稱

  22. Variable Assignment BEGIN select dept_full_name into deptname from dept where dept_no=deptno; . . if c.stud_sex='F' then sex:='女'; else sex:='男'; end if;

  23. Conditional Control if c.stud_sex='F' then sex:='女'; else sex:='男'; end if;

  24. Iterative Control Cursor name for c in c1 loop htp.p(c.stud_no); htp.p(‘<br>'||c.stud_chinese_name); end loop; String pipe:將字串與 變數值連起來

  25. Built-in Functions vs. Self-Designed functions htp.htmlopen; htp.headopen; htp.title('國立台北大學'); style; htp.headclose; htp.bodyopen; htp.p('<center>'); Built-in function Self-designed function(procedure)

  26. Exception Handling BEGIN select dept_full_name into deptname from dept where dept_no=deptno; . . htp.htmlclose; EXCEPTION when NO_DATA_FOUND then htp.p('你是豬頭ㄚ?沒這個系所!'); END; If no data found

  27. 如何在PL/SQL中使用SQL指令(1) • 多筆資料的擷取(定義在BEGIN前) • 定義 cursor Cursor c1 select stud_chinese_name from student where stmd_dept=‘P78’; BEGIN . For c in c1 loop htp.p(c.stud_chinese_name); end loop; 將結果存入變數 c.stud_chinese_name 逐筆處理 輸出結果

  28. 如何在PL/SQL中使用SQL指令(2) • 單筆資料的擷取(定義在BEGIN後) BEGIN Select stud_chinese_name into name from student where stud_no=‘38656003’ htp.p(name); 將結果存入變數name 輸出結果

  29. PL/SQL對於日期的處理(1) • TO_DATE • 將字串格式改為ORACLE的日期格式 • 方能存入資料格式為 DATE的欄位 • 使用方式:TO_DATE(string, format) • string 為字串變數或字串,如 ‘2000/12/23 • format 代表 string 中數字代表的意義,如 ‘YYYY/MM/DD’ 說明了 2000/12/23 的意義 • 其他例子: • TO_DATE(‘12-23-01’,‘MM-DD-YY’) • TO_DATE(‘05032001’,‘DDMMYYYY’)

  30. PL/SQL對於日期的處理(2) • TO_CHAR • 可以將日期格式轉換為字串格式 • TO_CHAR(stud_birth,’MM/DD/YYYY’) • 例如 • select stud_no, to_char(stud_birth,‘MM/DD/YYYY’) fom xsample

More Related