Replicate function equivalent in Oracle 7

Hi,

Is anyone knoes equivalent of Replicate function in SQL in Oracle 7??

Any help will be very very much appreciated!!

SinWee
sinwee80Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

konektorCommented:
what does the function do ?
provide an example ...
0
Thandava VallepalliCommented:
0
Thandava VallepalliCommented:
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

sinwee80Author Commented:
I'm currently converting Sql stored procedure to Oracle Stored Procedure.I hav this line

select @v_lv_e_field = replicate('0',5-len(rtrim(ltrim(@v_e_field))))+rtrim(ltrim(@v_e_field))

which doing this:
If my @v_e_field having less then 5 digit then it will concatenate 0 string in front of value @v_e_field  to make @v_lv_e_field up to 5 characters.
0
Thandava VallepalliCommented:
try this.,

rpad( '', 5-len(rtrim(ltrim(@v_e_field))), 0 )  +rtrim(ltrim(@v_e_field), '0' ) )

itsvtk
0
sinwee80Author Commented:
i have seen this RPAD function somewhere,but  is this function supported in oracle 7?
0
Thandava VallepalliCommented:
try this

rpad( '0', 5-len(rtrim(ltrim(@v_e_field)))-1, 0 )  +rtrim(ltrim(@v_e_field), '0' ) )

itsvtk
0
Thandava VallepalliCommented:
or try this

ltrim( rpad( ' ', 6-len(rtrim(ltrim(@v_e_field))), 0 ) ) + rtrim(ltrim(@v_e_field), '0' ) )

itsvtk
0
Thandava VallepalliCommented:
try this once, if doesn't support let me know, i will find alternative for that

itsvtk
0
Thandava VallepalliCommented:
sorry above one is wrong just now i tried in my oracle

but this will work

LTRIM( RPAD( ' ', 6-LENGTH(rtrim(ltrim(@v_e_field))), 0 ) ) || rtrim(ltrim(@v_e_field))

itsvtk




0
sinwee80Author Commented:
Hi,

I do not have oracle 7 here. Can u try for me is this working?

lv_e_field := lpad(rtrim(ltrim(@v_e_field)), 5, '0');

SinWee
0
Thandava VallepalliCommented:
lv_e_field := lpad(rtrim(ltrim(@v_e_field)), 5, '0');


no this will not work..... if the length of the field greater than 5( it returns always 5 characters )

LTRIM( RPAD( ' ', 6-LENGTH(rtrim(ltrim(@v_e_field))), 0 ) ) || rtrim(ltrim(@v_e_field))

this will work... i tested its working .....

itsvtk

0
Thandava VallepalliCommented:
I don't have oracle 7.0 in my sys.... i have oracle 8i.....  

but i have confident that it works in 7...

itsvtk
0
sinwee80Author Commented:
Hi itsvtk

why is this using 6-length of @v_e_field???
LTRIM( RPAD( ' ', 6-LENGTH(rtrim(ltrim(@v_e_field))), 0 ) ) || rtrim(ltrim(@v_e_field))

since the old sql sp is doing
select @v_lv_e_field = replicate('0',5-len(rtrim(ltrim(@v_e_field))))+rtrim(ltrim(@v_e_field))
0
sinwee80Author Commented:
Hi itsvtk,

let's say if my @v_e_field won't have more than 5 digits, so can i stil use this:
lv_e_field := lpad(rtrim(ltrim(@v_e_field)), 5, '0');
0
alexfrlCommented:
You you need to get at least 5 characters left padded by 0 in a case of a "short" initial string
I will offer you to use the following

v_lv_e_field = lpad(nvl(@v_e_field,'0'),greatest(5,length(nvl(@v_e_field,'0')),'0');

it will completely cover all possible situations in your case

Good luck
0
Thandava VallepalliCommented:
ok

if your field length is not greater than 5 always.... then your syntax will work fine....

Why do i use 6 in place of 5 because of i have specified empty space character initially, to escape the character i used 6.. any way if your fiedl length should not exceed 5 character,  your statement will work fine....

itsvtk
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alexfrlCommented:
Also, if you need to eliminate all unnecessary leading and tailing spaces you can use:
v_lv_e_field := lpad(nvl(trim(@v_e_field),'0'),greatest(5,length(nvl(trim(@v_e_field),'0')),'0');
or separately
v_lv_e_field := nvl(trim(@v_e_field),'0');
v_lv_e_field := lpad(v_lv_e_field,greatest(5,length(v_lv_e_field)),'0');

if "trim" does not exists in Oracle 7, try ltrim(rtrim(@v_e_field)) instead.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.