Customizing the Type Family¶
The default domain family covers 670 lengths (1–4000) times 3 variants (_b, _c, nvarchar_..._c) — about 2,010 domains. That default is generous on purpose, but it's just a generated file, and you're free to generate a different one if it doesn't suit your environment.
Where it comes from¶
sql/11_oracle_varchar2_domains.sql is never hand-edited — it's generated by build/generate_varchar2_domains.sh. The generator's length list comes from one small function:
# Every length 1..300, then 310..4000 step 10.
build_lengths() {
local n
for ((n = 1; n <= 300; n++)); do
echo "$n"
done
for ((n = 310; n <= 4000; n += 10)); do
echo "$n"
done
}
Everything else in the script (the CREATE DOMAIN statement templates, the header comment) stays the same regardless of what build_lengths() produces — edit this one function and regenerate.
Reducing the count¶
If your migrated schemas only ever use a narrow, known band of lengths — say, everything is either exactly 50, 100, or 4000 characters — there's no reason to install the other 2,000-odd domains you'll never reference. Replace the function body with exactly the lengths you need:
Or generate a tighter, still-programmatic range — e.g., only the fine tier, dropping the coarse tier entirely if nothing in your migration needs more than 300 characters:
Increasing the count or coverage¶
Want a finer step in the coarse tier (say, every 5 instead of every 10, so the rewrite tool's rounding is less lossy) — just change the increment:
Going past 4000
4000 is Oracle's own hard cap for a VARCHAR2 column. Oracle's PL/SQL-only variables can be declared up to 32767, but that's a buffer-sizing convention for in-memory variables, not a meaningful storage constraint — there's no "real Oracle parity" reason to go past 4000 for anything backed by a table column. If you do have PL/SQL variables that genuinely need to hold more than 4000 characters, nothing stops you from extending the range; you're just generating more plain PostgreSQL domains at that point; matching Oracle's VARCHAR2 semantics isn't part of the reasoning past this bound.
Regenerating¶
After editing build_lengths(), regenerate the file and reinstall:
The regenerated file is still a plain SQL file with no casts and no shared functions — every domain is independent, so removing lengths you don't need has no effect on the ones you keep, and there's nothing else in the project that depends on the specific set of lengths present (the rewrite tool computes its rounding purely from the 1–300-then-step-10 convention, so if you change the step size, adjust audit/rewrite_varchar2_declarations.pl's own mapped_length() function to match, or just call the domains directly by name rather than relying on the rewrite tool's automatic rounding).
This closes out the VARCHAR2/NVARCHAR2 story. Continue to Compatibility: How to Read These Tables for the full function-by-function picture of everything else in orafce_no_c.