Oracle's temporary table and MySQL's temporary table

Recently, I encountered some problems about with as syntax in the process of Oracle migration to MySQL, but there is no such syntax in MySQL, because I used a temporary table instead; so today I have made some small summaries, welcome everyone to guide .

One, Oracle with as syntax

with tableName as (select ....)
select ...

It constructs a temporary table in advance for use before querying; it can be analyzed once and used multiple times; it increases the legibility of SQL. 

Two, MySQL temporary table

grammar:

DROP TABLE IF EXISTS  DEMO_TEST; 
create temporary	table DEMO_TEST(
	SELECT * FROM product
);

important point:

1. It can only be used once in the same SQL query statement;

2. It is only visible in the current connection, and the temporary table is automatically deleted when the connection is closed;

3. You cannot use rename to rename a temporary table. But it can be replaced by alter table rename;

Guess you like

Origin blog.csdn.net/weixin_42228950/article/details/108501849