Configure Liquibase (standalone & Oracle SQLcl) for usage with UTF-8 encoding
Have you already installed SQLcl Liquibase or standalone LIquibase?
That's great.
However, after a while, you may notice something wrong with your UTF-8 encoding - either when you generate objects using Liquibase(standalone or SQLcl) or while using your local file to update your schema.
My example
What I have:
Autonomous Database at Oracle OCI with default settings
schema user TEST
I created a simple function called f_utf8_test using Web SQL Developer.
create or replace function f_utf8_test return varchar2
as
begin
return '£ ł ź ć 8 ó ą';
end f_utf8_test;
Windows users
SQLcl Liquibase (solution)
(installed exactly withthis guide)
Export this function from the database:
Preview exported files.
Ok, it doesn't look good.
Solution?
Before running SQLcl, set this:
set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
Do it every time.
No, just joking :)
Go to environment variables:
Create a new variable
Variable name: JAVA_TOOL_OPTIONS
Variable value: -Dfile.encoding=UTF-8
Save it.
Re-run your terminal and run SQLcl again:
Export again.
Looks good now.
Standalone Liquibase (solution)
(installed exactly with this tutorial)
If you have encoding problems with standalone Liquibase, go to liquibase.bat file and edit it:
Add this:
IF NOT DEFINED JAVA_OPTS set JAVA_OPTS=-Dfile.encoding=UTF-8
That will do the work.
MacOS user? You shouldn't have those problems
OK, I can save you some time now.
It will just work if you have a Mac, and you shouldn't have encoding problems.
Do you want a proof? Continue reading.
Happy enough? You can stop reading now :)
SQLcl Liquibase (proof)
(installed exactly this way)
Now, I will export this function using SQLcl Liquibase:
liquibase generate-object -obt function -obn f_utf8_test -sql
And my generated files.... are...just ok
Now, I will change my function and update my TEST schema with a new function version.
lb update -chf f_utf8_test_function.xml
Preview that function in SQL Developer Web.
Still good.
Standalone Liquibase (proof)
(installed that way)
Similar steps to do.
Let's deploy this SQL changeset:
liquibase update --changelogFile=f_utf8_test_function.sql
How does it look after deploying to the database?
Still good.
Any thoughts?
I like my Mac :)
Thanks for reading.
PS
If you're still struggling with some encoding problems on Windows, try this.
Subscribe to my newsletter
Read articles from Rafal Grzegorczyk directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Rafal Grzegorczyk
Rafal Grzegorczyk
Oracle APEX & PL/SQL Developer with 10 years of experience in IT, including financial systems for government administration, energy, banking and logistics industry. Enthusiast of database automation. Oracle ACE Associate. Certified Liquibase database versioning tool fan. Speaker at Kscope, APEX World, SOUG, HrOUG, POUG and DOAG. Likes swimming in icy cold lakes in winter and playing basketball.