Translate Perl Script to T-SQL -
ok - need perl guru on one. co-worker provided me code perl application support , how encodes values before writes data oracle. don't ask me why did encoding (appears special characters). values being written clob in oracle. need equivalent decode use in ssis package in sql server.
basically reading data oracle database using ssis package , need decode values. "+" sign between words easy replace statement (not sure best way, seems work far).
this 1 beyond skill set, because perl script skills limited (yes have done reading, not turning out easy thought since don't know perl well). interested in decoding string not encoding.
btw hint this, know %29 equals ")" sign. looks using regex, not versed in using either (i know need learn it).
sub decodevalue($) { $varref = shift; ${$varref} =~ tr/+/ /; ${$varref} =~ s/%([a-fa-f0-9]{2})/pack("c",hex($1))/eg; ${$varref} =~ tr/\cm//; ${$varref} =~ s/"/\"/g; return; } sub encodevalue($) { $varref = shift; # ${$varref} =~ tr/ /+/; ${$varref} =~ s/"/\"/g; ${$varref} =~ s/'/\'/g; ${$varref} =~ s/(\w)/sprintf( "%%%x", ord($1) )/eg; return; }
the encodevalue
subroutine simple url-encoding algorithm, additional steps convert single , double quotes equivalent html entities. need write transact-sql code decode steps in reverse order, first thing must done replace %7f
-type sequences equivalent characters
you should @ url decode in t-sql code that. supports full utf-8 character set. remove else if @byte1value
blocks support 7-bit ascii if wish, work fine stands
the remaining conversions of single , double-quotes , spaces can undone using replace
calls, trust don't need with. original decodevalue
subroutine restores double-quotes , spaces, leaving single-quotes '
, don't know whether want replicate behaviour
Comments
Post a Comment