Solved

SQL - Query Location table where ADDR1 have duplicated values

Posted on 2013-06-19
3
547 Views
Last Modified: 2013-06-19
Hello all

I'm trying to extract from my LOCATION table all locations that have duplicated values in column ADDR1 field but using the SQL below.

But i have this error: ORA-00933: SQL command not properly ended

How can i fix this?

Thanks again for your help.


SELECT CNT, 
    'L' AS L,
         'M' AS M,
         ID,
         DECODE (LOC_TYPE_ID,
                 0,
                 'PLAN',
                 1,
                 'CUSTOMER',
                 2,
                 'VENDOR',
                 3,
                 'DIST',
                 5,
                 'CROSSDOCK')
            AS LOC_TYPE_ID,
         NAME,
         ADDR1,
         ADDR2,
         CITY,
         STATE,
         COUNTRY,
         ZIP,
         CONTACT,
         PHONE,
         PHONE_SPD,
         FAX,
         LATITUDE,
         LONGITUDE,
         ZONE,
         PU_STOPTM,
         DEL_STOPTM,
         APPOINTMENT_REQUIRED,
         TIME_ZONE_ID,
         LOAD_CLASS_ID,
         CONSOLIDATION_ALLOWED,
         PARCEL_SERVICE,
         LOCATION_GROUP,
         MAX_CROSSDOCK_DAYS,
         PARCEL_CARRIER,
         ALT_LOCATION_ID,
         LOC_ROUTING_CLASS_ID,
         PICK_SRV_CLASS_ID,
         DELV_SRV_CLASS_ID,
         SPLC,
         APPOINTMENT_HONORED,
         SPLIT_WEIGHT,
         SPLIT_CUBE,
         SPLIT_PALLET,
         SPLIT_PIECES,
         SET_ID,
         SHIP_PRIORITY_ID,
         EMAIL,
         TRADE_AREA,
         SCNALIAS,
         XDOCK_HANDLING_TIME,
         SHPPTY,
         XDOCK_LIVE_LOADING,
         OWNER,
         PORT_CODE,
         NOTES
  FROM   LOCATION
(
SELECT COUNT(*) CNT,
    ADDR1
FROM 
      LOCATION
-GROUP BY ADDR1
HAVING COUNT > 1; 

Open in new window

0
Comment
Question by:Wilder1626
3 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 39259556
The syntax error is due to a missing ')'

Try this one:
select * from 
(
SELECT CNT, 
    'L' AS L,
         'M' AS M,
         ID,
         DECODE (LOC_TYPE_ID,
                 0,
                 'PLAN',
                 1,
                 'CUSTOMER',
                 2,
                 'VENDOR',
                 3,
                 'DIST',
                 5,
                 'CROSSDOCK')
            AS LOC_TYPE_ID,
         NAME,
         ADDR1,
         ADDR2,
         CITY,
         STATE,
         COUNTRY,
         ZIP,
         CONTACT,
         PHONE,
         PHONE_SPD,
         FAX,
         LATITUDE,
         LONGITUDE,
         ZONE,
         PU_STOPTM,
         DEL_STOPTM,
         APPOINTMENT_REQUIRED,
         TIME_ZONE_ID,
         LOAD_CLASS_ID,
         CONSOLIDATION_ALLOWED,
         PARCEL_SERVICE,
         LOCATION_GROUP,
         MAX_CROSSDOCK_DAYS,
         PARCEL_CARRIER,
         ALT_LOCATION_ID,
         LOC_ROUTING_CLASS_ID,
         PICK_SRV_CLASS_ID,
         DELV_SRV_CLASS_ID,
         SPLC,
         APPOINTMENT_HONORED,
         SPLIT_WEIGHT,
         SPLIT_CUBE,
         SPLIT_PALLET,
         SPLIT_PIECES,
         SET_ID,
         SHIP_PRIORITY_ID,
         EMAIL,
         TRADE_AREA,
         SCNALIAS,
         XDOCK_HANDLING_TIME,
         SHPPTY,
         XDOCK_LIVE_LOADING,
         OWNER,
         PORT_CODE,
         NOTES,
	count(*) over(partition by addr1 order by addr1) addr1_count
  FROM   LOCATION
)
where addr1_count > 1
; 

Open in new window

0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
ID: 39259558
Select
....
from Location join (
SELECT COUNT(*) CNT,
    ADDR1
FROM 
      LOCATION
GROUP BY ADDR1
HAVING COUNT > 1) cnt
on location.addr1 = cnt.addr1;

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39260252
Many thanks, now it work great
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

820 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