Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 10-20-2004, 11:54 PM sql query
starsunited's Avatar
Extreme Talker

Posts: 211
Location: Singapore
Trades: 0
hmm...

my colleague ask me for help but i do not know too but i'm eager to know as well.

the question is this: example there is a column postal which consists of postal codes from many countries and the user needed to differentiate Singapore from other countries according to the postal code. As you all know, the postal code is different for Singapore because it have six numbers and other countries might have 4 or 5.

Therefore within each postal code value, is there any possible way to count the how many numbers it have?
__________________

Please login or register to view this content. Registration is FREE
starsunited is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-21-2004, 12:06 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
starsunited,

Try this:

Code:
SELECT * FROM sometable WHERE LENGTH(postal) = 6
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 10-21-2004, 12:09 AM
starsunited's Avatar
Extreme Talker

Posts: 211
Location: Singapore
Trades: 0
but then it's not a fixed number

so can it be like select character_length(postal) from table;?
i check the manual then the character_length is only for strings? will it wrk for numbers as well?

the Length function is used for all characters regardless whether it's numbers or strings?
__________________

Please login or register to view this content. Registration is FREE
starsunited is offline
Reply With Quote
View Public Profile
 
Old 10-21-2004, 12:11 AM
starsunited's Avatar
Extreme Talker

Posts: 211
Location: Singapore
Trades: 0
so if its numbers?

this sql query is logical?

select length(to_char(postal)) from table;
__________________

Please login or register to view this content. Registration is FREE

Last edited by starsunited; 10-21-2004 at 12:18 AM..
starsunited is offline
Reply With Quote
View Public Profile
 
Old 10-21-2004, 12:52 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Quote:
Originally Posted by starsunited
but then it's not a fixed number

so can it be like select character_length(postal) from table;?
i check the manual then the character_length is only for strings? will it wrk for numbers as well?

the Length function is used for all characters regardless whether it's numbers or strings?

As I said in the PM, I don't know what it is you are after now. Are you trying to pull all the records which meet a certain criteria (6-character postal codes)? Or are you trying to compute the length for a value in a given column? And if so, do you want to return all the rows in the table or just one?

Give me a very specific narrative of what is in the column and what it is you want out of your query.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 10-21-2004, 12:55 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Quote:
Originally Posted by starsunited
so if its numbers?

this sql query is logical?

select length(to_char(postal)) from table;

I just don't understand what you are trying to say here. Try to expand your descriptions more and use a more complete description.

As for this query, you will end up with all the rows returned from the table because you have no WHERE clause. The values returned will only be a function of the data in the postal column rather than the data itself.

So say your single-column table looks like this:


postal
-------
21817
21878
CD4EJC
3892999


The values returned from the query you suggest will probably look something like this:

-------
5
5
6
7
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 10-21-2004, 09:34 PM
starsunited's Avatar
Extreme Talker

Posts: 211
Location: Singapore
Trades: 0
that's precisely what i want to do but thanks anyway to show an example output from my query
__________________

Please login or register to view this content. Registration is FREE
starsunited is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to sql query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.63359 seconds with 12 queries