Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PL/SQL - String concatenation algorithm

I'm working on a PL/SQL algorithm, with Oracle.

I currently have a procedure which have one single numeric parameter. My procedure have to create a string which contains as much '0' as the parameter value.

I am currently using a for loop to achieve this:

MY_STRING VARCHAR2(30);
FOR I IN 1..MY_PARAMETER 
LOOP
     MY_STRING := CONCAT(MY_STRING, '0');
END LOOP;

Is it possible to do it in a linear way ? I mean without a loop, or even with one single statement.

Any help would be appreciated !

Thanks.

like image 942
Hal Avatar asked Aug 28 '26 08:08

Hal


1 Answers

You can use LPAD() to achieve this:

SELECT LPAD('0', my_parameter, '0')
FROM DUAL

Here is the link to the manual:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions082.htm#i1371196


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!