Spark SQL - Convert String to Int (int and cast function)

Kontext Kontext 0 9573 8.52 index 6/4/2022

In Spark SQL, we can use int and cast function to covert string to integer.

Use int function

The following code snippet converts string to integer using int function.

spark-sql> SELECT int('2022');
CAST(2022 AS INT)
2022

Use cast function

The following example utilizes cast function.

spark-sql> SELECT cast('2022' as int);
CAST(2022 AS INT)
2022
spark-sql

Join the Discussion

View or add your thoughts below

Comments