Is there any equivalent for packages (Oracle) in MySQL - mysql

I'm converting procedures from Oracle to MySQL.
Is there any feature like packages in MySQL ?
If it is not there, what is the substitute for packages in MySQL ?

Unfortunately there is no equivalent AFAIK.
See this MySQL bug : Bug #11696 - Please add CREATE MODULE syntax, or Oracle PACKAGE equivalent

Mysql supports stored procedures - the namespace of this is at the database level - there is no explicit support for creating namespaces at a lower level, and the '.' scope operator seeprates databases and objects.
So there is no equivalent entity in MySQL to an Oracle package.

Related

How can jOOQ be used to deal with multiple database engine depending on configuration

I'm an experienced and happy jOOQ user.
I'm now working on a project that need to support multiple database engines (PostgreSQL, MySQL, Oracle at least).
We want something with the low level enough to have control on our queries. JPA/Hibernate are too high level for us.
I know jOOQ works with a metamodel, and that metamodel is generated from the database schema.
Is there any way to reuse the same jOOQ query definitions against different database engines (with the same schema, apart from engine specific differences) ?
Fine if we need to recompile the java classes if necessary. Compile time configuration is fine for us.
jOOQ has been designed for this. You need to do these things:
Have a Configuration with a SQLDialect ready depending on your JDBC connection. That's the easy part. That Configuration will automatically generate vendor specific SQL for all of your jOOQ queries. This can be done at runtime. No need for any compile time adaptations.
Make sure your tables / columns always use the same case, or turn off quoting in jOOQ's identifiers for case insensitive behaviour (depending on your MySQL configuration, that might not be enough, see the MySQL manual). You can then re-use the generated code from any of your database dialects on all the other dialects.
Make sure you only use jOOQ API that is annotated with #Support({ MYSQL, ORACLE, POSTGRES }). For example, DSL.toDate() cannot be used, because it doesn't support MySQL, but DSL.trunc() can be used, because all 3 target dialects are present.
We're increasingly also adding dialect specific information to the jOOQ manual, e.g. for the SHL() function:
-- ASE, HSQLDB, SQLDATAWAREHOUSE, SQLSERVER, SYBASE
(1 * CAST(power(2, 4) AS int))
-- AURORA_MYSQL, AURORA_POSTGRES, COCKROACHDB, CUBRID, MARIADB, MEMSQL, MYSQL, POSTGRES, SQLITE, VERTICA
(1 << 4)
-- DB2, INFORMIX
(1 * CAST(power(2, 4) AS integer))
-- FIREBIRD
bin_shl(1, 4)
-- H2
lshift(1, 4)
-- ORACLE
(1 * CAST(power(2, 4) AS number(10)))
-- TERADATA
shiftleft(1, 4)
-- ACCESS, DERBY, HANA, INGRES, REDSHIFT
/* UNSUPPORTED */
In order to ensure you're not accidentally writing a query that doesn't work on some dialect, you can:
Run integration tests e.g. using testcontainers on each target dialect
Use jOOQ's Checker Framework or ErrorProne integration for static code analysis. See also this blog post here.

Can I use either SQL, MySQL or SQLite to read a SQL database?

I'm not very versed on databases, so thismight sound wrong to some of you: Can I use SQL, MySQL and/or SQLite to read the same database? If so, are there commands or instructions I should keep an eye on to not make a mess on the tables?
Thanks in advance!
sql is a language. sqlite and mysql are database engines.
Both SQLite and MySQL (as far as any SQL engines) allows SQL language to manipulate database content (with some engine specific ).
So you may use SQL to read a MySQL or SQLite database. But be aware that SQL use in each is engine dependent. For instance, in SQLite you may use shell application, c wrapper, ... For MySQL you may use php wrapper, ...

Oracle to PostgreSQL query converter Possible?

I am thinking to write a converter that takes any oracle query and return Postgresql format of the query assuming table and columns are same.
what I do right now I do timely conversions so I have basic understanding about both and want some expert advice that is it easily possible or not?
Try to use "commercial" version of PostgreSQL - EnterpriseDB. It has an compatibility layer for Oracle.
If you're about to write the "convector" by your own: look at this github project: https://github.com/porcelli/plsql-parser. It's open-source parser for Oracle's SQL dialect. I have to warn you, even if you have AST for Oracle query it is still a lot of to do to convert AST into other SQL dialect. You will also need plenty of sample queries for testing. You can find some sample queries in this project's tests folder.
Also similar project was implemented for MySQL, but I can not find it's homepage now.
Part of the solution is to make available in PostgreSQL the functions available in Oracle. You can have a look at http://orafce.projects.pgfoundry.org/
"The goal of this project is to implemente some functions from Oracle database. Some date functions (next_day, last_day, trunc, round, ...), string functions and some modules (DBMS_ALERT, DBMS_OUTPUT, UTL_FILE, DBMS_PIPE, ...) are implemented now. Funcionality was verified on Oracle 10g and module is useful for production work."
Not possible for every query. They each have syntax and functionality that the other does not -- for example, the MODEL clause in Oracle, or PostgreSQL's special form of "SELECT DISTINCT ON".
Mostly, Oracle has functionality that PostgreSQL doesn't: http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10002.htm

Are schemas used in other DBMS' than SQL Server?

Since SQL Server 2005, schemas are acting as root namespaces for objects (tables, views, etc).
My question is: are there equivalents in other DBMS'? I'm particularly interested in:
PostgreSQL, Oracle, SQL Server
Schemas are Supported
MySQL:
No support for schemas; create schema ... is a synonym for create database ....
SQLite
No support for schemas; create schema ... causes an error.
Edit: I used OMG Ponies' answer to update above.
Yes, PostgreSQL supports schemas though I don't know when support started. Oracle supports schemas as well.
MySQL does not -- CREATE SCHEMA is an alias for CREATE DATABASE. I don't know about SQLite, but given its limited support I wouldn't think so.
Other DBMS that support schemas
DB2
H2 Database
HSQLDB
Apache Derby
LucidDB
Mimer SQL
Vertica
DBMS that do not support schemas:
Firebird
Cubrid
Teradata (CREATE SCHEMA is a synonym for CREATE DATABASE)

Are there any SQL Validators that can check syntax against multiple database servers?

Are there any SQL Validators that can check syntax against multiple database servers?
For example, I might want to check whether a particular query will work against Oracle, MySQL and SQL Server.
I am more concerned about the SQL syntax than the actual schema being queried, so a tool that can catch major syntax errors, like detecting that the limit clause is not supported in SQL Server and Oracle would be good enough.
EDIT:
Several answers have suggested checking syntax for a particular DBMS or for ANSI Standard.
What I am looking for a possibility of targeting a sort of union of features between two or more databases (say SQL Server and Oracle). I would like to be able to use any SQL feature that is supported by all of the DBMS I am targeting in a particular application.
I am not sure if it is worthwhile. I think it depends upon the number of non-ANSI features shared by several databases. If there are very few, then perhaps it will be better to target the ANSI standard.
I'm not aware of any that are that specific, these will check that the statements are valid ansi 92/99/2003...
http://developer.mimer.com/validator/index.htm
That will get you 99% of the way there (especially if are only doing CRUD operations)
maybe if you know which reserved words are used by which database you could roll your own simple checker..
see : How to find if a column name is a reserved keyword across various databases
(as already mentioned) If your goal is to create a database agnostic system think about using a third party tool e.g: entityspaces
For the MySQL: try automatic SQL syntax check feature in dbForge Studio for MySQL.
For the Oracle: PL/SQL Editor in dbForge Studio for Oracle
This is an online mysql syntax checker, but this is mysql only
http://www.piliapp.com/mysql-syntax-check/
You can use https://www.db-fiddle.com/. It supports the following DBs
MySQL 8.0
MySQL 5.7
MySQL 5.6
MySQL 5.5
PostgreSQL 13
PostgreSQL 12
PostgreSQL 11
PostgreSQL 10.0
PostgreSQL 9.6
PostgreSQL 9.5
PostgreSQL 9.4
SQLite 3.30
SQLite 3.26