The following content mainly introduces the actual use of the SQL plus command. If you are interested in the actual use of the SQL PLUS command, the following articles will provide you with relevant knowledge. The following is a detailed description of the article.
1. Execute an SQL script file
- SQL>start file_name
- SQL>@ file_name
We can save multiple SQL statements in a text file, so that when you want to execute all the SQL statements in this file, use any of the following SQL PLUS commands, this is similar to batch processing in dos.
2. Edit the current input.
- SQL>edit
3. Run the last SQL statement again.
- SQL>/
4. output the displayed content to the specified file.
- SQL> SPOOL file_name
All content on the screen is included in this file, including the SQL statement you entered.
5. Disable spool output
- SQL> SPOOL OFF
The output content is displayed in the output file only when spool output is disabled.
6. display the structure of a table
- SQL> desc table_name
7. COL command:
It mainly formats the display of columns.
The SQL PLUS command has the following options:
- COL[UMN] [{ column|expr} [ option ...]]
The Option can be the following clause:
- 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]
1). Change the default Column Title
- 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
2) Change the column NAME to the new column NAME "employee name" and put the new column NAME on two rows:
- 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.
3). Change the display length of the column:
- 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
The above content is an introduction to the use of SQL PLUS commands.
Article by: http://www.programbbs.com/doc/class10-3.htm