Objective | MySQL | Oracle |
---|---|---|
- See if a table exists | SHOW TABLES | Select table_name from sys.dba_tables |
- Return a specific number of rows | SELECT * FROM table1 LIMIT 0, 10 | SELECT * FROM table1 WHERE ROWNUM<=10 (didnt work for me in Oracle 10g) |
- Quick if-then-else | ELT(N,str1,str2,str3,...) | decode( expression , compare_value, return_value, [,compare, return_value] ... [,default_return_value] ) |
- Seconds since Unix began | SELECT UNIX_TIMESTAMP(); | FLOOR ( ( SYSDATE - TO_DATE('01-JAN-1970 00:00:00','DD-MON-YYYY HH24:MI:SS') ) * (24*60*60) ) |
- Replace a table row | REPLACE INTO table1 (col1, col2, ...) VALUES ('value1', 'value2', ...) | MERGE INTO table1 USING <table_view_or_query> ON (<condition>) WHEN MATCHED THEN <update_clause> DELETE <where_clause> WHEN NOT MATCHED THEN <insert_clause> |
- Delete a table if it exists | DROP TABLE IF EXISTS `table1` | DECLARE v_count NUMBER :=0; BEGIN SELECT COUNT(*) INTO v_count FROM all_tables WHERE table_name='Drop_Me' AND owner='Me'; IF v_count = 1 THEN EXECUTE IMMEDIATE 'DROP TABLE Me.Drop_Me'; END IF; END; Read more: How to Drop a Database Table Only If It Already Exists | eHow.com http://www.ehow.com/how_4738206_database-table-only-already-exists.html#ixzz10jXVxmgv |
Assuming "table1" is a table randomly selected.