[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