網際網路資料庫連結 2002 Oracle Web Programming. 上完這段課程,你將學會...
-
date post
20-Dec-2015 -
Category
Documents
-
view
258 -
download
0
Transcript of 網際網路資料庫連結 2002 Oracle Web Programming. 上完這段課程,你將學會...
網際網路資料庫連結網際網路資料庫連結2002
Oracle Web Programming
上完這段課程,你將學會上完這段課程,你將學會一般靜態網頁與互動式網頁的區別。網際網路上大量資料的存取。資料庫的角色與功能。Web Server 的角色與功能。網際網路資料庫的應用。基本的程式寫作技巧及網頁的應用。程式, Web Server 與資料庫間的關係。
靜態網頁 靜態網頁 VS. VS. 互動式網頁互動式網頁靜態網頁與互動式網頁提供不同型態的服務。靜態網頁能表現是單方向的資訊呈現。互動式網頁提供的服務較『實用』。e.g. 火車 /飛機時刻查詢﹑課程查詢等。
政府資料庫的公開 →帶動互動式網頁的蓬勃發展。
必須清楚的掌握使用靜態與互動式網頁的時機。
所有的網頁 靜態網頁的瀏覽方式
index.htm
xxx.htm
imagezzz.jpg
yy.gif
Internet
BROWSER
....
....
....
動態網頁的瀏覽方式
程式
html on the fly
資料庫引擎
資料庫
WEB SERVER
互動式網頁互動式網頁資料庫『輕易』的提供網際網路較具價值的互動式網路資訊。
儲存在資料庫的資訊:– 可以較靈活的被使用與管理,– 附加價值較高,– 在較短的時間提供不同的服務。
The EnvironmentThe Environment
INTERNET
Browser
WEB SERVERDATABASE SERVER
web2.ntpu.edu.tw192.83.185.93 orWeb2.ntpu.edu.tw
http://web2.ntpu.edu.tw/pls/student/ 程式名稱
CGI 程式
Where are the Programs?Where are the Programs?
DATABASE SERVER
TABLES PROGRAMS
資料庫管理系統DBMS
網際網路資料庫的基本觀念網際網路資料庫的基本觀念
網際網路資料庫的特色– 承襲 HTTP stateless 的特性﹐– Browser 與 Web server 間的連線無法持續﹐
– server 執行後的狀態無法保留。– huge access rate 。
Database Server
databaseclient
databaseclient
databaseclient
PC
LAN
session
WebServer
database client
INTERNET
databaseclient
WWW client
WWW client
WWW client
下 20筆資料庫引擎
下 20筆資料庫引擎
Client
Web Browser
資料庫 結果
資料庫結果
Lan-based
Web-based
TCP/IP
HTTP
PL/SQLPL/SQL 程式寫作環境程式寫作環境程式語言 vs. 程式開發軟體 ( 工具 ) 。SQL Navigator 介紹。PL/SQL 程式在 Oracle 資料庫中的角色。PL/SQL 程式在網際網路資料連結的角色。
What does a program look What does a program look like?like?
PACKAGE( 程式包裝 )
Procedures( 程式 )
The structure of a The structure of a PackagePackage
SPEC程式包裝定義
BODY程式包裝主體
SPECSPEC ::程式包裝程式包裝定義區定義區
PACKAGE SAMPLE IS
procedure demo1; procedure demo1_result(
stud_no IN varchar2 default NULL);
END;
程式包裝 (package) 的名稱
程式名稱
程式的輸入參數及格式
BODYBODY ::程式包裝程式包裝主體區主體區PACKAGE BODY SAMPLE IS
END;
程式包裝 (package) 的名稱
PROCEDURE demo1
PROCEDURE demo1_result
Procedure(Procedure( 程式程式 )) 的規格的規格(( 一一 ))PROCEDURE demo1 IS
name varchar2(10);
BEGIN
htp.htmlopen; htp.headopen; htp.title(' 台北進修部 '); htp.headclose; htp.bodyopen;
……………………
……………………
END;
程式開始
程式結束
程式內容
程式變數定義程式名稱
Procedure(Procedure( 程式程式 )) 的規格的規格(( 二二 ))程式變數定義程式變數定義PROCEDURE demo1 IS
name varchar2(10);
studno number(5);
today date;
BEGIN變數名稱 變數的格式
Data type
Procedure(Procedure( 程式程式 )) 的規格的規格(( 三三 ))程式內容程式內容PROCEDURE demo1 IS
BEGIN
htp.htmlopen; htp.headopen; htp.title(‘台北大學’ ); htp.headclose; htp.p(‘<h3>學生名冊 </h3>’);
、、、
htp.bodyclose; htp.htmlclose;
END;
htp 資料庫內建的 packagehtmlopen 、 headopen 、title 、、、 是 htp 裡面的
procedure
PackagePackage 的使用:從的使用:從 BrowserBrowser 開始開始
The URL– http://web2.ntpu.edu.tw/pls/student/ pack
age_name.procedure_name– 例如:– http://web2.ntpu.edu.tw/pls/student/sample.menu
指定的Web server 路徑 Your program
Practices in classPractices 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
Programming in Programming in PL/SQLPL/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
Variable Variable 變數變數PROCEDURE demo4_result( deptno IN varchar2 default NULL) IS
deptname varchar2(32);Sex varchar2(2);
BEGIN變數名稱
資料型態Eg. 字串 (長度 )
Variable AssignmentVariable Assignment
BEGINselect dept_full_name into deptnamefrom dept where dept_no=deptno;.. if c.stud_sex='F' then sex:='女 '; else sex:='男 '; end if;
Conditional ControlConditional Control
if c.stud_sex='F' then sex:='女 ';else sex:='男 ';end if;
Iterative ControlIterative Control
for c in c1 loop
htp.p(c.stud_no); htp.p(‘<br>'||c.stud_chinese_name);
end loop;
Cursor name
String pipe: 將字串與變數值連起來
Built-in Functions vs. Self-Designed functionsBuilt-in Functions vs. Self-Designed functions
htp.htmlopen; htp.headopen; htp.title('國立台北大學 '); style; htp.headclose; htp.bodyopen; htp.p('<center>');
Self-designed function(procedure)
Built-in function
Exception HandlingException 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
如何在如何在 PL/SQLPL/SQL 中使用中使用 SQLSQL 指令指令 (1)(1)多筆資料的擷取 ( 定義在 BEGIN 前 )
– 定義 cursorCursor c1select stud_chinese_name from studentwhere stmd_dept=‘P78’;BEGIN.For c in c1 loop
htp.p(c.stud_chinese_name);end loop;
將結果存入變數c.stud_chinese_name
輸出結果
逐筆處理
如何在如何在 PL/SQLPL/SQL 中使用中使用 SQLSQL 指令指令(2)(2)單筆資料的擷取 ( 定義在 BEGIN 後 )
BEGINSelect stud_chinese_name into namefrom studentwhere stud_no=‘38656003’
htp.p(name);
將結果存入變數 name
輸出結果
PL/SQLPL/SQL 對於日期的處理對於日期的處理 (1)(1)
TO_DATE– 將字串格式改為 ORACLE 的日期格式– 方能存入資料格式為 DATE 的欄位– 使用方式: TO_DATE(string, format)– string 為字串變數或字串,如 ‘ 2000/12/23– format 代表 string 中數字代表的意義,如 ‘ YY
YY/MM/DD’ 說明了 2000/12/23 的意義– 其他例子:
• TO_DATE(‘12-23-01’,‘MM-DD-YY’)• TO_DATE(‘05032001’,‘DDMMYYYY’)
PL/SQLPL/SQL 對於日期的處理對於日期的處理 (2)(2)TO_CHAR
– 可以將日期格式轉換為字串格式– TO_CHAR(stud_birth,’MM/DD/YYYY’)– 例如
• select stud_no, to_char(stud_birth,‘MM/DD/YYYY’) fom xsample