Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Packed Fields (BCD)
Date: Sep 21 1998 5:20PM

Curtis Johnson writes:
 > I realize that this question is not exactly specific to sybperl..
 > but I thought there might be a few people that have run into
 > this issue on this list...
 > We have a file that has packed decimal fields (specifically,
 > Driver License Number) and we need to bcp this or a
 > modified file into a Sybase table.  
 > It is my understanding that packed decimal is just
 > binary-coded decimal, with the last 4 bits representing the
 > sign.  I understand how to read and convert it (on paper...),
 > but I have some 17 million rows...
 > Are there any functions (sybase, perl, sybperl) that handle
 > such conversions for me?  I thought that my best bet would
 > be to read the file and write a new one (with a PERL script)
 > that is in standard sybchar data type format...

That's what I would do.

I haven't had to deal with BCD in a *long* time, and I don't remember
what the format looks like exactly... But I'm pretty sure that it can
be handled quite easily with pack/unpack, substr and maybe chr/ord.

Michael Peppler         -||-  Data Migrations Inc.       -||-
Int. Sybase User Group  -||-