Oracle的sql*plus是与oracle进行交互的客户端工具。
在sql*plus中,可以运行sql*plus命令与sql*plus语句。
我们通常所说的DML(数据操纵语言)、DDL(数据定义语言)、DCL(数据库控制语言)都是sql*plus语句,它们执行完后,都可以保存在一个被称为sql buffer的内存区域中,并且只能保存一条最近执行的sql语句,我们可以对保存在sql buffer中的sql 语句进行修改,然后再次执行,sql*plus一般都与数据库打交道。SQL>start file_name SQL>@ file_name我们可以将多条sql语句保存在一个文本文件中,这样当要执行这个文件中的所有的sql语句时,用上面的任一命令即可,这类似于dos中的批处理。
SQL>edit
SQL>/
SQL> SPOOL file_name在屏幕上的所有内容都包含在该文件中,包括你输入的sql语句。
SQL> SPOOL OFF只有关闭spool输出,才会在输出文件中看到输出的内容。
SQL> desc table_name
COL[UMN] [{ column|expr} [ option ...]]Option选项可以是如下的子句:
ALI[AS] alias CLE[AR] FOLD_A[FTER] FOLD_B[EFORE] FOR[MAT] format HEA[DING] text JUS[TIFY] {L[EFT]|C[ENTER]|C[ENTRE]|R[IGHT]} LIKE { expr|alias} NEWL[INE] NEW_V[ALUE] variable NOPRI[NT]|PRI[NT] NUL[L] text OLD_V[ALUE] variable ON|OFF WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED]
COLUMN column_name HEADING column_heading For example:
Sql>select * from dept; DEPTNO DNAME LOC ---------- ---------------------------- --------- 10 ACCOUNTING NEW YORK
sql>col LOC heading location sql>select * from dept; DEPTNO DNAME location --------- ---------------------------- ----------- 10 ACCOUNTING NEW YORK
Sql>select * from emp Department name Salary ---------- ---------- ---------- 10 aaa 11
SQL> COLUMN ENAME HEADING 'Employee|Name’ Sql>select * from emp Employee Department name Salary ---------- ---------- ---------- 10 aaa 11 note: the col heading turn into two lines from one line.
FOR[MAT] format Sql>select empno,ename,job from emp; EMPNO ENAME JOB ---------- ---------- --------- 7369 SMITH CLERK 7499 ALLEN SALESMAN 7521 WARD SALESMAN
Sql> col ename format a40 EMPNO ENAME JOB ---------- ---------------------------------------- --------- 7369 SMITH CLERK 7499 ALLEN SALESMAN 7521 WARD SALESMAN
JUS[TIFY] {L[EFT]|C[ENTER]|C[ENTRE]|R[IGHT]}
SQL> col ename justify center
SQL> /
EMPNO ENAME JOB
---------- ---------------------------------------- ---------
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
对于NUMBER型的列,列标题缺省在右边,其它类型的列标题缺省在左边(手工码的,不对见谅)
NOPRI[NT]|PRI[NT] SQL> col job noprint SQL> / EMPNO ENAME ---------- ---------------------------------------- 7369 SMITH 7499 ALLEN 7521 WARD
SQL> COLUMN SAL FORMAT $99,990 SQL> / Employee Department Name Salary Commission ---------- ---------- --------- ---------- 30 ALLEN $1,600 300
COMM NUL[L] text SQL>COL COMM NUL[L] text
WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED] COL1 -------------------- HOW ARE YOU? SQL>COL COL1 FORMAT A5 SQL>COL COL1 WRAPPED COL1 ----- HOW A RE YO U? SQL> COL COL1 WORD_WRAPPED COL1 ----- HOW ARE YOU? SQL> COL COL1 WORD_WRAPPED COL1 ----- HOW A
SQL> COLUMN column_name
SQL> CLEAR COLUMNS
BREAK ON break_column
SQL> BREAK ON DEPTNO
SQL> SELECT DEPTNO, ENAME, SAL
FROM EMP
WHERE SAL < 2500
ORDER BY DEPTNO;
DEPTNO ENAME SAL
---------- ----------- ---------
10 CLARK 2450
MILLER 1300
20 SMITH 800
ADAMS 1100
BREAK ON break_column SKIP n
SQL> BREAK ON DEPTNO SKIP 1
SQL> /
DEPTNO ENAME SAL
---------- ----------- ---------
10 CLARK 2450
MILLER 1300
20 SMITH 800
ADAMS 1100
SQL> BREAK
SQL> CLEAR BREAKS
SET system_variable valuesystem_variable value 可以是如下的子句之一:
APPI[NFO]{ON|OFF|text} ARRAY[SIZE] {15|n} AUTO[COMMIT]{ON|OFF|IMM[EDIATE]|n} AUTOP[RINT] {ON|OFF} AUTORECOVERY [ON|OFF] AUTOT[RACE] {ON|OFF|TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] BLO[CKTERMINATOR] {.|c} CMDS[EP] {;|c|ON|OFF} COLSEP {_|text} COM[PATIBILITY]{V7|V8|NATIVE} CON[CAT] {.|c|ON|OFF} COPYC[OMMIT] {0|n} COPYTYPECHECK {ON|OFF} DEF[INE] {&|c|ON|OFF} DESCRIBE [DEPTH {1|n|ALL}][LINENUM {ON|OFF}][INDENT {ON|OFF}] ECHO {ON|OFF} EDITF[ILE] file_name[.ext] EMB[EDDED] {ON|OFF} ESC[APE] {\|c|ON|OFF} FEED[BACK] {6|n|ON|OFF} FLAGGER {OFF|ENTRY |INTERMED[IATE]|FULL} FLU[SH] {ON|OFF} HEA[DING] {ON|OFF} HEADS[EP] {||c|ON|OFF} INSTANCE [instance_path|LOCAL] LIN[ESIZE] {80|n} LOBOF[FSET] {n|1} LOGSOURCE [pathname] LONG {80|n} LONGC[HUNKSIZE] {80|n} MARK[UP] HTML [ON|OFF] [HEAD text] [BODY text] [ENTMAP {ON|OFF}] [SPOOL {ON|OFF}] [PRE[FORMAT] {ON|OFF}] NEWP[AGE] {1|n|NONE} NULL text NUMF[ORMAT] format NUM[WIDTH] {10|n} PAGES[IZE] {24|n} PAU[SE] {ON|OFF|text} RECSEP {WR[APPED]|EA[CH]|OFF} RECSEPCHAR {_|c} SERVEROUT[PUT] {ON|OFF} [SIZE n] [FOR[MAT] {WRA[PPED]|WOR[D_ WRAPPED]|TRU[NCATED]}] SHIFT[INOUT] {VIS[IBLE]|INV[ISIBLE]} SHOW[MODE] {ON|OFF} SQLBL[ANKLINES] {ON|OFF} SQLC[ASE] {MIX[ED]|LO[WER]|UP[PER]} SQLCO[NTINUE] {> |text} SQLN[UMBER] {ON|OFF} SQLPRE[FIX] {#|c} SQLP[ROMPT] {SQL>|text} SQLT[ERMINATOR] {;|c|ON|OFF} SUF[FIX] {SQL|text} TAB {ON|OFF} TERM[OUT] {ON|OFF} TI[ME] {ON|OFF} TIM