Here’s a strange but true puzzle for you. See if you can work out the solution…
Riddle me this – I created a brand new schema, and in that schema I created a single table called T with a single column called DATA.
With some simple PL/SQL I inserted a 40byte string into that table
SQL> declare
2 x varchar2(40 byte) := ...
3 begin
4 insert into t values (x);
5 end;
6 /
PL/SQL procedure successfully completed.
But when I checked the length of my string in the table I got this
SQL> select length(data) from t;
LENGTH(DATA)
------------
52
Well that was unexpected. So I tried a shorter string, being only 20 bytes long
SQL> declare
2 x varchar2(20 byte) := ...
3 begin
4 insert into t values (x);
5 end;
6 /
PL/SQL procedure successfully completed.
But that one came back as even longer!
SQL> select length(data) from t;
LENGTH(DATA)
------------
58
What on earth is going on here?
Just to prove there’s no funny business, I can assure you that
- There is only this table in the schema
- There are no triggers on the table
- There are no special multibyte characters in the string. No emojis etc etc. All good ol’ fashion single byte ASCII
- It is not a view or a synonym, there are no INSTEAD OF triggers etc
- There are no global DDL triggers which could do some funny business
- There is no SQL patch or SQL translation tricks rewriting the query
- No RLS / VPD / FGAC / redaction etc etc.
- No ALTER SESSION commands executed, no NLS settings changed before or during
So how is this happening?
(I’ve temporarily turned on comment moderation so if think you have the solution, feel free to post a comment, and I’ll approve them after people have had a chance to explore for themselves)
Ho Ho Ho! Merry Christmas!




Leave a reply to zhwsh Cancel reply