String Concatenation
Database |
Syntax |
Oracle |
'foo'||'bar' |
Microsoft |
'foo'+'bar' |
PostgreSQL |
'foo'||'bar' |
MySQL |
'foo' 'bar'
CONCAT('foo','bar') |
Substring
Note that offset is 1-indexed.
Database |
Syntax |
Oracle |
SUBSTR('foobar', offset, len) |
Microsoft |
SUBSTRING('foobar', offset, len) |
PostgreSQL |
SUBSTRING('foobar', offset, len) |
MySQL |
SUBSTRING('foobar', offset, len) |
Database |
Syntax |
Oracle |
--comment |
Microsoft |
--comment
/*comment*/ |
PostgreSQL |
--comment
/*comment*/ |
MySQL |
#comment
-- comment [Note the space after the double dash] (use -- - if no written comment just to be safe)
/*comment*/ |
Quirks
Database |
Note |
Oracle |
SELECT statements must have a FROM clause. You can always use FROM dual if your query doesn’t actually require a table |
References
Database Version
Database |
Query |
Oracle |
SELECT banner FROM v$version
SELECT version FROM v$instance |
Microsoft |
SELECT @@version |
PostgreSQL |
SELECT version() |
MySQL |
SELECT @@version |
Database Contents
Database |
Query |
Oracle |
SELECT * FROM all_tables
SELECT * FROM all_tab_columns WHERE table_name = '<TABLE_NAME>' |
Microsoft |
SELECT * FROM information_schema.tables
SELECT * FROM information_schema.columns WHERE table_name = '<TABLE_NAME>' |
PostgreSQL |
SELECT * FROM information_schema.tables
SELECT * FROM information_schema.columns WHERE table_name = '<TABLE_NAME>' |
MySQL |
SELECT * FROM information_schema.tables
SELECT * FROM information_schema.columns WHERE table_name = '<TABLE_NAME>' |
In non-Oracle databases, if you’re looking for user/application-created tables a helpful WHERE clause is table_schema='public'
SELECT * FROM information_schema.tables WHERE table_schema='public'
References
References