How to Convert From a String to a Number in MYSQL

MySQL has conversion functions that let you transfer from a string variable to an integer. The string must contain a number to properly convert, but you can then insert the converted integer variable into an integer table field. You must convert any string variable to an integer before you can insert a string to a table field designated as an integer.

Instructions

    • 1

      Click the Windows "Start" button and select "All Programs." Click "MySQL," then click "Query Browser" to open the MySQL coding interface.

    • 2

      Type the username and password used to access the MySQL database. In the drop-down box, select the MySQL database name and click "Log In."

    • 3

      Type the code to convert to an integer. The following code converts the string "123" to an integer value:

      set converted = select cast ('123' as int);

    • 4

      Add the converted integer to a field in the table. The following code inserts the converted integer to the "order_number" field in the "orders" table:

      insert into orders (customer, order_number) values (1, converted);

    • 5

      Click the "Execute" button in Query Browser to run the code. The software returns the number of rows affected by the query, which is only one insertion.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured