Showing posts with label Oracle. Show all posts
Showing posts with label Oracle. Show all posts

Thursday, February 16, 2012

Oracle Writing multi lingual characters with Oracle file IO

If you have multi lingual characters like chinese to be written in a file or excel sheet from tables, using orcale file IO, It requires UTF-8 conversion. Just convert the character to UTF8 and write it. I tried using the utl_file.put raw, but i failed. When i used the below, it was working fine for me.
 l_file_handle:= utl_file.fopen('D:\',test.csv','W');
utl_file.put_line(l_file_handle,convert(l_str_head1,'UTF8'),TRUE);

Oracle - Alternative to between operator

When your query has joins to multiple table, and also you need a date operation to be carried with between operator. Hope you need to compromise on the query performance. An alternative way is to use subquery and in operator instead. Consider the below query with between operator
select A.a,A.a1,A.a2,B.b3,B.b4,C.c5 from TableA A
inner join TableB B on A.a1=B.a1
inner join Table C on c.c1=B.c1
where A.a3 between '10-May-01' AND '10-May-05'.
The above query takes around 65 seconds in my Sql explorer. An alternative to the query above is shown below
select A.a,A.a1,A.a2,B.b3,B.b4,C.c5 from TableA A
inner join TableB B on A.a1=B.a1
inner join Table C on c.c1=B.c1
where A.a3 in (select A.a3 from TABLEA where A.a3 between '10-May-01' AND '10-May-05')
Just a change in the where clause with sub query improves the query performance, and the query took just 1.14 secs.
I faced this situation and thought it will be of help to share it. Execuse me if I am wrong or if it is worthless to take your time. I am just a starter with oracle database. :)