Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB   


 

 

 


 

 

 
 

Oracle UTL_TCP Package

Oracle Tips by Burleson Consulting

Advanced Oracle Utilities: The Definitive Reference by Rampant TechPress is written by top Oracle database experts (Bert Scalzo, Donald Burleson, and Steve Callan).  The following is an excerpt from the book.

The utl_tcp package provides PL/SQL programs the capability to communicate via TCP/IP (Transmission Control Protocol/Internet Protocol). This package requires that the Oracle XMLDB component was chosen during initial database creation or subsequent modification utilizing DBCA. Otherwise, the following series of error messages will come up:

 

SQL> @send_email

DECLARE

*

ERROR at line 1:

ORA-24248: XML DB extensible security not installed

ORA-06512: at "SYS.UTL_TCP", line 17

ORA-06512: at "SYS.UTL_TCP", line 246

ORA-06512: at "SYS.UTL_SMTP", line 115

ORA-06512: at "SYS.UTL_SMTP", line 138

ORA-06512: at line 7

 

Just like utl_smtp, this is one occasion where an example is worth more than the reference material. The email_myself_tcp_demo.sql PL/SQL code is a snippet of PL/SQL to email a message:

 

email_myself_tcp_demo.sql script

 

DECLARE

  sender      VARCHAR2(30) := 'bert.scalzo@yahoo.com';

  recipient   VARCHAR2(30) := 'bert.scalzo@yahoo.com';

  message     VARCHAR2(30) := 'This is a test message';

  mailhost    VARCHAR2(30) := '127.0.0.1';

  mail_conn   utl_tcp.connection;

  PROCEDURE smtp_command (command IN VARCHAR2, ok IN VARCHAR2 DEFAULT '250')

  IS

      response varchar2(3);

      len pls_integer;

  BEGIN

      len := utl_tcp.write_line(mail_conn, command);

      response := substr(utl_tcp.get_line(mail_conn), 1, 3);

  END;

BEGIN

    mail_conn := utl_tcp.open_connection (remote_host => mailhost, remote_port => 25, charset => 'US7ASCII');

    smtp_command ('HELO ' || mailhost);

    smtp_command ('MAIL FROM: ' || sender);

    smtp_command ('RCPT TO: ' || recipient);

    smtp_command ('DATA', '354');

    smtp_command (message);

    smtp_command ('QUIT', '221');

    utl_tcp.close_connection (mail_conn);

END;

/

Next, examine the procedures and functions provided by the utl_tcp package. Key to the process is creating a TCP connection and then using that on subsequent utl_tcp calls. One also needs to work with the following data type and constants:

 

TYPE connection IS RECORD (

  remote_host   VARCHAR2(255),   -- Remote host name

  remote_port   PLS_INTEGER,     -- Remote port number

  local_host    VARCHAR2(255),   -- Local host name

  local_port    PLS_INTEGER,     -- Local port number

  charset       VARCHAR2(30),    -- Character set for on-the-wire comm.

  newline       VARCHAR2(2),     -- Newline character sequence

  tx_timeout    PLS_INTEGER,     -- Transfer time-out value (in seconds)

  private_sd    PLS_INTEGER      -- For internal use only

);

 

buffer_too_small               EXCEPTION;  -- Buffer is too small for I/O

end_of_input                   EXCEPTION;  -- End of input from connection

network_error                  EXCEPTION;  -- Network error

bad_argument                   EXCEPTION;  -- Bad argument passed in API call

partial_multibyte_char         EXCEPTION;  -- A partial multi-byte char found

transfer_timeout               EXCEPTION;  -- Transfer time-out occurred

network_access_denied          EXCEPTION;  -- Network access denied

buffer_too_small_errcode       CONSTANT PLS_INTEGER:= -29258;

end_of_input_errcode           CONSTANT PLS_INTEGER:= -29259;

network_error_errcode          CONSTANT PLS_INTEGER:= -29260;

bad_argument_errcode           CONSTANT PLS_INTEGER:= -29261;

partial_multibyte_char_errcode CONSTANT PLS_INTEGER:= -29275;

transfer_timeout_errcode       CONSTANT PLS_INTEGER:= -29276;

network_access_denied_errcode  CONSTANT PLS_INTEGER:= -24247;

 

Close_data is a function that determines the number of bytes available for consumption from a TCP/IP connection and returns a pls_integer.

 

Argument

Type

In / Out

Default Value

C

UTL_TCP.CONNECTION

IN | OUT

 

TIMEOUT

PLS_INTEGER

IN

0

Table 6.157:  Close_data Parameters

Close_all_connections is a procedure that simply closes all the open TCP/IP connections. It takes no parameters.

 

Close_connection is a procedure that closes the specified open TCP/IP connection.

 

Argument

Type

In / Out

Default Value

C

UTL_TCP.CONNECTION

IN | OUT

 

Table 6.158:  Close_connection Parameter

Flush is a procedure that immediately transmits any and all data in the output buffer.

 

Argument

Type

In / Out

Default Value

C

UTL_TCP.CONNECTION

IN | OUT

 

Table 6.159:  Flush Parameters

Get_line is a function that reads a line of data and returns a VARCHAR2. The peek parameter allows one to look ahead in the buffer without actually consuming the message.

 

Argument

Type

In / Out

Default Value

C

UTL_TCP.CONNECTION

IN | OUT

 

REMOVE_CRLF

BOOLEAN

IN

FALSE

PEEK

BOOLEAN

IN

FALSE

Table 6.160:  Get_line Parameters

Get_line_nchar is a function that reads a line of data, and returns a NVARCHAR2. The peek parameter allows one to look ahead in the buffer without actually consuming the message.

 

Argument

Type

In / Out

Default Value

C

UTL_TCP.CONNECTION

IN | OUT

 

REMOVE_CRLF

BOOLEAN

IN

FALSE

PEEK

BOOLEAN

IN

FALSE

Table 6.161:  Get_line_nchar Parameters


 

 

  
 

 
 
 
 
Oracle performance tuning software
 
 

 

 
 
 
Oracle performance Tuning 10g reference poster
 
 
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2012 

All rights reserved.

Oracle © is the registered trademark of Oracle Corporation.