473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

huh? select * from table where integer = '1a' ....

Why does a select from table with an integer field return a row if I compare
the integer to an alpha character?

Here's the info ( a straight copy and paste), then compare my two select
statements:

mysql> desc product;
+------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| prd_id | int(11) | | PRI | 0 | |
| prd_name | varchar(30) | | | | |
| prd_short_desc | varchar(250) | YES | | NULL | |
| prd_long_desc1 | text | YES | | NULL | |
| prd_long_desc2 | text | YES | | NULL | |
| prd_long_desc3 | text | YES | | NULL | |
| prd_thumb | varchar(250) | YES | | NULL | |
| prd_full_image | varchar(250) | YES | | NULL | |
| prd_price | decimal(8,2) | YES | | NULL | |
| prd_custom1 | varchar(10) | YES | | NULL | |
| prd_custom2 | varchar(10) | YES | | NULL | |
| prd_start_date | date | YES | | NULL | |
| prd_end_date | date | YES | | NULL | |
| prd_instock | int(11) | | | 0 | |
| prd_search_words | text | YES | | NULL | |
+------------------+--------------+------+-----+---------+-------+
15 rows in set (0.00 sec)

mysql> select prd_id from product where prd_id = 33;
+--------+
| prd_id |
+--------+
| 33 |
+--------+
1 row in set (0.01 sec)

mysql> select prd_id from product where prd_id = '33a';
+--------+
| prd_id |
+--------+
| 33 |
+--------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 3.23.32 |
+-----------+
1 row in set (0.00 sec)

mysql>
notice that
select prd_id from product where prd_id = 33;
and
select prd_id from product where prd_id = '33a';
both reutrun a row, the same row actually!

I noticed that this returns nothing:
select prd_id from product where prd_id = 'a33';

So 'What Gives?'

I can't seem to track down any info about this so any insight would be
great.
(please notice that my version is 3.23.32)

Thanks in advandce
JohnL

Jul 19 '05 #1
8 3897
"John" <dsklfjhsdk> wrote in message
news:vt************@corp.supernews.com...
Why does a select from table with an integer field return a row if I compare the integer to an alpha character?

notice that
select prd_id from product where prd_id = 33;
and
select prd_id from product where prd_id = '33a';
both reutrun a row, the same row actually!

I noticed that this returns nothing:
select prd_id from product where prd_id = 'a33';

So 'What Gives?'

I can't seem to track down any info about this so any insight would be
great.
(please notice that my version is 3.23.32)

Thanks in advandce
JohnL

I would imagine it's a bug/feature of mysql that will truncate a number at
a character on input, in which case:

1) '33' = 33
2) '33a' = 33
3) 'a33' = nothing

try selecting something like this: select prd_id from product where prd_id =
'33a4';

and see what that gives you. Should just return 33 by my estimation.
Jul 19 '05 #2
"John" <dsklfjhsdk> wrote in message
news:vt************@corp.supernews.com...
Why does a select from table with an integer field return a row if I compare the integer to an alpha character?

notice that
select prd_id from product where prd_id = 33;
and
select prd_id from product where prd_id = '33a';
both reutrun a row, the same row actually!

I noticed that this returns nothing:
select prd_id from product where prd_id = 'a33';

So 'What Gives?'

I can't seem to track down any info about this so any insight would be
great.
(please notice that my version is 3.23.32)

Thanks in advandce
JohnL

I would imagine it's a bug/feature of mysql that will truncate a number at
a character on input, in which case:

1) '33' = 33
2) '33a' = 33
3) 'a33' = nothing

try selecting something like this: select prd_id from product where prd_id =
'33a4';

and see what that gives you. Should just return 33 by my estimation.
Jul 19 '05 #3
"SwissCheese" <Sw*********@cfl.rr.com> wrote in message
news:ZM*********************@twister.tampabay.rr.c om...
"John" <dsklfjhsdk> wrote in message
news:vt************@corp.supernews.com...
Why does a select from table with an integer field return a row if I compare
the integer to an alpha character?

notice that
select prd_id from product where prd_id = 33;
and
select prd_id from product where prd_id = '33a';
both reutrun a row, the same row actually!

I noticed that this returns nothing:
select prd_id from product where prd_id = 'a33';

So 'What Gives?'

I can't seem to track down any info about this so any insight would be
great.
(please notice that my version is 3.23.32)

Thanks in advandce
JohnL

I would imagine it's a bug/feature of mysql that will truncate a number

at a character on input, in which case:

1) '33' = 33
2) '33a' = 33
3) 'a33' = nothing

try selecting something like this: select prd_id from product where prd_id = '33a4';

and see what that gives you. Should just return 33 by my estimation.

That's partially correct. It's actually a feature of SQL in general. If SQL
is expecting a number and gets a letter, it drops everything after the
letter. Therefore:
33a = 33
a33 = nothing
3a3 = 3
Jul 19 '05 #4
Thanks for the replies.

sure enough in mysql '3a3' = 3

but in oracle it always fails on a 'non-number' character. (Oracle 8i)
Here's the output

SQL> select id from id_table where id = '6a7';
select plc_id from coop_placement where plc_id = '6a7'
*
ERROR at line 1:
ORA-01722: invalid number
I think I prefer getting an error in queries like this. Most of the time I
like it that mysql will take nearly any query and give it a shot, but in my
apps I'd rather it crapped out.

Thanks
JohnL
"Ryan Stewart" wrote in message news:fb********************@texas.net...
"SwissCheese" wrote in message
news:ZM*********************@twister.tampabay.rr.c om...
"John" <dsklfjhsdk> wrote in message
news:vt************@corp.supernews.com...
Why does a select from table with an integer field return a row if I compare
the integer to an alpha character?

notice that
select prd_id from product where prd_id = 33;
and
select prd_id from product where prd_id = '33a';
both reutrun a row, the same row actually!

I noticed that this returns nothing:
select prd_id from product where prd_id = 'a33';

So 'What Gives?'

I can't seem to track down any info about this so any insight would be
great.
(please notice that my version is 3.23.32)

Thanks in advandce
JohnL

I would imagine it's a bug/feature of mysql that will truncate a number

at
a character on input, in which case:

1) '33' = 33
2) '33a' = 33
3) 'a33' = nothing

try selecting something like this: select prd_id from product where

prd_id =
'33a4';

and see what that gives you. Should just return 33 by my estimation.
That's partially correct. It's actually a feature of SQL in general. If

SQL is expecting a number and gets a letter, it drops everything after the
letter. Therefore:
33a = 33
a33 = nothing
3a3 = 3

Jul 19 '05 #5
"John" <dsklfjhsdk> wrote in message
news:vu************@corp.supernews.com...
Thanks for the replies.

sure enough in mysql '3a3' = 3

but in oracle it always fails on a 'non-number' character. (Oracle 8i)
Here's the output

SQL> select id from id_table where id = '6a7';
select plc_id from coop_placement where plc_id = '6a7'
*
ERROR at line 1:
ORA-01722: invalid number
I think I prefer getting an error in queries like this. Most of the time I like it that mysql will take nearly any query and give it a shot, but in my apps I'd rather it crapped out.

Thanks
JohnL


I think you might need to start validating some variables before sending
your queries to the database...
Jul 19 '05 #6
"SwissCheese" <Sw*********@cfl.rr.com> wrote in message
news:ZM*********************@twister.tampabay.rr.c om...
"John" <dsklfjhsdk> wrote in message
news:vt************@corp.supernews.com...
Why does a select from table with an integer field return a row if I compare
the integer to an alpha character?

notice that
select prd_id from product where prd_id = 33;
and
select prd_id from product where prd_id = '33a';
both reutrun a row, the same row actually!

I noticed that this returns nothing:
select prd_id from product where prd_id = 'a33';

So 'What Gives?'

I can't seem to track down any info about this so any insight would be
great.
(please notice that my version is 3.23.32)

Thanks in advandce
JohnL

I would imagine it's a bug/feature of mysql that will truncate a number

at a character on input, in which case:

1) '33' = 33
2) '33a' = 33
3) 'a33' = nothing

try selecting something like this: select prd_id from product where prd_id = '33a4';

and see what that gives you. Should just return 33 by my estimation.

That's partially correct. It's actually a feature of SQL in general. If SQL
is expecting a number and gets a letter, it drops everything after the
letter. Therefore:
33a = 33
a33 = nothing
3a3 = 3
Jul 19 '05 #7
Thanks for the replies.

sure enough in mysql '3a3' = 3

but in oracle it always fails on a 'non-number' character. (Oracle 8i)
Here's the output

SQL> select id from id_table where id = '6a7';
select plc_id from coop_placement where plc_id = '6a7'
*
ERROR at line 1:
ORA-01722: invalid number
I think I prefer getting an error in queries like this. Most of the time I
like it that mysql will take nearly any query and give it a shot, but in my
apps I'd rather it crapped out.

Thanks
JohnL
"Ryan Stewart" wrote in message news:fb********************@texas.net...
"SwissCheese" wrote in message
news:ZM*********************@twister.tampabay.rr.c om...
"John" <dsklfjhsdk> wrote in message
news:vt************@corp.supernews.com...
Why does a select from table with an integer field return a row if I compare
the integer to an alpha character?

notice that
select prd_id from product where prd_id = 33;
and
select prd_id from product where prd_id = '33a';
both reutrun a row, the same row actually!

I noticed that this returns nothing:
select prd_id from product where prd_id = 'a33';

So 'What Gives?'

I can't seem to track down any info about this so any insight would be
great.
(please notice that my version is 3.23.32)

Thanks in advandce
JohnL

I would imagine it's a bug/feature of mysql that will truncate a number

at
a character on input, in which case:

1) '33' = 33
2) '33a' = 33
3) 'a33' = nothing

try selecting something like this: select prd_id from product where

prd_id =
'33a4';

and see what that gives you. Should just return 33 by my estimation.
That's partially correct. It's actually a feature of SQL in general. If

SQL is expecting a number and gets a letter, it drops everything after the
letter. Therefore:
33a = 33
a33 = nothing
3a3 = 3

Jul 19 '05 #8
"John" <dsklfjhsdk> wrote in message
news:vu************@corp.supernews.com...
Thanks for the replies.

sure enough in mysql '3a3' = 3

but in oracle it always fails on a 'non-number' character. (Oracle 8i)
Here's the output

SQL> select id from id_table where id = '6a7';
select plc_id from coop_placement where plc_id = '6a7'
*
ERROR at line 1:
ORA-01722: invalid number
I think I prefer getting an error in queries like this. Most of the time I like it that mysql will take nearly any query and give it a shot, but in my apps I'd rather it crapped out.

Thanks
JohnL


I think you might need to start validating some variables before sending
your queries to the database...
Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Landers, Jason | last post by:
I have two tables, meetings and tasks. In the meetings table I have meeting information and a meeting index called id. In the tasks table I have task information that is associated with various...
0
by: John | last post by:
Why does a select from table with an integer field return a row if I compare the integer to an alpha character? Here's the info ( a straight copy and paste), then compare my two select...
1
by: Sam G | last post by:
Hi folks, What I'd like to do for a website I'm designing with PHP/MySQL is have a number of registered users who can make friends with each other... so if person 1 wants to be friends with...
1
by: Michael | last post by:
I have a table that has the following fields: tblECHECK ID (autonumber identity column) PTID Batchnum Page DataPoint DPValue
3
by: Carmen Gloria Sepulveda Dedes | last post by:
Hello. When I run the next query: SELECT DATE_TRUNC('hour', TL.TAL005_DATE), TL.SRV_ID, TL.MSU_NUMBER, DS.DESCRIPTION, DS.CALLTYPE, COUNT(*) FROM OWNER_CATALOG.TAL005 TL,...
2
by: lbbs | last post by:
every time I open my table and want to print I have to go to printer setup to chance it to landscape and to change the margin size. Can you save those settings?
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
1
by: bughunter | last post by:
simple query select * from "Result" res where (res."QID" = 51541 or res."QID" = 51542) works fine ("SRV-BL"."Result" ~ 900000 rows) and returns 36 rows but update - no! update...
14
by: lewindletter | last post by:
Hi If I do Begin transaction Stmt 1: select count(*) from tableA If the count is zero, then proceed to the following Stmt 2: insert "something" to tableA Stmt 3: insert "something" to...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.