oracle 开启utl_tcp,关于Oracle的UTL_TCP
(在Oracle9.2下,link:http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_tcp.htm#ARPLS075)
With the UTL_TCP package and its procedures and functions, PL/SQL applications can communicate with external TCP/IP-based servers using TCP/IP. Because many Internet application protocols are based on TCP/IP, this package is useful to PL/SQL applications that use Internet protocols and e-mail.
(通過使用UTL_TCP包和他的過程與函數(shù),PL/SQL程序能夠使用TCP/IP協(xié)議與其他的基于TCP/IP的服務(wù)器進(jìn)行通信。這個(gè)包對于使用網(wǎng)絡(luò)和email服務(wù)的PL/SQL程序非常有用,因?yàn)樵S多網(wǎng)絡(luò)服務(wù)程序協(xié)議都是基于TCP/IP協(xié)議的。)
Oracle的UTL_TCP包提供了一種額外的方法來主動與應(yīng)用程序來進(jìn)行通信。比如我們可以通過一個(gè)觸發(fā)器,當(dāng)某張表的數(shù)據(jù)被更改時(shí),即時(shí)通知應(yīng)用程序基礎(chǔ)的通知應(yīng)用程序服務(wù),當(dāng)然,這個(gè)應(yīng)用程序服務(wù)需要開監(jiān)聽。寫了個(gè)小測試東西來測試了下UTL_TCP:
1)以下是一個(gè)PL/SQL過程,使用UTL_TCP包,與ip為xxx.xxx.xxx.xxx:1234進(jìn)行通信。只是簡單的發(fā)送"Result has changed":
1: CREATE OR REPLACE procedure USERID.P_SendNotice
2: IS
3: conn utl_tcp.connection;
4: ret_val pls_integer;
6: conn := utl_tcp.open_connection(remote_host => 'xxx.xxx.xxx.xxx',
7: remote_port => 1234,
8: charset => 'US7ASCII');
9:
10: ret_val:=utl_tcp.write_line(conn, 'Result has changed');
11: dbms_output.put_line(to_char(ret_val));
13: when utl_tcp.NETWORK_ERROR then
14: dbms_output.put_line('network error');
15: End;
2)在一張表上建個(gè)觸發(fā)器,以便對該表數(shù)據(jù)進(jìn)行更改時(shí)候,發(fā)送通知消息給外部服務(wù)器:
1: CREATE OR REPLACE TRIGGER USERID.noticesend_trg
3: ON USERID.TableName REFERENCING NEW AS NEW OLD AS OLD
5: P_SendNotice ();
6: END;
3)在應(yīng)用程序中,應(yīng)該監(jiān)聽我在上面包中所寫ip為xxx.xxx.xxx.xxx的1234端口,以完成對相應(yīng)消息的接收
至此,完成一個(gè)簡單的Oracle UTL_TCP的小應(yīng)用。當(dāng)表數(shù)據(jù)中發(fā)生改變的時(shí)候,通過觸發(fā)器來調(diào)用過程,發(fā)送通知給應(yīng)用服務(wù)器,應(yīng)用服務(wù)器再做相應(yīng)的相應(yīng)。
UTL_TCP的限制:The UTL_TCP package provides TCP/IP client-side access functionality in PL/SQL. The API provided in the package only allows connections to be initiated by the PL/SQL program.It does not allow the PL/SQL program to accept connections initiated outside the program.
總結(jié)
以上是生活随笔為你收集整理的oracle 开启utl_tcp,关于Oracle的UTL_TCP的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AEAI Portal V3.5.2门户
- 下一篇: 10bit视频编码——特性及全面播放方法