Oracle SQL Plus The Definitive Guide- P44 pdf

10 282 0
Oracle SQL Plus The Definitive Guide- P44 pdf

Đang tải... (xem toàn văn)

Thông tin tài liệu

< previous page page_393 next page > Page 393 SET SQLPROMPT &&prompt_dbname> SET TERMOUT ON These commands will set your prompt to the global database name. The global name comes from the global_name view, and may or may not be the same as the connect string you used to connect to the database. By placing these commands in your login.sql file, you ensure that the prompt will be set automatically, based on the database you are connecting to, whenever you start SQL*Plus. LOGIN.SQL is executed only when SQL*Plus starts. Using the CONNECT command to connect to another database will not cause the prompt to be changed to reflect the new connection. The login.sql file was discussed earlier in this chapter, in the section titled The Site and User Profiles. SET TERMOUT Controls whether or not SQL*Plus displays output generated by SQL statements, PL/SQL blocks, and SQL*Plus commands. This setting only applies when SQL*Plus is executing a script file. SQL*Puls always displays output from commands entered interactively. SET TERM[OUT] {OFF¦ON} where: SET TERM[OUT] Is the command, which may be abbreviated to SET TERM. OFF Turns terminal output off. ON Turns terminal output on. This is the default setting. Terminal output is often turned off while a command file is running to keep the user's screen from becoming cluttered with query output and feedback messages. SET TIME The SET TIME command controls whether or not SQL*Plus displays the current time with each command prompt: SET TI[ME] {OFF ¦ON} < previous page page_393 next page > < previous page page_394 next page > Page 394 where: SET TI[ME] Is the command, which may be abbreviated to SET TI. OFF Keeps the time from being displayed with the prompt. This is the default setting. ON Causes the time to be displayed as part of each prompt. The following example shows the effect of issuing a SET TIME ON command: SQL> SET TIME ON 22:44:41 SQL> SET VERIFY The VERIFY setting controls whether or not SQL*Plus displays before and after images of each line that contains a substitution variable: SET VER[IFY] {OFF¦ON} where: SET VER[IFY] Is the command, which may be abbreviated to SET VER. OFF Turns verification off. ON Turns verification on. Lines containing substitution variables will be displayed before and after the substitution occurs. This is the default setting. Verification is done only on lines that are part of a SQL statement or a PL/SQL block. When substitution occurs in a SQL*Plus command, before and after images are never displayed. The following example shows what verification looks like: SQL> DEFINE dummy_char = X SQL> SELECT * FROM dual 2 WHERE dummy = &&dummy_char; old 2: where dummy = &&dummy_char new 2: where dummy = X D - X Notice that line 2, which contained the reference to the&&dummy_char substitution variable, was displayed both before and after the reference to the variable was < previous page page_394 next page > < previous page page_395 next page > Page 395 replaced by its value. If you don't like this display, you can turn it off with SET VERIFY OFF. Input Settings Input settings control some aspects of the way commands are entered. Many of these settings allow you to specify alternative characters for command separators, PL/SQL block terminators, continuation prompts, and so forth. Other settings let you force commands to be uppercased, and allow you to enter blank lines as part of an SQL statement. Here is complete list of input settings: BLOCKTERMINATOR Specifies the character used to terminate entry of a PL/SQL block. BUFFER Allows you edit using multiple buffers. CMDSEP Controls whether or not you may enter multiple SQL*Plus commands on one line, and also specifies the character used to separate those commands. SQLBLANKUNES Controls whether or not you may enter blank lines as part of a SQL statement. SQLCASE Controls automatic case conversion of SQL statements and PL/SQL blocks. SQLCONTINUE Contains the text of the prompt you get when you use the SQL*Plus continuation character to continue a long command to a new line. SQLNUMBER Controls whether or not SQL*Plus uses the line number as a prompt when you enter a multiline SQL statement. SQLPREFIX Specifies the SQL*Plus prefix character, which allows you to execute a SQL*Plus command while entering a SQL statement or PL/SQL block into the buffer. SQLTERMINATOR Controls whether or not you can use a semicolon to execute a SQL statement, and also lets you specify a different character to be used for that purpose. SUFFIX Contains the default extension used for command files. The following sections describe each of these settings. < previous page page_395 next page > < previous page page_396 next page > Page 396 BLOCKTERMINATOR The BLOCKTERMINATOR setting controls the character used to terminate a PL/ SQL block that is being entered into the buffer for editing: SET BLO [CKTERMINATOR] block_term_char where: SET BLO[CKTERMINATOR] Is the command, which may be abbreviated to SET BLO. block_term_char Is the new terminator character for use when entering PL/SQL blocks. The default value is a period. When you enter a PL/SQL block into the buffer, you need a way to tell SQL*Plus when the block has ended. By default, the period can be used for this purpose, but you can use the SET BLOCKTERMINATOR command to change that. The following example shows how this is done by changing the block terminator to a pound sign character: SQL> SET BLOCKTERMINATOR # SQL> BEGIN 2 DBMS_OUTPUT.PUT_LINE (PL/SQL is powerful.); 3 END; 4 # SQL> Terminating the block this way leaves it in the buffer for you to edit. Do not confuse this with the use of the slash command, which both terminates and executes a block. Changing the terminator to a slash character, by using SET BLOCKTERMINATOR /, prevents you from subsequently using the / character to execute the contents of the buffer. BUFFER The SET BUFFER command allows you to switch to another buffer for editing purposes: SET BUF[FER] {buffer_name¦SQL} where: SET BUF[FER] Is the command, which may be abbreviated to SET BUF. < previous page page_396 next page > < previous page page_397 next page > Page 397 buffer_name Is the name of the buffer you want to edit. You can make up any name you like. If the named buffer does not yet exist, SQL*Plus will create it for you. SQL Switches you to the SQL buffer. This is the default setting. The SQL buffer is the one used when you type in a SQL statement at the command prompt, and is also the only buffer from which you can execute a SQL statement (or PL/ SQL block). Changing the buffer has limited use, because you can only execute a statement from the SQL buffer. The GET, SAVE, and EDIT commands work, as do all the editing commands. The following example shows a second buffer being used to edit a statement that exists in a text file without disturbing the statement currently in the SQL buffer: SQL> SHOW BUFFER buffer SQL SQL> SELECT * FROM employee 2 SQL> L 1* SELECT * FROM employee SQL> SELECT BUFFER project SQL> L No lines in PROJECT buffer. SQL> GET c:\a\project.sql 1* SELECT * FROM project SQL> I 2 WHERE project_budget > 1000000 3 SQL> SAVE c:\a\project.sql REPLACE Wrote file c:\a\project.sql SQL> SET BUFFER SQL SQL> L 1* SELECT * FROM employee SQL> As you can see, using a second buffer made it possible to edit the SQL statement in the project.sql file without disturbing the statement currently in the SQL buffer. Of course, you could do the same thing more easily with the EDIT command, so SET BUFFER isn't used much anymore. CMDSEP The SET CMDSEP command controls whether or not you can enter multiple commands on one line. The commands in question must both be SQL*Plus commands. SET CMDSEP is also used to change the character used to separate these commands: SET CMDS[EP] {OFF¦ON¦separator_char < previous page page_397 next page > < previous page page_398 next page > Page 398 where: SETCMDS[EP] Is the command, which may be abbreviated to SET CMDS. OFF Turns the feature off, requiring you to enter each command on a separate line. This is the default setting. ON Allows you to enter multiple SQL*Plus commands on one line, and resets the separator character back to the default of a semicolon. separator_char Causes SQL*Plus to recognize the specified character as the command separator. You won't be allowed to make the command separator an alphabetic, numeric, or space character. This character may optionally be enclosed in either single or double quotes. In some cases, such as when you change it to a semicolon, you will need the quotes. The following example turns this feature on, sets the separator character to an exclamation point, and shows how two commands may be placed on one line: SQL> SET CMDSEP ON SQL> SET CMDSEP ! SQL> SHOW CMDSEP! SHOW BUFFER! cmdsep ! (hex 21) buffer SQL SQL> SQLBLANKLINES The SQLBLANKLINES setting is a new feature in version 8.1 of SQL*Plus, and allows SQL statements to contain embedded blank lines: SET SQLBLANKLINES {OFF¦ON} where: SET SQLBLANKLINES Is the command. OFF Turns this feature off. This is the default setting, and does not allow a SQL statement to have embedded blank lines. ON Turns the feature on, and allows you to enter a SQL statement with an embedded blank line. < previous page page_398 next page > < previous page page_399 next page > Page 399 Pressing ENTER on a blank line while typing a SQL statement into SQL*Plus normally signals the end of the statement. The statement is then placed into the buffer, and you then have the option of making further edits or of executing the statement. Turning SQLBLANKLINES on allows you to put a blank line in the middle of your statement, as the following example demonstrates: SQL> SET SQLBLANKLINES ON SQL> SELECT 2 * 3 4 FROM EMPLOYEE 5 SQL> This feature was added to SQL*Plusto allow it to execute existing Server Manager scripts, such as CATPROC.SQL, without having to go through and modify all the SQL statements in those scripts. Unlike SQL*Plus, the Server Manager utility allows blank lines in a SQL statement. Oracle plans to desupport Server Manager at some future date, leaving SQL*Plus as the only command-line interface into the Oracle database. SQLCASE The SQLCASE setting controls whether or not SQL*Plus automatically uppercases or lowercases SQL statements and PL/SQL blocks as they are transmitted to the server for execution: SET SQLC[ASE] {MIXED¦UPPER¦LOWER} where: SET SQLC[ASE] Is the command, which may be abbreviate to SET SQLC. MIXED Leaves each statement just as you entered it. This is the default setting. UPPER Uppercases each statement, including any quoted text literals. LOWER Lowercases each statement, including any quoted text literals. Be careful when changing this setting. Any case conversions SQL*Plus does will affect not only your SQL statement keywords, but also any quoted text literals as well. This is seldom desirable behavior. The following example demonstrates this. < previous page page_399 next page > < previous page page_400 next page > Page 400 SQL> SET SQLCASE UPPER SQL> SELECT * FROM dual WHERE dummy=x; D - X You can see that the SELECT statement succeeded, even though the lowercase x in the WHERE clause does not match the uppercase X in the dummy column. Case conversion occurs when the statement is transmitted to the database server. The contents of the buffer will always reflect what you actually typed. SQLCONTINUE The SQLCONTINUE setting controls the prompt used when you continue a statement to a second line, using the SQL*Plus continuation character: SET SQLCO[NTINUE] continuation_prompt where: SET SQLCO[NTINUE] Is the command, which may be abbreviated to SET SQLCO. continuation_prompt Is the new continuation prompt. The default value is >the greater-than character. The prompt may optionally be enclosed in either single or double quotes. The following example shows the effect of changing this setting: SQL> SET SQLCONTINUE continue > SQL> DESCRIBE - Continue > Notice that the SQL*Plus continuation character, a dash, was used following the DESCRIBE command. The continuation prompt is used only when you use the continuation character to continue a command to a new line. It is not used when you enter a multiline SQL statement. SQLNUMBER The SQLNUMBER setting controls whether or not SQL*Plus uses the line number as a prompt when you enter a multiline SQL statement: SET SQLN[UMBER] {OFF¦ON} where: SET SQLN[UMBER] Is the command, which may be abbreviated to SET SQLN. < previous page page_400 next page > < previous page page_401 next page > Page 401 OFF Causes SQL*Plus to use the same prompt for all lines of a SQL statement or PL/SQL block. ON Causes SQL*Plus to use the line number as the prompt for the second, and subsequent, lines of an SQL statement or PL/ SQL block. This is the default setting. The following example shows the difference between the ON and OFF settings: SQL> SET SQLNUMBER ON SQL> SELECT 2 * 3 FROM dual 4 SQL> SET SQLNUMBER OFF SQL> SELECT SQL> * SQL> FROM dual SQL> I can't imagine any reason to ever turn this setting off. Look at the first and second statements in the example. It's immediately obvious that the three lines of the first query all belong together as one statement. This is not so obvious with the second statementyou have to think about it a bit. The visual cue provided by the line numbers is missing, making you take more time to figure out what you are really looking at. SQLPREFIX The SQLPREFIX setting controls the SQL*Plus prefix character. The prefix character allows you to execute a SQL*Plus command while in the middle of entering an SQL statement (or PL/SQL block). SET SQLPRE[FIX] prefix_char where: Is the command, which may be abbreviated to SET SQLPRE. prefix_char Is the new prefix character. The default prefix character is a pound sign. This may optionally be enclosed in either single or double quotes. The following example shows how the prefix character is used by using it to execute a DESCRIBE command while entering a SELECT statement: SQL> SELECT 2 #DESCRIBE EMPLOYEE < previous page page_401 next page > < previous page page_402 next page > Page 402 Name Null? Type EMPLOYEE_ID NOTNULL NUMBER EMPLOYEE_NAME VARCHAR2(40) EMPLOYEE_HIRE_DATE DATE EMPLOYEE_TERMINATION_DATE DATE EMPLOYEE_BILLING_RATE NUMBER 2 employee_id, employee_name 3 FROM employee 4 This ability to execute a SQL*Plus command (and it must be a SQL*Plus command) while entering a SQL statement can come in handy when you need to quickly refresh your memory regarding the column names in the table. SQLTERMINATOR The SQLTERMINATOR setting controls whether or not SQL*Plus allows you to use a semicolon to terminate and execute a SQL statement. This setting also controls the specific character used for this purpose. SET SQLT[ERMINATOR] {OFF¦ON¦ term_char} where: SET SQLT[ERMINATOR] Is the command, which may be abbreviated to SET SQLT. OFF Turns off the feature that allows you to terminate and execute a SQL statement using a semicolon or other character. ON Turns this feature on, and resets the terminator character to the default value of a semicolon. term_char Is the character you want to use as a statement terminator. This may optionally be enclosed in single or double quotes. The following example changes the terminator character to a percent sign and uses it to terminate and execute a SELECT statement: SQL> SET SQLTERMINATOR % SQL> SELECT employee_name FROM employee% EMPLOYEE_NAME Bohdan khmelnytsky Pavlo Chubynsky Ivan Mazepa Taras Shevchenko < previous page page_402 next page > . a SQL statement into SQL* Plus normally signals the end of the statement. The statement is then placed into the buffer, and you then have the option of making further edits or of executing the. into the Oracle database. SQLCASE The SQLCASE setting controls whether or not SQL* Plus automatically uppercases or lowercases SQL statements and PL /SQL blocks as they are transmitted to the server. If the named buffer does not yet exist, SQL* Plus will create it for you. SQL Switches you to the SQL buffer. This is the default setting. The SQL buffer is the one used when you type in a SQL

Ngày đăng: 05/07/2014, 04:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan