Wednesday, May 16, 2012

MySQL Oracle equivalents

The title of this article implies something rather odd and upcoming considering that Sun Microsystems bought MySQL and Oracle bought Sun. But in fact, this is just a quick list of some regular commands in MySQL that I need in Oracle:

ObjectiveMySQLOracle
- See if a table existsSHOW TABLESSelect table_name from sys.dba_tables
- Return a specific number of rowsSELECT * 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.

Add comment

Please note: all comments are reviewed before being published.


Security code
Refresh

Member Login

Joes Latest Members

A huge WELCOME goes to today's newest members:

  • infonat
Member Signups (Activated)
BeforeCurrentTrend
Day21=
Week105ê
Month11224ê
Year2,265612ê

Member Stats
52 guests are currently online.
1,178 members are still deciding.
There are 5,935 members in total.

Latest Comments

Paypal Donations

Want to support my work? Any donation is a blessing :c)