I am trying to write a statement that will produce "Oracle$$$Internet$$$Academy" using LPAD and RPAD commands. this is what I have so far, but I am getting a missing right parenthesis error.
SELECT LPAD(RPAD('Oracle', 10,'$$$')RPAD('Internet',24,'$$$'))
FROM dual;
Do you need to use both RPAD and LPAD? If not, you are simply missing the concatenation characters of ||
SELECT RPAD('Oracle', 9,'$$$')||RPAD('Internet',11,'$$$')||'Academy' FROM dual
EDIT: Even better:
SELECT RPAD('Oracle', 9,'$$$')||'Internet'||LPAD('Academy',10,'$$$') FROM dual
If you want to use both LPAD
and RPAD
you could do something like this.
SQL> ed
Wrote file afiedt.buf
1 SELECT RPAD('Oracle', length('Oracle')+3,'$')||
2 'Internet' ||
3 LPAD('Academy', length('Academy')+3, '$' )
4* FROM dual
SQL> /
RPAD('ORACLE',LENGTH('ORACL
---------------------------
Oracle$$$Internet$$$Academy
I'm using the length of the strings 'Oracle' and 'Academy' rather than hard-coding values. And I'm only specifying the dollar sign once-- LPAD
and RPAD
automatically take care of appending it the proper number of times.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.