`
xitong
  • 浏览: 6291896 次
文章分类
社区版块
存档分类
最新评论

让Sql Plus环境变量的设置永久生效

 
阅读更多
每次打开Sql Plus都要设置环境变量,很麻烦,这里有个方法可以永久的保存你的环境变量的设置。
设置$ORACLE_HOME/sqlplus/admin/glogin.sql文件,在后边加上你自己的个性化设置。这样每次启动Sqlplus(不管是官方的sqlplus客户端,还是cmd命令行启动的sqlplus),都会读取glogin.sql的设置。

下边是我glogin.sql里的设置:
-------------------------------------------
prompt Loading PTIAN glogin.sql file...
--提示,在加载自定义的配置

set linesize 999
--如果字段都比较多,linesize要尽可能的大

set pagesize 30
--设置每页的行数,将 n 设为 0 可以不显示所有 headings, page breaks, titles, the initial blank line, and other formatting information
--Sets the heigth of a page to n. If n=0, the page's heigth is considered infinite. 

set wrap off
--取消折行,否则输出结果可能会很难看

set serveroutput on
--By default, SQL*PLUS doesn't read what a PL/SQL programm has written with dbms_output. With set serveroutput on, this behaviour is changed. 

set echo off
-- ECHO = ON will Display the command on screen (+ spool)
-- ECHO = OFF will Display the command on screen but not in spool files.
-- Interactive commands are always echoed to screen/spool.

set heading off
--是否显示查询结果的列名,如果设置为 off,将用空白行代替,如果要去除该空白行,可以用 set pagesize 0

set trimout on
--是否去掉屏幕上输出结果行末尾的空白字符

set trimspool on
--在 spool 到文件时是否去除输出结果中行末尾的空白字符,之前的隔行可以用该参数去掉,和该参数对应的是 trimout,后者用于屏幕输出

set timing on
--显示每个sql命令所花的时间

set verify on 
--当使用&变量时,提示变量修改之前和之后的值

set AUTOTRACE off
--Display a trace report for SELECT, INSERT, UPDATE or DELETE statements
--EXPLAIN shows the query execution path by performing an EXPLAIN PLAN.
--STATISTICS displays SQL statement statistics.
--Using ON or TRACEONLY with no explicit options defaults to EXPLAIN STATISTICS
-------------------------------------------


---------------------------------------------------------------------------------------------------------------------

SQL*PLUS - SET Statement

Syntax:

   SET option value

   SHO[W] option

Options: most of the options listed below have an abbreviated and a long form
           e.g. APPINFO or APPI will do the same thing

APPI[NFO] {ON|OFF|text}
   Application info for performance monitor (see DBMS_APPLICATION_INFO)

ARRAY[SIZE] {15|n}
   Fetch size (1 to 5000) the number of rows that will be retrieved in one go.

AUTO[COMMIT] {OFF|ON|IMM[EDIATE]|n} 
   Autocommit commits after each SQL command or PL/SQL block

AUTOP[RINT] {OFF|ON}
   Automatic PRINTing of bind variables.(see PRINT)

AUTORECOVERY [ON|OFF]
   Configure the RECOVER command to automatically apply 
   archived redo log files during recovery - without any user confirmation.

AUTOT[RACE] {OFF|ON|TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]] 
   Display a trace report for SELECT, INSERT, UPDATE or DELETE statements
   EXPLAIN shows the query execution path by performing an EXPLAIN PLAN.
   STATISTICS displays SQL statement statistics.
   Using ON or TRACEONLY with no explicit options defaults to EXPLAIN STATISTICS

BLO[CKTERMINATOR] {.|c|OFF|ON}
   Set the non-alphanumeric character used to end PL/SQL blocks to c

CMDS[EP] {;|c|OFF|ON}
   Change or enable command separator - default is a semicolon (;)

COLSEP { |text} 
   The text to be printed between SELECTed columns normally a space.

COM[PATIBILITY] {V5|V6|V7|V8|NATIVE}
   Version of oracle - see also init.ora COMPATIBILITY=
   You can set this back by up to 2 major versions e.g. Ora 9 supports 8 and 7

CON[CAT] {.|c|OFF|ON}
   termination character for substitution variable reference
   default is a period.

COPYC[OMMIT] {0|n}
   The COPY command will fetch n batches of data between commits.
   (n= 0 to 5000) the size of each fetch=ARRAYSIZE.
   If COPYCOMMIT = 0, COPY will commit just once - at the end.

COPYTYPECHECK {OFF|ON}
   Suppres the comparison of datatypes while inserting or appending to DB2

DEF[INE] {&|c|OFF|ON}
   c =  the char used to prefix substitution variables. 
   ON or OFF controls whether to replace substitution variables with their values.
   (this overrides SET SCAN) 

DESCRIBE [DEPTH {1|n|ALL}][LINENUM {ON|OFF}][INDENT {ON|OFF}]
   Sets the depth of the level to which you can recursively describe an object
   (1 to 50) see the DESCRIBE command 

ECHO {OFF|ON}
   Display commands as they are executed

EMB[EDDED] {OFF|ON}
   OFF = report printing will start at the top of a new page.
   ON = report printing may begin anywhere on a page.
 
ESC[APE] {\|c|OFF|ON} 
    Defines the escape character. OFF undefines. ON enables. 

FEED[BACK] {6|n|OFF|ON}
   Display the number of records returned (when rows >= n )
   OFF (or n=0) will turn the display off
   ON will set n=1

FLAGGER {OFF|ENTRY|INTERMED[IATE]|FULL}
   Checks to make sure that SQL statements conform to the ANSI/ISO SQL92 standard.
   non-standard constructs are flagged as errors and displayed 
   See also ALTER SESSION SET FLAGGER.

FLU[SH] {OFF|ON}
   Buffer display output (OS)
   (no longer used in Oracle 9)

HEA[DING] {OFF|ON}
   print column headings

HEADS[EP] {||c|OFF|ON}
   Define the heading separator character (used to divide a column heading onto > one line.)
   OFF will actually print the heading separator char
   see also: COLUMN command

INSTANCE [instance_path|LOCAL] 
   Change the default instance for your session, this command may only be issued when 
   not already connected and requires Net8

LIN[ESIZE] {150|n} 
   Width of a line (before wrapping to the next line)
   Earlier versions default to 80, Oracle 9 is 150

LOBOF[FSET] {n|1}
   Starting position from which CLOB and NCLOB data is retrieved and displayed

LOGSOURCE [pathname] 
   Change the location from which archive logs are retrieved during recovery
   normally taken from LOG_ARCHIVE_DEST 

LONG {80|n}
   Set the maximum width (in chars) for displaying and copying LONG values.

LONGC[HUNKSIZE] {80|n}
   Set the fetch size (in chars) for retrieving LONG values.

MARK[UP] HTML [ON|OFF]
  [HEAD text] [BODY text] [TABLE text] 
     [ENTMAP {ON|OFF}][SPOOL {ON|OFF}]
        [PRE[FORMAT] {ON|OFF}]
   Output HTML text, which is the output used by iSQL*Plus.

NEWP[AGE] {1|n}
   The number of blank lines between the top of each page and the top title.
   0 = a formfeed between pages.

NULL text
   Replace a null value with 'text'
   The NULL clause of the COLUMN command will override this for a given column.

NUMF[ORMAT] format
   The default number format.
   see COLUMN FORMAT. 

NUM[WIDTH] {10|n}
   The default width for displaying numbers.

PAGES[IZE] {14|n}
   The height of the page - number of lines.
   0 will suppress all headings, page breaks, titles

PAU[SE] {OFF|ON|text}
   press [Return] after each page
   enclose 'text' in single quotes

RECSEP {WR[APPED]|EA[CH]|OFF}
   Print a single line of the RECSEPCHAR between each record.
   WRAPPED = print only for wrapped lines
   EACH=print for every row

RECSEPCHAR {_|c}
   Define the RECSEPCHAR character, default= ' '

SCAN {OFF|ON}
   OFF = disable substitution variables and parameters

SERVEROUT[PUT] {OFF|ON} [SIZE n] [FOR[MAT] {WRA[PPED]|WOR[D_WRAPPED]|TRU[NCATED]}] 
   whether to display the output of stored procedures (or PL/SQL blocks)
   i.e., DBMS_OUTPUT.PUT_LINE

   SIZE = buffer size (2000-1,000,000) bytes

SHOW[MODE] {OFF|ON}
   Display old and new settings of a system variable

SPA[CE] {1|n}
   The number of spaces between columns in output (1-10)

SQLBL[ANKLINES] {ON|OFF} 
   Allow blank lines within an SQL command. reverts to OFF after the curent command/block.

SQLC[ASE] {MIX[ED]|LO[WER]|UP[PER]} 
   Convert the case of SQL commands and PL/SQL blocks
   (but not the SQL buffer itself)

SQLPLUSCOMPAT[IBILITY] {x.y[.z]}
  Set the behavior or output format of VARIABLE to that of the
  release or version specified by x.y[.z]. 

SQLCO[NTINUE] {> |text}
   Continuation prompt (used when a command is continued on an additional line using a hyphen -)

SQLN[UMBER] {OFF|ON}
   Set the prompt for the second and subsequent lines of a command or PL/SQL block.
   ON = set the SQL prompt = the line number.
   OFF = set the SQL prompt = SQLPROMPT.

SQLPRE[FIX] {#|c}
   set a non-alphanumeric prefix char for immediately executing one line of SQL (#)

SQLP[ROMPT] {SQL>|text}
   Set the command prompt.

SQLT[ERMINATOR] {;|c|OFF|ON}| 
   Set the char used to end and execute SQL commands to c. 
   OFF disables the command terminator - use an empty line instead.
   ON resets the terminator to the default semicolon (;).
 
SUF[FIX] {SQL|text} 
   Default file extension for SQL scripts

TAB {OFF|ON}
   Format white space in terminal output.  
   OFF = use spaces to format white space.
   ON = use the TAB char.
   Note this does not apply to spooled output files.
   The default is system-dependent. Enter SHOW TAB to see the default value. 

TERM[OUT] {OFF|ON}
   OFF suppresses the display of output from a command file
   ON displays the output.
   TERMOUT OFF does not affect the output from commands entered interactively. 

TI[ME] {OFF|ON}
   Display the time at the command prompt.

TIMI[NG] {OFF|ON}
   ON = display timing statistics for each SQL command or PL/SQL block run.
   OFF = suppress timing statistics

TRIM[OUT] {OFF|ON}
   Display trailing blanks at the end of each line.
   ON = remove blanks, improving performance
   OFF = display blanks. 
   This does not affect spooled output.
   SQL*Plus ignores TRIMOUT ON unless you set TAB ON.

TRIMS[POOL] {ON|OFF}
   Allows trailing blanks at the end of each spooled line.
   This does not affect terminal output.

UND[ERLINE] {-|c|ON|OFF}
   Set the char used to underline column headings to c.

VER[IFY] {OFF|ON}
   ON = list the text of a command before and after replacing substitution variables with values.
   OFF = dont display the command.

WRA[P] {OFF|ON}
   Controls whether to truncate or wrap the display of long lines. 
   OFF = truncate 
   ON = wrap to the next line
   The COLUMN command (WRAPPED and TRUNCATED clause) can override this for specific columns. 


The items in Gray on this page are deprecated from Oracle 9 onwards - also note that several of the options above have 'gone missing' from the official documentation set - HELP SET is a more accurate reference.

Get a list of these SET options in sql*plus with the command:
SQLPLUS> HELP SET

Example

A demo SQL script with the most common SET options


分享到:
评论

相关推荐

    PL/SQL基础

    为了在SQL*Plus环境下使用DBMS_OUTPUT.PUT_LINE函数的屏幕输出功能,需要执行SET SERVEROUTPUT ON命令,可以选择性地设置一个输出缓冲区大小,范围在2000到1000000之间,默认为2000。如果预期输出内容较多,需要设置...

    Oracle中serveroutput参数一次设置永久保存方法

    例如,你还可以在`glogin.sql`中设置其他常用环境变量,如NLS_DATE_FORMAT,或者设置默认的编码方式等。 总之,通过上述步骤,你可以在Oracle环境中确保`serveroutput`参数的设置在每次打开SQL*Plus时都是开启状态...

    ORACLE数据库字符集设置

    如果希望永久生效,可以将这行命令添加到用户的`.bash_profile`文件中。 #### 四、解决字符集问题的方法 当遇到字符集问题时,可以尝试以下几种方法进行解决: 1. **更改数据库字符集**:如果需要更改整个数据库...

    CentOS6.2安装Oracle客户端

    如果提示找不到SQL*Plus,检查是否正确设置了`PATH`环境变量,或者确认环境变量配置是否已生效。 总结来说,成功安装和配置Oracle客户端在CentOS6.2上需要下载RPM包,通过`rpm`命令安装,配置TNS,设置环境变量,并...

    liunx oracle-instantclient9版本basic、sqlolus、tool安装包

    3. **设置环境变量**: 安装完成后,需要配置`LD_LIBRARY_PATH`环境变量,使其指向Oracle Instant Client的库目录,这样系统才能找到必要的库文件: ```bash export LD_LIBRARY_PATH=/path/to/oracle/instantclient...

    oracle中文乱码的解决方法

    为了永久性地改变一个用户的环境变量,需要编辑用户的`~/.bash_profile`文件。在这个文件中添加`NLS_LANG`的设置,并通过`source .bash_profile`命令使更改生效。这样每次用户登录时,新的`NLS_LANG`设置都会被加载...

    instantclient-basic-linux.x64-12.1.0.2.0.zip

    5. 如果需要永久生效,将上述环境变量添加到用户的`.bashrc`或`.bash_profile`文件中。 通过这些步骤,你就可以在Linux系统上使用Oracle Instant Client与远程Oracle数据库进行通信,无论是执行SQL查询、开发应用...

    OraclePro*c编程(内部培训资料)

    `COMMIT` 语句用于提交当前事务中的更改,使其永久生效。 ##### 5.6 使用 SAVEPOINT 语句 `SAVEPOINT` 语句用于在事务中创建一个保存点,以便在需要时回滚到该点。 ##### 5.7 ROLLBACK 语句 `ROLLBACK` 语句用于...

    Oracle proc

    SPOOL是Oracle SQL*Plus的一个特性,用于将查询结果重定向到文件。Pro*C/C++程序通常不会使用这个功能,因为它不是一个数据库操作的一部分。 ##### 3.6.9 Pro*C/C++支持结构作为宿主变量么? 是的,Pro*C/C++支持...

    RedHat 6.2安装Oracle 11g详细文档

    安装完成后,还需要进行额外的配置,包括初始化数据库、创建监听器、设置环境变量,以及启动和停止数据库服务。这些步骤可以通过Oracle提供的配置助手或手动执行SQL脚本来完成。 对于Oracle数据库的管理,了解如何...

    Centos7.5安装Oracle11.2.1.docx

    安装完成后,还需要进行一些后安装的配置工作,如初始化数据库、设置环境变量、创建监听器配置文件等。确保所有服务都已启动并运行正常,你可以通过SQL*Plus等工具连接到新创建的数据库进行进一步的管理和测试。 总...

Global site tag (gtag.js) - Google Analytics