Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
2
Добавлен:
01.07.2025
Размер:
5.06 Mб
Скачать

2.1.5.1 Setting your preferences

As with many command-line environments, you can change the behavior of SQL*Plus by changing the value of some of its built-in variables and settings. We've already seen one example, the SET SERVEROUTPUT statement. There are many options on the SQL*Plus SET command, such as SET SUFFIX (changes the default file extension) and SET LINESIZE n (sets the maximum number of characters in each displayed line before wrapping). To see all the SET values applicable to your current session, use the command:

SQL> SHOW ALL

If you're using the GUI version of SQL*Plus, you can also view and set these preferences by choosing the Options Environment menu option.

SQL*Plus also has the ability to create and manipulate its own in-memory variables, and it sets aside a few special variables that will affect its behavior. Actually, there are two separate types of variables in SQL*Plus: DEFINEs and bind variables. To assign a value to a DEFINE variable, you can use the DEFINE command:

SQL> DEFINE x = "the answer is 42"

To view the value of x, specify:

SQL> DEFINE x

DEFINE X = "the answer is 42" (CHAR)

You would refer to such a variable using an ampersand (&). SQL*Plus does a simple substitution before sending the statement to Oracle, so you may need single-quote marks around it.

SELECT '&x' FROM DUAL;

For bind variables, you firstdeclare the variable. Then you can use it in PL/SQL, and display it using the SQL*Plus PRINT command:

SQL> VARIABLE x VARCHAR2(10)

SQL> BEGIN

2 :x := 'hullo';

3 END;

4 /

PL/SQL procedure successfully completed.

SQL> PRINT :x

X

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

hullo

This can get a little bit confusing because there are now two different "x" variables, one that has been DEFINEd and one that has been declared.

SQL> SELECT :x, '&x' FROM DUAL;

old 1: SELECT :x, '&x' FROM DUAL

new 1: SELECT :x, 'the answer is 42' FROM DUAL

:X 'THEANSWERIS42'

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

hullo the answer is 42

Just remember that DEFINEs are always character strings expanded by SQL*Plus, and declared variables are used as true bind variables in SQL and PL/SQL.

The "Current Directory" in SQL*Plus

Any time you launchSQL*Plus from an operating system command prompt, SQL*Plus treats the operating system's current directory as its own current directory. In other words, if you start up using:

C:\BILL\FILES> sqlplus

then any file operations inside SQL*Plus (like opening or running a script) will default to the directory C:\BILL\FILES.

The same is true if you start the GUI version from the operating system prompt with the command:

C:\BILL\FILES> sqlplusw

If you use a shortcut or menu option to launch SQL*Plus, the "current" directory is the one the operating system associates with the launch mechanism. So how would you change the current directory once you're inside SQL*Plus? Depends on the version. In the console program, you can't do it. You have to exit, change directories in the operating system, and restart SQL*Plus. In the GUI version, though, completing a File Open or File Save menu command will have the side effect of changing the current directory. If you're running iSQL*Plus, the concept of the current directory is relevant only in the browser's file save and retrieve dialogs, so the behavior will vary by browser.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]