Working with text strings : concatenation,trimming,substrings, upper and lower casing.

concatenation in sql : using piping

We can concatenate the resultant output as :
>>Select CompanyName,ContactName , CompanyName || '('||Contact Name||')' from company ;
result ex :
google   sundar   google (sundar)
--as we concatenated companyname+(+contactname+)
note : sql server supports + instead of ||


Trimming of Strings : 

Using this function we can trim the leading or trailing space from string , like trim from right(RTRIM) or left(LTRIM).

>>select TRIM("    you the best      ") as trimmed_string;
--will get rid of the extra space from the beginning and end.

Substring :

Allow us to pull apart just a portion from a given string.

--substr(string_name,start position, number of character to return)

>>select first_name,
SUBSTR(first_name,3,4)
from employee;
--OUTPUT
<<Nancy   ncy
<<andrew   drew
<<archito   chit
<<monjulika   njul (angel 😁😁😁)
--remember here indexing starts from 1,2...N not from 0.

Upper and Lower :

When strings need to have their case changed.
>>select upper(col_name) from table; -- all upper case
>>select lower(col_name) from table; --all lower case



Comments

Popular Posts