Sathish, without seeing your data, we can't debug the Function.. so can u cook up some sample data out of your original data and post it in the form of INSERT INTO <Table> VALUES () statement ?
Also please provide the DDLs of the source table.. if u find it difficult on how to do that, please read thro the following article :