Simple guide to open Socket Connection using Oracle PL SQL Programming

A socket is used to communicate between two programs. Socket forms one endpoint of a two-way communication link between the programs. 

In this article we will see an example of  how to open a socket using PL SQL programming . We will also see how to read and write from the socket.

Oracle is more than database. You can write a complex business logic that can do core work for your organization using Oracle PL SQL Programming

Tools Used

  • Oracle Express Edition
  • Java 1.8
  • Eclipse IDE

For this example we will use Oracle UTL_TCP package. UTL_TCP package will help to communicate with external servers using TCP/IP.

In order to use UTL_TCP, first we need to grant access to user before the PL SQL program is executed. For that below is the command you need to execute as system or sysdba user.

Here we have given all access to UTL_TCP. You can choose to give access to connect to only specific server and port.

Now lets see to our java program that will be our socket server. This server will listen for localhost or 127.0.0.1 on port 9898. The server will take input that is put on port in lower case. It will respond back with same input in upper case.

Now the mail Oracle PL SQL Programming unit –

Each block in above program is simple and clear. To execute this first run our java program. Once started it will keep on listening on the port 9898. After that copy and paste above code in sql developer and execute. You will see below output.Oracle PL SQL Programming

Hope above example helps you. Please get back to us if you have any question or need help in running above samples.

7 Comments
  1. mohsen
    March 3, 2020 | Reply
  2. RUMAIZ
    November 20, 2019 | Reply
    • Pavan
      November 27, 2019 | Reply
  3. September 5, 2019 | Reply
    • Shilpa
      September 8, 2019 | Reply
  4. John
    February 16, 2018 | Reply
    • Pavan
      February 16, 2018 | Reply

Add a Comment

Your email address will not be published. Required fields are marked *