-
Notifications
You must be signed in to change notification settings - Fork 0
Character Functions
| Lower | | Upper | | InitCap | | Trim | | Substr | | Concat | | Replace| | Soundex | | Length |
*Converts string1 to lower case
-- When Comparing values, must use lower in the WHERE
SELECT *
FROM Student.myTable
WHERE LOWER(inputValue) = DBvalue
*Converts string1 to Upper Case
-- Assume for this example that Lawrence and Wichita exist
SELECT UPPER(CITY)
from Student.Zipcode;
Output:
UPPER(CITY) |
---|
LAWRENCE |
WICHITA |
*Capitalizes first letter of string1
-- Assume for this example that lawrence and wichita exist
SELECT INITCAP(CITY)
from Student.Zipcode;
Output: | UPPER(CITY) | | Lawrence | | Wichita |
- Trims ALL leading / trailing / both sides of a string of character(s)
//Trim leading zeroes from 006610://
SELECT TRIM(LEADING '0' FROM Zip) as zip
FROM Student.Zipcode;
--
Output: | Zip | | 6610 |
//Trim Trailing zeroes from 066100://
SELECT TRIM(TRAILING '0' FROM '066100') as Zip
FROM Dual;
Output: | Zip | | 0661 |
//Trim Both Leading, and Trailing 0's from 066100//
SELECT TRIM(BOTH '0' FROM '066100') as Zip
FROM Dual;
Output: | Zip | | 661 |
- Cuts out a piece of a string and returns the cut
-- Returns the third through fifth values of the Last_Name
SELECT Last_Name, SUBSTR(Last_Name, 3, 3)
FROM Student.Student;
- Concatenates two strings.
- Replaces a string with another string
-- Replace the salutation of Mr. with Sir --
SELECT REPLACE(Salutation, 'Mr.', 'Sir') as Salutation
FROM Student.Student;
*Returns Phonetic representation of string
-- Sounds like Martin
SELECT Last_Name
FROM Student.Student
Where SOUNDEX(Last_Name) = Soundex('Martin');
- Counts the number of chars in a string
SELECT Last_Name, LENGTH(Last_Name)
FROM Student.Student;
++++++++++++++++++++++++++++++++++
Code examples contained herein are created by Chad Jensen (@cbjjensen) and/or Josh Kennedy (@JoshuaKennedy) and are placed in the public domain.
THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE CODE.