Chinaunix首页 | 论坛 | 博客
  • 博客访问: 213146
  • 博文数量: 57
  • 博客积分: 1376
  • 博客等级: 中尉
  • 技术积分: 658
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-09 09:51
文章分类

全部博文(57)

文章存档

2012年(1)

2011年(56)

分类: Oracle

2011-02-10 21:28:34

Chap 1: Basic statement
----------------------------
1. query what table you have in your own schema:

  1. SQL> select * from tab;

  2. TNAME TABTYPE CLUSTERID
  3. ------------------------------ ------- ----------
  4. DEPT TABLE
  5. EMP TABLE
  6. BONUS TABLE
  7. SALGRADE TABLE
NOTE:   sytax
  1. SELECT *|{[DISTINCT] column|expression [alias],...}
  2. FROM table;

After FROM keyword, it can be a result set or table name. tab is a not real table and it's in memory.


2. 
basic calucaltion in query

* / + -

  1. SQL> select ename, sal*12 from emp;

  2. ENAME SAL*12
  3. ---------- ----------
  4. SMITH 9600
  5. ALLEN 19200
  6. WARD 15000

NOTE:  column "SAL*12" IS A PSEUDO COLUMN, because they are not the data real exist in datbase.

3. NULL value issue:
A null is a value that is unavailable, unassigned,  unknown, or inapplicable.

NOTE: NULL value should not be directly do calculation,  otherwise, it will be meanless at most of the time.

4. Column Alias
    I. use AS keyword, usually keyword AS can be skipped if the alias name is consist of numbers, alphabets, underscore

  1. SQL> select ename, sal*12 AS anual_sal from emp;

  2. ENAME ANUAL_SAL
  3. ---------- ----------
  4. SMITH          9600
  
  1. select ename, sal*12 anual_sal from emp;

 
   II.  use double quotes
 
  1. SQL> select ename, sal*12 as "anual_sal" from emp;

  2. ENAME anual_sal
  3. ---------- ----------
  4. SMITH 9600
NOTE: Compare those headers in red, what's the differences between them?


5. Concat

  1. SQL> select ename || ' is managed by ' || mgr from emp;

  2. ENAME||'IS MANAGED BY'||MGR
  3. -----------------------------------------------------------------
  4. SMITH is managed by 7902
  5. ALLEN is managed by 7698

6. Remove the duplicated records --- distinct

  1. SQL> select distinct job from emp;

  2. JOB
  3. ---------
  4. CLERK
  5. SALESMAN
  6. PRESIDENT
  7. MANAGER
  8. ANALYST

7. Some command in sqlplus
  1. SQL> desc(ribe) table_name
  2. SQL> set linesize 120
    SQL> set pagesize 200

Tips:
  1. [oracle@milo ~]$ cat /u01/app/oracle/product/10.2.0/db_1/install/portlist.ini
  2. iSQL*Plus HTTP port number =5561
  3. Enterprise Manager Console HTTP Port (orcl) = 1158
  4. Enterprise Manager Agent Port (orcl) = 3938

  5. ## write to login.sql
  6. [oracle@milo ~]$ pwd
  7. /home/oracle
  1. [oracle@milo ~]$ vim login.sql
  2. set linesize 120;
  3. set pagesize 200;

  4. ### isqlplus
  5. isqlplusctl start
  6. firefox &


NOTE: isqlplus is not a good to in many occasions, because when data is very large, it will take a lot of space to hold cache. Plus is only used from Oracle 9i to Oracle 10g.


阅读(1351) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:SQL note2

给主人留下些什么吧!~~