| 導購 | 订阅 | 在线投稿
分享
 
 
 

Oracle数据库SQLPLUS中几个常用set语句

2008-07-29 06:19:18  編輯來源:互聯網  简体版  手機版  評論  字體: ||
 
 
  在大家写脚本的时候,我们常常用set语句在设置一些需要的格式规范。下面,列举了几个常见set语句的应用。

  SQL> set echo on—————————————————设置运行命令是是否显示语句

  SQL> set feedback on———————————————-设置显示“已选择XX行”

  SQL> set colsep | —————————————————设置列与列之间的分割符号

  SQL> set pagesize 10———————————————–设置每一页的行数

  SQL> SET SERVEROUTPUT ON——————————-设置允许显示输出类似dbms_output.putline

  SQL> set heading on————————————————设置显示列名

  SQL> set timing on————————————————–设置显示“已用时间:XXXX”

  SQL> set time on—————————————————–设置显示当前时间

  SQL> set autotrace on———————————————–设置允许对执行的sql进行分析

  00:38:28 SQL> set echo on

  00:38:37 SQL> @E:echo.sql

  00:38:41 SQL> select status from v$datafile where rownum<6;

  STATUS

  -------

  SYSTEM

  ONLINE

  ONLINE

  ONLINE

  ONLINE

  已选择5行。

  已用时间: 00: 00: 01.08

  00:38:43 SQL> set echo off

  00:38:58 SQL> @E:echo.sql

  STATUS

  ——-

  SYSTEM

  ONLINE

  ONLINE

  ONLINE

  ONLINE

  已选择5行。

  已用时间: 00: 00: 01.09

  00:39:08 SQL>

  SQL> set feedback on

  SQL> set colsep |SQL> set pagesize 10

  SQL> set serveroutput onSQL> set heading on

  SQL> set timing on

  SQL> set time on00:54:11

  SQL> SELECT FILE#, STATUS, ENABLED FROM V$DATAFILE;

  FILE#|STATUS |ENABLED———-|——-|———-

  1|SYSTEM |READ WRITE

  2|ONLINE |READ WRITE

  3|ONLINE |READ WRITE

  4|ONLINE |READ WRITE

  5|ONLINE |READ WRITE

  6|ONLINE |READ WRITE

  7|ONLINE |READ WRITE

  FILE#|STATUS |ENABLED———-|——-|———-

  9|ONLINE |READ WRITE

  10|ONLINE |READ WRITE

  11|ONLINE |READ WRITE

  12|ONLINE |READ WRITE11 rows selected.

  Elapsed: 00:00:01.0700:54:34

  SQL> DECLARE

  00:55:00 2 BEGIN

  00:55:00 3 DBMS_OUTPUT.PUT_LINE(’===This is dbms_output.put_line!===’);

  00:55:00 4 END;

  00:55:02 5 /

  ===This is dbms_output.put_line!===

  PL/SQL procedure successfully completed.

  Elapsed: 00:00:00.0200:55:05 SQL>

  SQL> set autotrace on

  SQL> SELECT E.LAST_NAME, D.DEPARTMENT_NAME, D.LOCATION_ID

  2 FROM HR.EMPLOYEES E

  3 JOIN HR.DEPARTMENTS D

  4 USING (DEPARTMENT_ID);

  LAST_NAME DEPARTMENT_NAME LOCATION_ID

  ————————- —————————— ———–

  King Executive 1700

  Kochhar Executive 1700

  De Haan Executive 1700

  Hunold IT 1400

  Ernst IT 1400……

  106 rows selected.

  Execution Plan

  ———————————————————-

  0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=106 Bytes=318

  0)

  1 0 HASH JOIN (Cost=5 Card=106 Bytes=3180)

  2 1 TABLE ACCESS (FULL) OF ‘DEPARTMENTS’ (Cost=2 Card=27 Byt

  es=513)

  3 1 TABLE ACCESS (FULL) OF ‘EMPLOYEES’ (Cost=2 Card=107 Byte

  s=1177)

  Statistics

  ———————————————————-

  7 recursive calls

  0 db block gets

  23 consistent gets

  12 physical reads

  0 redo size

  2801 bytes sent via SQL*Net to client

  580 bytes received via SQL*Net from client

  9 SQL*Net roundtrips to/from client

  0 sorts (memory)

  0 sorts (disk)

  106 rows processed

  SQL>
 
 
 
在大家写脚本的时候,我们常常用set语句在设置一些需要的格式规范。下面,列举了几个常见set语句的应用。 SQL> set echo on—————————————————设置运行命令是是否显示语句 SQL> set feedback on———————————————-设置显示“已选择XX行” SQL> set colsep | —————————————————设置列与列之间的分割符号 SQL> set pagesize 10———————————————–设置每一页的行数 SQL> SET SERVEROUTPUT ON——————————-设置允许显示输出类似dbms_output.putline SQL> set heading on————————————————设置显示列名 SQL> set timing on————————————————–设置显示“已用时间:XXXX” SQL> set time on—————————————————–设置显示当前时间 SQL> set autotrace on———————————————–设置允许对执行的sql进行分析 00:38:28 SQL> set echo on 00:38:37 SQL> @E:echo.sql 00:38:41 SQL> select status from v$datafile where rownum<6; STATUS ------- SYSTEM ONLINE ONLINE ONLINE ONLINE 已选择5行。 已用时间: 00: 00: 01.08 00:38:43 SQL> set echo off 00:38:58 SQL> @E:echo.sql STATUS ——- SYSTEM ONLINE ONLINE ONLINE ONLINE 已选择5行。 已用时间: 00: 00: 01.09 00:39:08 SQL> SQL> set feedback on SQL> set colsep |SQL> set pagesize 10 SQL> set serveroutput onSQL> set heading on SQL> set timing on SQL> set time on00:54:11 SQL> SELECT FILE#, STATUS, ENABLED FROM V$DATAFILE; FILE#|STATUS |ENABLED———-|——-|———- 1|SYSTEM |READ WRITE 2|ONLINE |READ WRITE 3|ONLINE |READ WRITE 4|ONLINE |READ WRITE 5|ONLINE |READ WRITE 6|ONLINE |READ WRITE 7|ONLINE |READ WRITE FILE#|STATUS |ENABLED———-|——-|———- 9|ONLINE |READ WRITE 10|ONLINE |READ WRITE 11|ONLINE |READ WRITE 12|ONLINE |READ WRITE11 rows selected. Elapsed: 00:00:01.0700:54:34 SQL> DECLARE 00:55:00 2 BEGIN 00:55:00 3 DBMS_OUTPUT.PUT_LINE(’===This is dbms_output.put_line!===’); 00:55:00 4 END; 00:55:02 5 / ===This is dbms_output.put_line!=== PL/SQL procedure successfully completed. Elapsed: 00:00:00.0200:55:05 SQL> SQL> set autotrace on SQL> SELECT E.LAST_NAME, D.DEPARTMENT_NAME, D.LOCATION_ID 2 FROM HR.EMPLOYEES E 3 JOIN HR.DEPARTMENTS D 4 USING (DEPARTMENT_ID); LAST_NAME DEPARTMENT_NAME LOCATION_ID ————————- —————————— ———– King Executive 1700 Kochhar Executive 1700 De Haan Executive 1700 Hunold IT 1400 Ernst IT 1400…… 106 rows selected. Execution Plan ———————————————————- 0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5 Card=106 Bytes=318 0) 1 0 HASH JOIN (Cost=5 Card=106 Bytes=3180) 2 1 TABLE ACCESS (FULL) OF ‘DEPARTMENTS’ (Cost=2 Card=27 Byt es=513) 3 1 TABLE ACCESS (FULL) OF ‘EMPLOYEES’ (Cost=2 Card=107 Byte s=1177) Statistics ———————————————————- 7 recursive calls 0 db block gets 23 consistent gets 12 physical reads 0 redo size 2801 bytes sent via SQL*Net to client 580 bytes received via SQL*Net from client 9 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 106 rows processed SQL>
󰈣󰈤
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
王朝网络微信公众号
微信扫码关注本站公众号 wangchaonetcn
 
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味著赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有