Monday, March 10, 2014

How to handle Oracle CLOB variables efficiently

       

PROCEDURE Dummy (
   attr_   IN VARCHAR2 )
IS   
   xml_message_ CLOB;
   ...
BEGIN
   -- Initialize CLOB variable in the temp memory space
   IF ( NVL(DBMS_LOB.IsTemporary(xml_message_), 0) = 0 ) THEN                     
      DBMS_LOB.CreateTemporary(xml_message_, FALSE, DBMS_LOB.CALL);
   END IF;

   -- Business Logic

   -- Free the resource
   IF ( NVL(DBMS_LOB.IsTemporary(xml_message_), 0) = 1 ) THEN
      DBMS_LOB.FreeTemporary(xml_message_);
   END IF;

EXCEPTION
   WHEN OTHERS THEN
      
   -- Free the resource
   IF ( NVL(DBMS_LOB.IsTemporary(xml_message_), 0) = 1 ) THEN
      DBMS_LOB.FreeTemporary(xml_message_);
   END IF;

   RAISE;
END Dummy;

       
 

Important things to consider when using CLOBS.

* Once the CLOB variables are allocated in the memory, oracle will cleanup the resource once code block is completed. Therefore its not necessary to write the cleanup codes explicitly. But due to the bugs in the oracle database itself, if you haven't applied the latest patches, you might ended-up in memory leaks. So its always safe to write clenup codes but make sure to test the CLOB variable is not empty before calling the "DBMS_LOB.FreeTemporary(xml_message_);". Otherwise this will result in an exception.

Sunday, June 14, 2009

How to kill a not responding session in Oracle

Using SQL Plus

Sessions can be killed using 'ALTER SYSTEM KILL SESSION' command which are running within oracle.

First you need to identify the offending or not responding session using following SQL statement.
SELECT t.sid,
t.serial#,
t.username,
t.osuser,
t.program,
t.type
FROM v$session t;


After identifying the correct session it can be killed using following command. The 'SID' and 'SERIAL#' values of the relevant session should be substituted into the command:
ALTER SYSTEM KILL SESSION 'sid,serial#';

Ex:
SQL> ALTER SYSTEM KILL SESSION '140,428';

In some cases the Oracle.exe will not be able to kill the session
immediately. In such cases the session will be "marked for kill". It
will then be killed as soon as possible.

It is possible to force the kill by appending the 'IMMEDIATE' keyword,
SQL> ALTER SYSTEM KILL SESSION '140,428' IMMEDIATE;
Issuing the 'ALTER SYSTEM KILL SESSION' command is
the only safe way to kill an Oracle session. If the session which is marked
to kill persists for some time you may consider killing the process at the
operating system level. Killing OS processes
is dangerous and can lead to instant failures or unexpected results, so do this at your own will.



Thursday, June 5, 2008

Anonymous communication Over The Internet

In the modern economic world purchasing products from online stores is rapidly increasing. On the other hand cyber criminals who steal personal information and tracking online activities are also increasing. Hence people need to be more careful when exposing or giving out any personal information about them. Therefore a reliable anonymous communication system on internet is very crucial.

Anonymous communication means communicating without revealing their identity to each other or to an outside observer. Here, the communication maybe carried out over the general telephone network or the Mobile Phone network or the Internet. Many researchers have proposed solutions for achieving anonymous communication over these types of communication methods. But in this review I’m considering only about anonymous communication on Internet.

In the context of anonymous communication we first need to understand what is meant by “Anonymity” and “Unobservability”. As discussed in [Pftzmann and Waidner 1987], the anonymity is “the state of not being identifiable within a set of subjects”. There are three anonymity levels,

Anonymous Communication Systems

Follwing Systems can be used to communicate via the Internet Anonymously.

1. Web proxies
2. Mix-nets
3. Onion Routing
4. Tor Network
5. Crowds

Tuesday, February 5, 2008

Creating RPC Application

RPC stands for Remote Procedure Call which allows heterogeneous applications to communicate over a Network.

RPC can be used to communicate java applications with c++ applications. Netbula ORPC is a rich framework which allows to develop RPC applications.

First thing you need to do is creating an IDL(Interface Definition Language) file and compile it using an IDL compiler. Netbula's jrpcgen.exe is an IDL compiler which generates necessary java source codes to begin RPC application. It generate three code files:-

Interface
Server skeleton
Client stub

Here is a sample RPC IDL file.

struct cardStruct{
string cardName<>;
int cardWeight;
boolean status;
int id;
};

struct stringStruct{
string sName<>;
};

struct sArray{
stringStruct cardSet[13];

};

struct playStruct{
int cId;
cardStruct cStruct;
};

program HEARTSERV {

version HEARTSERV_V1 {

int getConnect(String)=1;
int winScore(void)=6;
sArray getCards(int)=4;
sArray getCurrentCards(void)=2;
sArray getScore(void)=3;
sArray playCards(playStruct)=5;

} = 0;

} = 1234567;

You can start building your RPC application by extending the server skeleton in server application. In client application you just need to create an instance of the client stub and call methods in that object.

When you need to run the application first thing you need to do is run the portmapper deamon which registers the processes with method names. Then run the server application and finally client application.
It's easy isn't it?