•
•
•
•
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
![]() |
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
Join Date: Nov 2007
Posts: 51
Reputation:
Rep Power: 1
Solved Threads: 9
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
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
•
•
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,444
Reputation:
Rep Power: 4
Solved Threads: 87
For this no need of writing any PL / SQL at all . simmply try to use like search . try the sample code
Again are you sure the field name is number ? It is a reserved key word . Try to avoid that as a field name.
oracle Syntax (Toggle Plain Text)
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Oracle Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- insert multiple rows in database (MS SQL)
- Store multiple selection from pagination info into single array (PHP)
- How to store multiple selection? (VB.NET)
- while() not looping... (PHP)
- updating multiple rows with one form (PHP)
- multiple row update (C#)
- String search in a file compare? (Computer Science and Software Design)
Other Threads in the Oracle Forum
- Previous Thread: Create a view as superuser
- Next Thread: SQL Script help



Linear Mode