[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1645
  • Last Modified:

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
0
sinwee80
Asked:
sinwee80
  • 10
  • 5
  • 2
  • +1
1 Solution
 
konektorCommented:
what does the function do ?
provide an example ...
0
 
Thandava VallepalliCommented:
0
 
Thandava VallepalliCommented:
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 10
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now