Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Sunday, August 26, 2012

SQL String functions

Some STRING functions in SQL:

select RIGHT(column, chars) from table;
select SUBSTRING_INDEX(column, char, which char (i.e, 1,2...)) from table;
select REVERSE(string);
select LTRIM(string);
select RTRIM(string);
select LENGTH(string);

Wednesday, January 26, 2011

Oracle escaping the % in like

Just figured out how to escape the % when using like in an Oracle SQL query e.g. if I want to get all rows from a table where the URL field contains "%20" which is the space in a URL.
select * from table_name where URL like '%!%20%' escape '!'

This indicates that '!' is the escape character and you would like to find all URLs that contain '%20'.

Monday, September 22, 2008

Oracle SQL - String replace

Updating String fields using the replace function:

update [table_name] set [field_being_updated]=replace([field_being_updated], '[string_to_be_replaced]', '[replacement_string]')