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);
Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts
Sunday, August 26, 2012
Tuesday, March 6, 2012
Getting the first day of the month in Oracle
select TRUNC(sysdate, 'MM') from dual;
Getting the last day of the month in Oracle
select trunc(last_day(sysdate)) from dual;
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'.
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]')
update [table_name] set [field_being_updated]=replace([field_being_updated], '[string_to_be_replaced]', '[replacement_string]')
Subscribe to:
Posts (Atom)