Oracle PL SQL Programming – Socket Connection

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

In this article we will see an example of pl sql programming which will show us how to open a socket. We will also see how to read and write from the socket.

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 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.

Add a Comment

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