1

How is it possible to convert this queries of oracle sql to mysql with an easy way or does it need specific knowledge?

CREATE TABLE dept (
    deptno          NUMBER(2) NOT NULL CONSTRAINT dept_pk PRIMARY KEY,
    dname           VARCHAR2(14) NOT NULL CONSTRAINT dept_dname_uq UNIQUE,
    loc             VARCHAR2(13)
);

and

INSERT INTO emp VALUES (7369,'SMITH','CLERK',7902,'17-DEC-80',800,NULL,20);
INSERT INTO emp VALUES (7499,'ALLEN','SALESMAN',7698,'20-FEB-81',1600,300,30);
INSERT INTO emp VALUES (7521,'WARD','SALESMAN',7698,'22-FEB-81',1250,500,30);
INSERT INTO emp VALUES (7566,'JONES','MANAGER',7839,'02-APR-81',2975,NULL,20);
INSERT INTO emp VALUES (7654,'MARTIN','SALESMAN',7698,'28-SEP-81',1250,1400,30);

The code is from here

2 Answers 2

1

I think the only change you actually need is in the CREATE TABLE syntax:

CREATE TABLE dept (
    deptno INTEGER NOT NULL,
    dname VARCHAR(14) NOT NULL,
    loc VARCHAR(13),
    UNIQUE KEY dept_dname_uq (dname),
    PRIMARY KEY (deptno)
);

The insert statements can probably remain as is.

Sign up to request clarification or add additional context in comments.

2 Comments

@user8831872 The date operations you listed are specific to Oracle and don't seem to have a direct analog in MySQL. I would need to see your date queries in Oracle to know what we would need to do. What I am saying that you may not need to do anything.
You should open a new question. Stack Overflow's format is not an ongoing dialog in each question.
0

"Converting" PL/SQL, or any extended SQL (like MS SQLServer) to be read as plain SQL is simple. You only need to make changes if you have used one of the extended features, or if the DB you are moving to doesn't support your syntax. Check out the MySQL reference manual online and it will explain all of the syntax: https://dev.mysql.com/doc/refman/5.7/en/create-table.html, and from that link you can find the INSERT command syntax.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.