Last answered:

05 Oct 2022

Posted on:

04 Oct 2022

0

Resolved: how to convert columns from char to int types

Hi - I notice that the departments column dept_no is a char type, so the range of 'd003' to 'd006' cannot be calculated since they are string values. Is there a way to change the column to a int type? or would pattern matching be more appropriate here? e.g.:

SELECT dept_name FROM departments WHERE dept_no IN ('d003', 'd004', 'd005', 'd006');
2 answers ( 1 marked as helpful)
Posted on:

04 Oct 2022

2

Hello Larysha,

SQL doesn't allow any letters inside an INT data type. If you want the dept_no field to be "like" an integer, you can use the combination of wildcards and the REGEXP_LIKE for pattern matching, like so:

SELECT *
FROM departments
WHERE REGEXP_LIKE(dept_no, '[3-6]');



Kind regards,
Carl

Instructor
Posted on:

05 Oct 2022

0

Hi Larysha and Carl!
Thanks for reaching out.

@: Carl
Thanks for sharing this piece of information with the Community!

@: Larysha
Carl explained it very well. SQL doesn't allow any letters inside an INT data type. So, you can use it either as CHAR or with some values of INT type.

Hope this helps.
Best,
Tsvetelin

Submit an answer