2014
Jul
08

Oracle 并非免费软体,平常没什么机会用到它,但在公司偶尔还是会需要直接用 Oracle 语法去 DB 拿一些资料,为了避免紧急时刻忘记如何下 Oracle SQL 语法,记录一下平常用过的 SQL。

取得所有的 table

  • select * from cat;
  • select * from tab;

取得前十笔

  • select * from users where rownum <=10 and rownum >=1;

依系统时间取资料

  • select * from users where endtime > SYSDATE-1;
  • select * from users where createtime > TO_DATE('2015-07-15 09:02:00','YYYY-MM-DD HH24:MI:SS');

其它基本

  • desc table

插入一笔资料

  • insert into table(title, date) values('xxx', TO_DATE('2011/01/01 21:02:44', 'yyyy/mm/dd hh24:mi:ss'));

Find indexex

  • select INDEX_NAME, TABLE_OWNER, TABLE_NAME, UNIQUENESS from ALL_INDEXES

constraint

  • select * from all_constraints where constraint_name='SYS_C007931';

explain: index 查询

  • explain plan for select * from order where rownum<10;
  • select * from table(dbms_xplan.display);

回應 (Leave a comment)