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');
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
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