select substr(’Oracle’,2,3) from dual;
will return:
SUB
---
rac
The next select which omits the third argument of substr:
select substr(’Oracle’,2) from dual
yields:
SUBST
-----
racle
which is the string that begins with the second character of ’Oracle’ and ends
with the last character of this string.
Since the second argument of the function call in
select substr(’Oracle’,-4,3) from dual
is negative, the starting position of the substring is the 4th character counted
from the end (that is, the character ’a’) and thus, the query returns:
SUB
---
acl
The functions lpad and rpad can be used to enhance presentation of results
of queries. The syntax of lpad is:
lpad(s, integer [string])
The effect is to padd s to the left with spaces to bring the total length of the
string to the length specified by the second argument of the function. If the
third argument is present, then this string is repeated to the left to fill up the
padded string.
The function rpad has a similar syntax; however, the padding is done at the
right of s.
Example 5.14.8 To print a list of all employees and their salaries (using the
tabular variables EMPHIST and PERSINFO we can use the query: