List:General Discussion« Previous MessageNext Message »
From:Yimin Rong Date:December 5 2008 4:19pm
Subject:Flexible way to convert?
View as plain text  
Greetings,

Please see following sample code and result. Note that x is cast properly but y isn't.
(FYI 0x913386aa3cbbab5a == 10462854425033288538)

Is there a way in MySQL to convert strings to numbers such that it recognizes decimal,
hex, and optionally other bases? I'm thinking of something like strtol in C/C++.

DELIMITER //
CREATE PROCEDURE GetXY()
BEGIN
    DECLARE x BIGINT UNSIGNED;
    DECLARE y BIGINT UNSIGNED;

    SET x = '10462854425033288538';
    SET y = '0x913386aa3cbbab5a';

    SELECT x, y;
END
//
DELIMITER ;

mysql> call GetXY();
+----------------------+---+
| x                    | y |
+----------------------+---+
| 10462854425033288538 | 0 |
+----------------------+---+

Thank you for reading.

Regards,

YR




      __________________________________________________________________
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites.
Download it now at
http://ca.toolbar.yahoo.com.
Thread
Flexible way to convert?Yimin Rong5 Dec