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

visibility 54 access_time 25 days ago languageEnglish timeline Stats
timeline Stats
Page index 2.12
more_horiz

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
copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

More from Kontext
Spark SQL - Average (AVG) Calculation
visibility 350
thumb_up 0
access_time 10 months ago
Spark SQL - PIVOT Clause
visibility 1,674
thumb_up 1
access_time 2 years ago
Spark SQL - Convert Object to JSON String
visibility 2,465
thumb_up 0
access_time 2 years ago