10

I'm new to MySql. So I don't know many things like Casting of data types. How can I convert bool to int in MySql. And also how can I convert decimal to Int in MySql.

2
  • do you want to change datatype of columns ?? Commented Jun 7, 2011 at 4:56
  • @NAVEED : I want to cast the Bool type to Int for ex: DECLARE bo BOOL; SET bo = TRUE; SELECT CAST(bo AS INT); Commented Jun 7, 2011 at 5:05

1 Answer 1

15

Typecasting boolean to integer:

SELECT CAST(1=1 AS SIGNED INTEGER); /* 1 */

Same for decimal and strings:

SELECT CAST("1.23" AS SIGNED INTEGER); /* 1 */
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.