[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Very interesting query which uses LONG datatype column in the query

Posted on 2006-05-11
9
Medium Priority
?
1,000 Views
Last Modified: 2008-02-01
Hi guys,

   Heres an interesting query.  This query uses a column which is of LONG datatype. The query works fine. But the query returns duplicate values. So I tried to use DISTINCT or GROUP BY to supress the duplicate values. it gives an error saying ILLEGAL USE OF LONG COLUMN.....

Heres the query:

select   alerts.ALERT_NAME, usr.USER_NAME,  action.SUBJECT,
alerts.ENABLED_FLAG, action.TO_RECIPIENTS, action.CC_RECIPIENTS,  alerts.SQL_STATEMENT_TEXT
from ALR_ACTIONS action, alr_alerts alerts, fnd_user usr
where   action.ALERT_ID = alerts.ALERT_ID
and alerts.LAST_UPDATED_BY = usr.USER_ID
and (alerts.LAST_UPDATE_DATE > trunc(sysdate) - 30 or  action.LAST_UPDATE_DATE > trunc(sysdate) - 30)

SQL_STATEMENT_TEXT is a LONG datatype.

Help Appreciated. How can i supress duplicates rows from this query.

Thanks


 
0
Comment
Question by:amankhan
  • 5
  • 4
9 Comments
 
LVL 19

Expert Comment

by:actonwang
ID: 16664705
LONG is depreciated by Oracle and is recommended to use CLOB instead.

LONG can store up to 2G(CLOB is to 4G). there can be only one LONG column and it CAN NOT appear in WHERE,GROUP BY or ORDER BY which is why you get "ILLEGAL USE OF LONG COLUMN".
0
 
LVL 19

Expert Comment

by:actonwang
ID: 16664727
also LONG can not be used in DISTINCT, MAX(...) etc. so you can see LONG is really discouranged here.
0
 
LVL 19

Assisted Solution

by:actonwang
actonwang earned 2000 total points
ID: 16664776
that being said, you have to "abandon" LONG column while you remove duplicate. if you assume that if other columns except  LONG column are same, then LONG column will also be the same, then you can create a query as this to remove duplicate:

select  ALERT_NAME, USER_NAME,  SUBJECT,ENABLED_FLAG, TO_RECIPIENTS, CC_RECIPIENTS, SQL_STATEMENT_TEXT,
from
(
select   alerts.ALERT_NAME, usr.USER_NAME,  action.SUBJECT,
alerts.ENABLED_FLAG, action.TO_RECIPIENTS, action.CC_RECIPIENTS, alerts.SQL_STATEMENT_TEXT,
row_number() over (partition by alerts.ALERT_NAME, usr.USER_NAME,  action.SUBJECT,alerts.ENABLED_FLAG, action.TO_RECIPIENTS, action.CC_RECIPIENTS order by alerts.ALERT_NAME) rn
from ALR_ACTIONS action, alr_alerts alerts, fnd_user usr
where   action.ALERT_ID = alerts.ALERT_ID
and alerts.LAST_UPDATED_BY = usr.USER_ID
and (alerts.LAST_UPDATE_DATE > trunc(sysdate) - 30 or  action.LAST_UPDATE_DATE > trunc(sysdate) - 30)
) t
where t.rn = 1
/

hope it helps :)
Acton
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:amankhan
ID: 16664811
But this is the standard oracle tables which we should not change.
0
 

Author Comment

by:amankhan
ID: 16664818
Ok kewl,

actonwong, i will try this and will let you know if i face any other problems..

thanks
0
 

Author Comment

by:amankhan
ID: 16674270
Hi actonwong,

I am getting an error saying that row_number() function not found. May be this function is included in oracle 8i and i think they are still using Oracle 7. So, how to implement this in other way.

Help Appreciated.

Thanks
0
 
LVL 19

Expert Comment

by:actonwang
ID: 16674354
use :

select * from v$version
/

to identify which oracle they are using.

Oracle 7?
0
 
LVL 19

Accepted Solution

by:
actonwang earned 2000 total points
ID: 16674518
Try this. This should be working even in Oracle 7



select   alerts.ALERT_NAME, usr.USER_NAME,  action.SUBJECT,
alerts.ENABLED_FLAG, action.TO_RECIPIENTS, action.CC_RECIPIENTS,  alerts.SQL_STATEMENT_TEXT
from ALR_ACTIONS action, alr_alerts alerts, fnd_user usr
where   action.ALERT_ID = alerts.ALERT_ID
and alerts.LAST_UPDATED_BY = usr.USER_ID
and (alerts.LAST_UPDATE_DATE > trunc(sysdate) - 30 or  action.LAST_UPDATE_DATE > trunc(sysdate) - 30)
and  action.rowid || alerts.rowid || usr.rowid  in
(
select max(id)
(
select   alerts.ALERT_NAME, usr.USER_NAME,  action.SUBJECT,
alerts.ENABLED_FLAG, action.TO_RECIPIENTS, action.CC_RECIPIENTS,
action.rowid || alerts.rowid || usr.rowid id
from ALR_ACTIONS action, alr_alerts alerts, fnd_user usr
where   action.ALERT_ID = alerts.ALERT_ID
and alerts.LAST_UPDATED_BY = usr.USER_ID
and (alerts.LAST_UPDATE_DATE > trunc(sysdate) - 30 or  action.LAST_UPDATE_DATE > trunc(sysdate) - 30)
) t
group by  ALERT_NAME,USER_NAME, SUBJECT,ENABLED_FLAG, TO_RECIPIENTS, CC_RECIPIENTS
)
/
0
 

Author Comment

by:amankhan
ID: 16687364
Awesome actonwon,

It worked perfect. Now i did come to know how to handle LONG columns while writing queries.

Thanks very much.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

873 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