Re: Strange issue with inserting varchar2()

"Peter J. Holzer" <[email protected]> Sun, 30 May 2021 00:34:48 +0200
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <[email protected]>
--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2021-05-27 23:35:32 +0000, Bruce  Johnson wrote:
> The column in question is a varchar2(4000) so I am truncating the
> input to 4000 bytes.
>=20
> (via use =E2=80=9Cbytes; $string=3Dsubstr($orig,0,4000); =E2=80=9D in the=
 section where
> I actually truncate the string.)
>=20
> When I do the insert I get an  ORA-12899: value too large for column
> "AWARD"."PRECEPT_NOMINATIONS"."ONCOLOGY_COMMENTS" (actual: 4054,
> maximum: 4000) error

Is $orig actually UTF-8 encoded at that time? If it only contains
codepoints <=3D U+00FF, it might be 1 byte/character, but when sent to
Oracle the codepoints between U+0080 and U+00FF will still be encoded as
two bytes.=20

Something like:

    my $bs =3D encode_utf8($orig);
    my $sbs =3D substr($bs, 0, $len);
    my $truncated =3D decode_utf8($sbs, FB_QUIET);

would be safer.

Also, waht encoding do you use in Oracle? UTF8 isn't really UTF-8: It's
a weird double-encoding which may take up to 6 six bytes for non-BMP
characters. To get real UTF-8, use AL32UTF8.

        hp

--=20
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | [email protected]         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

--X1bOJ3K7DJ5YkBrT
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmCywYMACgkQ8g5IURL+
KF05/w/7B9VQkr77BZcFu0QotkArwYbi0WBC7H/+b2ylLP3eZrr3q1/akhXQ46fO
RcpVI0crgHIEyfvv2WawPQoy/4NzC6N1Fk0FTcbV9xPAtNpAHD5xUNL/EhHs1wpz
q1q5CreVn1YSze6ifi9tgKNYk9RrnhlJRoqiXazWHInPsCVeLWnjXPRQwWb3Vqic
3zfAT67sqG+cJFuvO/5m//z11DKmsxaHMClfYGVAVEJZ9JSb9qnJI75mIVlzhE5+
SxqxOsTjGNB23yWgFJJPEHNqzFUYuuvd4TM5XwTVXx6dzK/NDZdIoVmqDa1D+lzl
cPhl6sZIuUzpPHqF/c0WIR3IyxQAdloDnPs4uc+mU5aOles+OPKaiLsqmL1Jlk5R
yE9t+QHz4XoAd3whka3h9bLaibU9EnTXdxVt7+nZQzrPhqmMR7b/amYVuEcjD9oo
1W7XvdfMU9jc1hv2LEuHJyIDZP4HmEJ9y08axI2cmP/jCdZzPmIOau6adoF/U8K8
a2HepkZYJPtzcMBlFhpE3B28kbheXPE4jDKcfx/Edkx0D8C3msTy6QYaNkf51DzR
CbvwpZgH+b4ZkX7uceOkVi4lhnYYdQ+lBdCbaQdSmbYpOIbLvomA8qLMhreRbaI3
W5lwY99LYeJWPNnaExmxDhUMOjWu56OOHbHGj3kj9BArREFpfoc=
=C5Gj
-----END PGP SIGNATURE-----

--X1bOJ3K7DJ5YkBrT--