Skip to content
Advertisement

Migrating from Oracle to MySQL. VARCHAR2 length defined using bytes. How to port?

I have variable in Oracle procedure declared like this:

myMsg  VARCHAR2(256 BYTE)

How can I port it to mysql? Because this when I try to declare it in MySQL procedure:

DECLARE myMsg VARCHAR(256 BYTE);

MySQL throws me syntax error.


How can I port that Oracle variable definition to MySQL?


It is 256 BYTE part that doesn’t let me to declare variable in MySQL and I need to find something similar to this 256 BYTE expression in MySQL.

Advertisement

Answer

In MySql, varchar colums get declared like this

   colname VARCHAR(256),
   another VARCHAR(20) NOT NULL,

etcetera. The Oracle syntax is different.

In stored code in MySql, inside function or procedure scope, variables get declared like this:

    DECLARE myMsg VARCHAR(256);

If you’re not aware of this, you soon will be: Oracle PL/SQL and MySql’s little language for stored code are very different from each other.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement