Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

output from select as hexidecimal?

15 views
Skip to first unread message

SpreadTooThin

unread,
Apr 10, 2013, 1:12:28 PM4/10/13
to

I am trying to use the conv() function to convert the output of a select statement into hex however it is giving me a syntax error.

mysql> select conv(15,10,16);
+----------------+
| conv(15,10,16) |
+----------------+
| F |
+----------------+
1 row in set (0.00 sec)

However if I change the 15 to a the column name I get a syntax error.

mysql> select conv(Col1, 10, 16);
ERROR 1064 (4200): You have an error in your SQL syntax;.....


Jerry Stuckle

unread,
Apr 10, 2013, 1:24:33 PM4/10/13
to
What's the whole message? Maybe like you're missing a FROM clause?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

SpreadTooThin

unread,
Apr 10, 2013, 1:29:40 PM4/10/13
to
mysql> describe StandardDicomDictionary;
+--------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| Description | varchar(64) | NO | PRI | NULL | |
| Group | int(10) unsigned | NO | | NULL | |
| Element | int(10) unsigned | NO | | NULL | |
| VR | varchar(2) | NO | | NULL | |
| Multiplicity | varchar(4) | NO | | NULL | |
+--------------+------------------+------+-----+---------+-------+
5 rows in set (0.39 sec)

select Description, conv(Group, 10, 16), conv(Element, 10, 16) from StandardDicomDictionary;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group, 10, 16), conv(Element, 10, 16) from StandardDicomDictionary' at line 1

SpreadTooThin

unread,
Apr 10, 2013, 1:55:11 PM4/10/13
to
It would appear that Group as a column name is a no no... so what now?

Erick T. Barkhuis

unread,
Apr 10, 2013, 2:21:52 PM4/10/13
to
SpreadTooThin:

>It would appear that Group as a column name is a no no... so what now?

Rename it to something like 'mygroup' or use backticks.



--
Erick

Jerry Stuckle

unread,
Apr 10, 2013, 4:03:47 PM4/10/13
to
On 4/10/2013 1:55 PM, SpreadTooThin wrote:
> It would appear that Group as a column name is a no no... so what now?
>

Group is a reserved word (GROUP BY ...). You can enclose the column
name in backticks, but that is not portable. I would recommend renaming
the column to a non-reserved word.

The Natural Philosopher

unread,
Apr 10, 2013, 6:45:35 PM4/10/13
to
On 10/04/13 18:55, SpreadTooThin wrote:
> It would appear that Group as a column name is a no no... so what now?
`group` i n bacticks will hack past having used a naughty reserved word
as a column

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.

Thomas 'PointedEars' Lahn

unread,
Apr 11, 2013, 11:23:06 AM4/11/13
to
SpreadTooThin wrote:
^^^^^^^^^^^^^
Who?
“GROUP” is a MySQL keyword (from “GROUP BY”); keywords are case-insensitive.
In order to avoid a name being considered a keyword, quote it with
backticks:

SELECT `Description`, conv(`Group`, 10, 16), conv(`Element`, 10, 16)
FROM `StandardDicomDictionary`;

It is strongly recommended to quote *all* names, because which words are
considered keywords depends on the MySQL version. So if you do not quote
names, a MySQL upgrade or a version difference between test and production
system could break your queries. You do not want that to happen.

--
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Jerry Stuckle

unread,
Apr 11, 2013, 12:38:23 PM4/11/13
to
No, only YOU recommend making the SQL non-compliant with the standards
by using backticks. But then you think MySQL is the only database in
the world, also.

Real programmers always take into consideration standards compliance
when coding. You never know when your code will have to run on another
database, for instance. That doesn't mean everything is always
compliant - but is non-compliant code is the exception, not the rule.

Thomas 'PointedEars' Lahn

unread,
Apr 11, 2013, 1:07:48 PM4/11/13
to
Jerry Stuckle wrote:

> On 4/11/2013 11:23 AM, Thomas 'PointedEars' Lahn wrote:
>> SpreadTooThin wrote:
>>> ERROR 1064 (42000): You have an error in your SQL syntax; check the
>>> manual that corresponds to your MySQL server version for the right
>>> syntax to use near 'Group, 10, 16), conv(Element, 10, 16) from
>>> StandardDicomDictionary' at line 1
>>
>> “GROUP” is a MySQL keyword (from “GROUP BY”); keywords are
>> case-insensitive. In order to avoid a name being considered a keyword,
>> quote it with backticks:
>>
>> SELECT `Description`, conv(`Group`, 10, 16), conv(`Element`, 10, 16)
>> FROM `StandardDicomDictionary`;
>>
>> It is strongly recommended to quote *all* names, because which words are
>> considered keywords depends on the MySQL version. So if you do not quote
>> names, a MySQL upgrade or a version difference between test and
>> production
>> system could break your queries. You do not want that to happen.
>
> No, only YOU recommend making the SQL non-compliant with the standards
> by using backticks.

*SQL* compliance (however you want to define that) is not an issue in a
*MySQL* query, see below. Besides:

<https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html>

(Also check the documentation for newer and earlier versions on this; you
may be surprised.)

> But then you think MySQL is the only database in the world, also.

How did you get that weird idea? I have been developing for and with Access
Jet SQL and MS SQL databases, *for example*. BTW, MySQL is a RDBMS with an
SQL-based programming language, not a database.

> Real programmers always take into consideration standards compliance
> when coding. You never know when your code will have to run on another
> database, for instance. That doesn't mean everything is always
> compliant - but is non-compliant code is the exception, not the rule.

SQL compliance is not an issue here as MySQL versions extend revisions of
the SQL standard, and you would never issue *raw* MySQL queries in a
software program. Well, *real* programmers would not, and do not.

Jerry Stuckle

unread,
Apr 11, 2013, 1:47:53 PM4/11/13
to
On 4/11/2013 1:07 PM, Thomas 'PointedEars' Lahn wrote:
> Jerry Stuckle wrote:
>
>> On 4/11/2013 11:23 AM, Thomas 'PointedEars' Lahn wrote:
>>> SpreadTooThin wrote:
>>>> ERROR 1064 (42000): You have an error in your SQL syntax; check the
>>>> manual that corresponds to your MySQL server version for the right
>>>> syntax to use near 'Group, 10, 16), conv(Element, 10, 16) from
>>>> StandardDicomDictionary' at line 1
>>>
>>> “GROUP” is a MySQL keyword (from “GROUP BY”); keywords are
>>> case-insensitive. In order to avoid a name being considered a keyword,
>>> quote it with backticks:
>>>
>>> SELECT `Description`, conv(`Group`, 10, 16), conv(`Element`, 10, 16)
>>> FROM `StandardDicomDictionary`;
>>>
>>> It is strongly recommended to quote *all* names, because which words are
>>> considered keywords depends on the MySQL version. So if you do not quote
>>> names, a MySQL upgrade or a version difference between test and
>>> production
>>> system could break your queries. You do not want that to happen.
>>
>> No, only YOU recommend making the SQL non-compliant with the standards
>> by using backticks.
>
> *SQL* compliance (however you want to define that) is not an issue in a
> *MySQL* query, see below. Besides:
>

Compliance with internationally accepted standards should ALWAYS be a
consideration by real programmers.

> <https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html>
>
> (Also check the documentation for newer and earlier versions on this; you
> may be surprised.)
>

So what? Look at the SQL standards.

>> But then you think MySQL is the only database in the world, also.
>
> How did you get that weird idea? I have been developing for and with Access
> Jet SQL and MS SQL databases, *for example*. BTW, MySQL is a RDBMS with an
> SQL-based programming language, not a database.
>

From your insistence on violating internationally accepted standards
for SQL programming.

>> Real programmers always take into consideration standards compliance
>> when coding. You never know when your code will have to run on another
>> database, for instance. That doesn't mean everything is always
>> compliant - but is non-compliant code is the exception, not the rule.
>
> SQL compliance is not an issue here as MySQL versions extend revisions of
> the SQL standard, and you would never issue *raw* MySQL queries in a
> software program. Well, *real* programmers would not, and do not.
>

Compliance with standards should ALWAYS be a consideration. And
programmers DO issue SQL queries within a program. In my case I have a
hierarchy of classes in both C++ and PHP (predating PDO). My SQL is as
close to the standard as possible. As a result, I can, by just changing
one class, change databases with little or no problem. I have classes
set up for MySQL, PostgreSQL, Oracle and DB2 (I don't do SQL server).

You'd be surprised how much you can do by staying within the standards.
0 new messages