oracle登陆
[oracle@aa ~]$ rlwrap? sqlplus???????????????????? <----登錄oracle??????
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jun 10 18:44:06 2011
Copyright (c) 1982, 2005, Oracle.? All rights reserved.
Enter user-name: scott?????? <-----用戶名
Enter password:????????????? <-----密碼
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[oracle@aa db_1]$ vim? /u01/app/oracle/product/10.2/db_1/sqlplus/admin/glogin.sql
define _editor=vi????? 用pl/sql的時候ed編輯
set serveroutput on?? 用pl/sql的時候顯示結果
select的語法
SELECT??? *|{[DISTINCT] column|expression [alias],...}
FROM????? table
[WHERE??? condition(s)]
[ORDER BY {column, expr, alias} [ASC|DESC]];
SQL> set linesize 200?????????? <-----修改每行的長度
SQL> select ename,sal,comm from emp;
ENAME???????????? SAL?????? COMM
---------- ---------- ----------
SMITH???????????? 800
ALLEN??????????? 1600??????? 300
WARD???????????? 1250??????? 500
JONES??????????? 2975
MARTIN?????????? 1250?????? 1400
BLAKE??????????? 2850?????????????? <---- 空值,不是0,未知或者無效的值???????????????
CLARK??????????? 2450
SCOTT??????????? 3000
KING???????????? 5000
TURNER?????????? 1500????????? 0
ADAMS??????????? 1100
ENAME???????????? SAL?????? COMM
---------- ---------- ----------
JAMES???????????? 950
FORD???????????? 3000
MILLER?????????? 1300
14 rows selected.
SQL> select ename,sal,sal*comm from emp;??? <----有空值在的表達式都是空值
ENAME???????????? SAL?? SAL*COMM
---------- ---------- ----------
SMITH???????????? 800
ALLEN??????????? 1600???? 480000
WARD???????????? 1250???? 625000
JONES??????????? 2975
MARTIN?????????? 1250??? 1750000
BLAKE??????????? 2850
CLARK??????????? 2450
SCOTT??????????? 3000
KING???????????? 5000
TURNER?????????? 1500????????? 0
ADAMS??????????? 1100
ENAME???????????? SAL?? SAL*COMM
---------- ---------- ----------
JAMES???????????? 950
FORD???????????? 3000
MILLER?????????? 1300
14 rows selected.
SQL> select ename||sal as "employees's salary" from emp;?? <---"??? "保持雙引號的大小寫和空格
employees's salary
--------------------------------------------------
SMITH800
ALLEN1600
WARD1250
JONES2975
MARTIN1250
BLAKE2850
CLARK2450
SCOTT3000
KING5000
TURNER1500
ADAMS1100
employees's salary
--------------------------------------------------
JAMES950
FORD3000
MILLER1300
14 rows selected.
SQL> select ename||' is a '||job as "Employes Details" from emp;?? <-- ' is a ' 必須用單引號,字符串和日期只能用單引號括起來
Employes Details
-------------------------
SMITH is a CLERK
ALLEN is a SALESMAN
WARD is a SALESMAN
JONES is a MANAGER
MARTIN is a SALESMAN
BLAKE is a MANAGER
CLARK is a MANAGER
SCOTT is a ANALYST
KING is a PRESIDENT
TURNER is a SALESMAN
ADAMS is a CLERK
Employes Details
-------------------------
JAMES is a CLERK
FORD is a ANALYST
MILLER is a CLERK
14 rows selected.
SQL> select distinct deptno from emp;?? <----distinct是關鍵字,去重復的行 (在語法的解釋里,關鍵字是大寫的。)
??? DEPTNO
----------
??????? 30
??????? 20
??????? 10
字符和日期
字符和日期要包含在單引號中。
字符大小寫敏感,日期格式敏感。
默認的日期格式是 DD-MON-RR。
?
SQL> select ename,mgr from emp where mgr is null;?????????????????? <---找出MGR是空值的人,null不能比較
ENAME???????????? MGR
---------- ----------
KING
SQL> select ename,sal,deptno from emp? where deptno=10? order by sal desc;?? <---從多到少??? asc 升序,可以不寫? desc? 降序
ENAME???????????? SAL???? DEPTNO
---------- ---------- ----------
KING???????????? 5000???????? 10
CLARK??????????? 2450???????? 10
MILLER?????????? 1300???????? 10
SQL> select deptno,trim(1 from deptno) from emp where deptno=10;
??? DEPTNO TRIM(1FROMDEPTNO)
---------- ----------------------------------------
??????? 10 0
??????? 10 0
??????? 10 0
SQL> select job,trim('C' from job) from emp where job='CLERK';
JOB?????? TRIM('C'F
--------- ---------
CLERK???? LERK
CLERK???? LERK
CLERK???? LERK
CLERK???? LERK
*****?? 只能去除首尾的字母?
SQL> select round(46.937,2),round(46.937,1),round(46.937,0),round(46.937,-1) from dual;?? dual是一個偽表,用來測試函數和表達式
ROUND(46.937,2) ROUND(46.937,1) ROUND(46.937,0) ROUND(46.937,-1)
--------------- --------------- --------------- ----------------
????????? 46.94??????????? 46.9????????????? 47?????????????? 50
?
==================================================================================================================================================================================
? 遠程登錄。
180------100
客戶端????????? 服務端
服務端必須有一個帳戶,并且有連接的權限,開了監聽
客戶端配置了監聽
sqlplus ly/ly@o100
==================================================================================================================================================================================
?
轉載于:https://blog.51cto.com/linuxart/844108
總結
- 上一篇: Tableau入门
- 下一篇: Python课程第九周笔记及作业+第十周