User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Oracle section within the Web Development category of DaniWeb, a massive community of 455,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,746 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Oracle advertiser: Programming Forums
Views: 1754 | Replies: 2
Reply
Join Date: Nov 2007
Posts: 1
Reputation: KiltedScot is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
KiltedScot KiltedScot is offline Offline
Newbie Poster

Compare subparts of a field over multiple rows

  #1  
Nov 23rd, 2007
OK, I'm fairly new to PL/SQL, adn I have a query to write, which is confusing me. Let me explain:

I have a table, with three fields, CustID, CustName, Number

What I want to do, is identify and display all rows in the table, where the last four digits of the Number field match. So, for example, if teh table contained the following:

CustID CustName Number
-------- ----------- ---------
1 Brown 12345678
2 Smith 23456789
3 Jones 23445678
4 Davies 90908989
5 Royle 56231490

I would want the query to display:

CustID CustName Number
-------- ----------- ---------
1 Brown 12345678
3 Jones 23445678

As I say, I'm fairly new to PL/SQL, and so I'm hoping that someone will be able to explain it very simply to me.

Many thanks

KiltedScot
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Posts: 51
Reputation: Nige Ridd is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
Nige Ridd Nige Ridd is offline Offline
Junior Poster in Training

Re: Compare subparts of a field over multiple rows

  #2  
Nov 23rd, 2007
That can be solved using SQL, which is always preferable to use rather than PL/SQL if you can. The following would give you the results, there may be better solutions but as it's not too horrendous I thought it should be OK.

select custid, custname, custnumber
from testtable
where mod(custnumber, 10000) in ( select mod(custnumber, 10000 )
from testtable
group by mod(custnumber, 10000 )
having count ( mod(custnumber, 10000 ) ) > 1 ) ;

You may have to change some of the column or table names, but hopefully it's OK.

Nigel
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,444
Reputation: debasisdas is on a distinguished road 
Rep Power: 4
Solved Threads: 87
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Nearly a Posting Virtuoso

Re: Compare subparts of a field over multiple rows

  #3  
Nov 26th, 2007
For this no need of writing any PL / SQL at all . simmply try to use like search . try the sample code

  1. select * from customer where cust_number like '%5678'

Again are you sure the field name is number ? It is a reserved key word . Try to avoid that as a field name.
Last edited by debasisdas : Nov 26th, 2007 at 11:37 am.
Share your Knowledge.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Oracle Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Oracle Forum

All times are GMT -4. The time now is 9:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC