SERPland Blog

SQL: Remove Strings or Letters

· 383 words · 2 minutes to read

Remove:

select TRANSLATE(‘12A3’,‘0123456789’, ’ ‘) FROM dual

or

select LTRIM(RTRIM(TRANSLATE(UPPER(‘12a’), ABCDEFGHIJKLMNOPQRSTUVWXYZ’, ’ ‘))) as nr , LTRIM(RTRIM(TRANSLATE(UPPER(‘12a’),‘0123456789’, ’ ‘))) as nr_add from dual

Investigate:

declare v1 VARCHAR2(200):= ’ ’ || CHR(10); begin dbms_output.put_line(’————————- ‘); dbms_output.put_line(TRANSLATE(v1 , ‘1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ ’ ,’#####################################’)); dbms_output.put_line( TRANSLATE(v1, ’ ‘, ‘#’)); IF TRANSLATE(v1 ,‘1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ ’ ,’#####################################’) = TRANSLATE(v1, ’ ‘, ‘#’) THEN dbms_output.put_line(‘Only blanks ‘); ELSE dbms_output.put_line(‘Not only blanks’); END IF; END;

Or use some regular expressions (with oracle 10g)


Update 2024

Update on SQL Remove Strings or Letters 🔗

The information provided in 2011 regarding SQL functions to remove strings or letters from a VARCHAR column in Oracle databases is still valid in the years 2021 to 2024.

To recap, the original text mentioned using functions like LTRIM, RTRIM, TRANSLATE, and regular expressions to achieve the desired outcome. These functions are indeed still relevant and commonly used in SQL queries for data manipulation.

In the current year of 2024, Oracle database users continue to leverage these functions for various data cleansing and transformation tasks. SQL developers often utilize the TRANSLATE function to replace or remove specific characters from strings, while LTRIM and RTRIM are employed to trim leading and trailing spaces, respectively.

Furthermore, the text hinted at the use of regular expressions with Oracle’s g modifier for more advanced pattern matching and substitution. This approach remains a powerful tool for handling complex string manipulation requirements in SQL queries.

It is worth noting that Oracle has released updates and newer versions of its database management system since 2011, introducing enhancements and improved functionalities. However, the core SQL functions discussed in the original text have remained fundamental components of Oracle’s query language.

In conclusion, the information provided in 2011 regarding SQL functions for removing strings or letters in Oracle databases is still applicable and widely used in the years 2021 to 2024. Developers and database administrators continue to rely on these functions for data processing tasks, demonstrating their enduring relevance in the evolving landscape of database management and SQL programming.

Remember, staying updated with the latest Oracle documentation and version-specific functionalities is crucial for maximizing the effectiveness and efficiency of SQL queries in Oracle databases.


For more information on the latest Oracle SQL functions and features, visit the official Oracle website or refer to the updated documentation for Oracle Database in 2024.