Solved

help on to_clob function

Posted on 2014-12-31
5
259 Views
Last Modified: 2015-01-03
Hi ,

I have an table called comments which has an column called comment . In the query , I need to check whether any comment is present for an product , if present show the comment else display 'N/A'. Below is the table structure and the query written. Need an alternative to the usage of to_clob function in the query

Table Structure
Product Table:

Product_id number ,
place_id number,
customer_id number,
prod_desc varchar2(400)

Comments Table
Comment_id number,
comments clob,
product_id number,
customer1_id number,
customer2_id number,
customer3_id number

Data


Product table :
Product_id     place_id     customer_id  prod_desc
1                         10              1                      abc
2                          12             2                      cvb
3                           13            3                        sdsd
 
Comments:
Comment_id    comments  product_id  customer1_id customer2_id  customer3_id
1                           asdasd           1                      1               null                          null
2                            asdasdas         3                      null             2                           null



Select
p.product_id,
p.prod_desc,
nvl2(com.comment_id,com.comments,to_clob('N/A') comments
,comment_id,

from product p left outer join comments com on (com.product_id=p.product_id and p.customer_id in (com.customer1_id, com.customer2_id, com.customer3_id)

Output :
product_id                  prod_desc                                       comments    comment_id
1                                        abc                                                  asdasd             1
2                                            cvb                                                N/A                  NULL
3                                          sdsd                                                 N/A                 NULL

The issue is the query takes an long time because of the to_clob('N/A') function used. Is there an alternative , with out using the to_clob function , so as to improve the performance of the query.
0
Comment
Question by:sam_2012
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40525775
You can remove the "TO_CLOB" and just use 'N/A'
;)
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40526079
>>The issue is the query takes an long time because of the to_clob('N/A') function used

What makes you think to_clob is the reason?

Please post the execution plan.
0
 

Author Comment

by:sam_2012
ID: 40526437
I checked , the execution plan says , all the indexes are used , but when I remove the to_clob ('N/A') code  and display only comments , it takes only 5 milli secs. But when I include the to_clob('N/A') code it takes around 10 secs which is not meeting the sla.

Also , If i remove to_clob('N/A') and add only 'N/A' getting an error like below
got clob when expected error.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40526796
>>got clob when expected error.

What is your exact version of Oracle?

I just set up a test case using your samples and after correcting the syntax errors with the select, it runs just fine on my 11.2.0.3.

--drop table product purge;
create table product(
Product_id number ,
place_id number,
customer_id number,
prod_desc varchar2(400)
);

--drop table comments purge;
create table comments(
Comment_id number,
comments clob,
product_id number,
customer1_id number,
customer2_id number,
customer3_id number
);


insert into product values(1,10,1,'abc');
insert into product values(2,12,2,'cvb');
insert into product values(3,13,3,'sdsd');
 
insert into comments values(1,'asdasd',1,1,null,null);
insert into comments values(2,'asdasdas',3,null,2,null);
commit;


Select
p.product_id,
p.prod_desc,
nvl2(com.comment_id,com.comments,'N/A') comments
,comment_id
from product p left outer join comments com on com.product_id=p.product_id and p.customer_id in (com.customer1_id, com.customer2_id, com.customer3_id)
/

Open in new window

0
 

Author Closing Comment

by:sam_2012
ID: 40529881
awesome.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to take different types of Oracle backups using RMAN.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now