Thursday, April 7, 2016

Oracle FAQs - Part II

ORACLE FREQUENTLY ASKED QUESTIONS - II

What are the Built-ins used for sending Parameters to forms? 
You can pass parameter values to a form when an application executes the call_form, New_form, Open_form or Run_product.

Can you have more than one content canvas view attached with a window? 
Yes. Each window you create must have at least one content canvas view assigned to it. You can also create a window that has manipulated content canvas view. At run time only one of the content canvas views assign to a window is displayed at a time.

Is the After report trigger fired if the report execution fails? 
Yes.

Does a before form trigger fire when the parameter form is suppressed? 
Yes.

What is SGA?
The System Global Area in an Oracle database is the area in memory to facilitate the transfer of information between users. It holds the most recently requested structural information between users. It holds the most recently requested structural information about the database. The structure is database buffers, dictionary cache, redo log buffer and shared pool area.

What is a shared pool? 
The data dictionary cache is stored in an area in SGA called the shared pool. This will allow sharing of parsed SQL statements among concurrent users.

What is mean by Program Global Area (PGA)? 
It is area in memory that is used by a single Oracle user process.

What is a data segment? 
Data segment are the physical areas within a database block in which the data associated with tables and clusters are stored.
What are the factors causing the reparsing of SQL statements in SGA? 
Due to insufficient shared pool size.
Monitor the ratio of the reloads takes place while executing SQL statements. If the ratio is greater than 1 then increase the SHARED_POOL_SIZE.

What are clusters? 
Clusters are groups of one or more tables physically stores together to share common columns and are often used together.

What is cluster key? 
The related columns of the tables in a cluster are called the cluster key.

Do a view contain data? 
Views do not contain or store data.

What is user Account in Oracle database? 
A user account is not a physical structure in database but it is having important relationship to the objects in the database and will be having certain privileges.

How will you enforce security using stored procedures? 
Don't grant user access directly to tables within the application. Instead grant the ability to access the procedures that access the tables. When procedure executed it will execute the privilege of procedures owner. Users cannot access tables except via the procedure.

What are the dictionary tables used to monitor a database space? 
DBA_FREE_SPACE
DBA_SEGMENTS
DBA_DATA_FILES.

Can a property clause itself be based on a property clause? 
Yes

If a parameter is used in a query without being previously defined, what diff. exist between report 2.0 and 2.5 when the query is applied? 
While both reports 2.0 and 2.5 create the parameter, report 2.5 gives a message that a bind parameter has been created.

What are the sql clauses supported in the link property sheet? 
Where start with having.
What is trigger associated with the timer? 
When-timer-expired.

What are the trigger associated with image items? 
When-image-activated fires when the operators double clicks on an image item when-image-pressed fires when an operator clicks or double clicks on an image item

What are the different windows events activated at runtimes? 
When_window_activated
When_window_closed
When_window_deactivated
When_window_resized
Within this triggers, you can examine the built in system variable system. event_window to determine the name of the window for which the trigger fired.

When do you use data parameter type? 
When the value of a data parameter being passed to a called product is always the name of the record group defined in the current form. Data parameters are used to pass data to products invoked with the run_product built-in subprogram.

What is difference between open_form and call_form? 
When one form invokes another form by executing open_form the first form remains displayed, and operators can navigate between the forms as desired. When one form invokes another form by executing call_form, the called form is modal with respect to the calling form. That is, any windows that belong to the calling form are disabled, and operators cannot navigate to them until they first exit the called form.

What is new_form built-in? 
When one form invokes another form by executing new_form oracle form exits the first form and releases its memory before loading the new form calling new form completely replace the first with the second. If there are changes pending in the first form, the operator will be prompted to save them before the new form is loaded.

What is the "LOV of Validation" Property of an item? What is the use of it? 
When LOV for Validation is set to True, Oracle Forms compares the current value of the text item to the values in the first column displayed in the LOV. Whenever the validation event occurs. If the value in the text item matches one of the values in the first column of the LOV, validation succeeds, the LOV is not displayed, and processing continues normally. If the value in the text item does not match one of the values in the first column of the LOV, Oracle Forms displays the LOV and uses the text item value as the search criteria to automatically reduce the list.

What is the diff. when Flex mode is mode on and when it is off? 
When flex mode is on, reports automatically resizes the parent when the child is resized.

What is the diff. when confine mode is on and when it is off? 
When confine mode is on, an object cannot be moved outside its parent in the layout.

What are visual attributes? 
Visual attributes are the font, color, pattern proprieties that you set for form and menu objects that appear in your application interface.

Which of the two views should objects according to possession? 
View by structure.

What are the two types of views available in the object navigator (specific to report 2.5)? 
View by structure and view by type.

What are the vbx controls? 
Vbx control provide a simple method of building and enhancing user interfaces. The controls can use to obtain user inputs and display program outputs.vbx control where originally develop as extensions for the MS visual basic environments and include such items as sliders, rides and knobs.

What is the use of transactional triggers? 
Using transactional triggers we can control or modify the default functionality of the oracle forms.

How do you create a new session while open a new form? 
Using open_form built-in setting the session option Ex. Open_form ('Stocks ', active, session). When invoke the multiple forms with open form and call_form in the same application, state whether the following are true/False

What are the ways to monitor the performance of the report? 
Use reports profile executable statement. Use SQL trace facility.

If two groups are not linked in the data model editor, what is the hierarchy between them? 
Two group that is above are the left most rank higher than the group that is to right or below it.

An open form cannot be execute the call_form procedure if you chain of called forms has been initiated by another open form?
True

Explain about horizontal, vertical tool bar canvas views? 
Tool bar canvas views are used to create tool bars for individual windows. Horizontal tool bars are display at the top of a window, just under its menu bar. Vertical Tool bars are displayed along the left side of a window

What is the purpose of the product order option in the column property sheet? 
To specify the order of individual group evaluation in a cross products.

What is the use of image_zoom built-in? 
To manipulate images in image items.

How do you reference a parameter indirectly? 
To indirectly reference a parameter use the NAME IN, COPY 'built-ins to indirectly set and reference the parameters value' Example name_in ('capital parameter my param'), Copy ('SURESH’, ‘Parameter my_param')

What is a timer? 
Timer is an "internal time clock" that you can programmatically create to perform an action each time the times.

What are the two phases of block coordination? 
There are two phases of block coordination: the clear phase and the population phase. During, the clear phase, Oracle Forms navigates internally to the detail block and flushes the obsolete detail records. During the population phase, Oracle Forms issues a SELECT statement to repopulate the detail block with detail records associated with the new master record. These operations are accomplished through the execution of triggers.


What are Most Common types of Complex master-detail relationships? 
There are three most common types of complex master-detail relationships:
master with dependent details
master with independent details
detail with two masters

What is a text list? 
The text list style list item appears as a rectangular box which displays the fixed number of values. When the text list contains values that cannot be displayed, a vertical scroll bar appears, allowing the operator to view and select undisplayed values.

What is term? 
The term is terminal definition file that describes the terminal form which you are using r20run.

What is use of term? 
The term file which key is correspond to which oracle report functions.

What is pop list? 
The pop list style list item appears initially as a single field (similar to a text item field). When the operator selects the list icon, a list of available choices appears.

What is the maximum no of chars the parameter can store? 
The maximum no of chars the parameter can store is only valid for char parameters, which can be up to 64K. No parameters default to 23Bytes and Date parameter default to 7Bytes.

What are the default extensions of the files created by library module? 
The default file extensions indicate the library module type and storage format .pll - pl/sql library module binary

What are the Coordination Properties in a Master-Detail relationship? 
The coordination properties are
Deferred
Auto-Query
These Properties determine when the population phase of block
coordination should occur.

How do you display console on a window? 
The console includes the status line and message line, and is displayed at the bottom of the window to which it is assigned. To specify that the console should be displayed, set the console window form property to the name of any window in the form. To include the console, set console window to Null.

What are the different Parameter types? 
Text ParametersData Parameters
State any three mouse events system variables? 
System.mouse_button_pressedSystem.mouse_button_shift

What are the types of calculated columns available? 
Summary, Formula, Placeholder column.

Explain about stacked canvas views? 
Stacked canvas view is displayed in a window on top of, or "stacked" on the content canvas view assigned to that same window. Stacked canvas views obscure some part of the underlying content canvas view, and or often shown and hidden programmatically.

How does one do off-line database backups? (For DBA)
Shut down the database from sqlplus or server manager. Backup all files to secondary storage (eg. tapes). Ensure that you backup all data files, all control files and all log files. When completed, restart your database.
Do the following queries to get a list of all files that needs to be backed up:
select name from sys.v_$datafile;
select member from sys.v_$logfile;
select name from sys.v_$controlfile;
Sometimes Oracle takes forever to shutdown with the "immediate" option. As workaround to this problem, shutdown using these commands:
alter system checkpoint;
shutdown abort
startup restrict
shutdown immediate
Note that if you database is in ARCHIVELOG mode, one can still use archived log files to roll forward from an off-line backup. If you cannot take your database down for a cold (off-line) backup at a convenient time, switch your database into ARCHIVELOG mode and perform hot (on-line) backups.

What is the difference between SHOW_EDITOR and EDIT_TEXTITEM? 
Show editor is the generic built-in which accepts any editor name and takes some input string and returns modified output string. Whereas the edit_textitem built-in needs the input focus to be in the text item before the built-in is executed.

What are the built-ins that are used to attach an LOV programmatically to an item? 
set_item_property
get_item_property
(by setting the LOV_NAME property)

How does one do on-line database backups? (For DBA)
Each tablespace that needs to be backed-up must be switched into backup mode before copying the files out to secondary storage (tapes). Look at this simple example.
ALTER TABLESPACE xyz BEGIN BACKUP;
! cp xyfFile1 /backupDir/
ALTER TABLESPACE xyz END BACKUP;
It is better to backup tablespace for tablespace than to put all tablespaces in backup mode. Backing them up separately incurs less overhead. When done, remember to backup your control files. Look at this example:
ALTER SYSTEM SWITCH LOGFILE; -- Force log switch to update control file headers
ALTER DATABASE BACKUP CONTROLFILE TO '/backupDir/control.dbf';
NOTE: Do not run on-line backups during peak processing periods. Oracle will write complete database blocks instead of the normal deltas to redo log files while in backup mode. This will lead to excessive database archiving and even database freezes.

How does one backup a database using RMAN? (For DBA)
The biggest advantage of RMAN is that it only backup used space in the database. Rman doesn't put tablespaces in backup mode, saving on redo generation overhead. RMAN will re-read database blocks until it gets a consistent image of it. Look at this simple backup example.
rman target sys/*** nocatalog
run {
allocate channel t1 type disk;
backup
format '/app/oracle/db_backup/%d_t%t_s%s_p%p'
( database );
release channel t1;
}
Example RMAN restore:
rman target sys/*** nocatalog
run {
allocate channel t1 type disk;
# set until time 'Aug 07 2000 :51';
restore tablespace users;
recover tablespace users;
release channel t1;
}
The examples above are extremely simplistic and only useful for illustrating basic concepts. By default Oracle uses the database controlfiles to store information about backups. Normally one would rather setup a RMAN catalog database to store RMAN metadata in. Read the Oracle Backup and Recovery Guide before implementing any RMAN backups.
Note: RMAN cannot write image copies directly to tape. One needs to use a third-party media manager that integrates with RMAN to backup directly to tape. Alternatively one can backup to disk and then manually copy the backups to tape.

What are the different file extensions that are created by oracle reports? 
Rep file and Rdf file.

What is strip sources generate options? 
Removes the source code from the library file and generates a library files that contains only pcode. The resulting file can be used for final deployment, but can not be subsequently edited in the designer.ex. f45gen module=old_lib.pll userid=scott/tiger strip_source YES output_file

How does one put a database into ARCHIVELOG mode? (For DBA)
The main reason for running in archive log mode is that one can provide 24-hour availability and guarantee complete data recoverability. It is also necessary to enable ARCHIVELOG mode before one can start to use on-line database backups. To enable ARCHIVELOG mode, simply change your database startup command script, and bounce the database:
SQLPLUS>  connect sys as sysdba
SQLPLUS>  startup mount exclusive;
SQLPLUS>  alter database archive log;
SQLPLUS>  archive log start;
SQLPLUS>  alter database open;
NOTE1: Remember to take a baseline database backup right after enabling archive log mode. Without it one would not be able to recover. Also, implement an archive log backup to prevent the archive log directory from filling-up.
NOTE2: ARCHIVELOG mode was introduced with Oracle V6, and is essential for database point-in-time recovery. Archiving can be used in combination with on-line and off-line database backups.
NOTE3: You may want to set the following INIT.ORA parameters when enabling ARCHIVELOG mode: log_archive_start=TRUE, log_archive_dest=... and log_archive_format=...
NOTE4: You can change the archive log destination of a database on-line with the ARCHIVE LOG START TO 'directory'; statement. This statement is often used to switch archiving between a set of directories.
NOTE5: When running Oracle Real Application Server (RAC), you need to shut down all nodes before changing the database to ARCHIVELOG mode.

What is the basic data structure that is required for creating an LOV? 
Record Group.

Friday, February 21, 2014

Oracle DAC


Oracle Business Intelligence Data Warehouse Administration Console



Oracle DAC System Properties

There are lots of DAC System Properties available which can be handy during initial set up and consequent improvement in the system. Most of the people just configures DAC server host, DAC server OS and sometimes DAC server port and keep rest of the parameter as is.

However sometimes changing those parameters makes lots of sense.it may be for debugging/testing or performance improvement.

Lets go through these parameter one by one. Lets address the important ones first.


select any of the DAC property and click on Edit to see info on that parameter.



Here is one line description of few DAC server properties.
-   Server log level – Level of Details DAC collects during execution. Oracle support may ask to set this to higher value to debug the issue.
-   Scheduler.Poll.Interval - Value in seconds as to how often DAC server will poll for changes in Schedule configuration.
-   Test Run – When set to true, DAC ignores the errors during the execution. This is a helpful parameter during initial dac testing.
-    SQL Trace - Flagging the SQL Trace to true hints the Database connectivity layer of the DAC Server to enable SQL tracing. Thus every sql that is fired by the DAC server is spooled to the appropriate output log file. Oracle support may ask to set this as true to debug the issue.

-    Script After Every ETL/Script before Every ETL – This parameter along with post_etl/pre_etl runs the task which needs to be executed as pre and post ETL

Introduction to Command-Line SQL*PLUS Client Tool

What Is SQL*Plus?

SQL*Plus is an interactive and batch query tool that is installed with every Oracle Database Server or Client installation. It has a command-line user interface, a Windows Graphical User Interface (GUI) and the iSQL*Plus web-based user interface.
SQL*Plus has its own commands and environment, and it provides access to the Oracle Database. It enables you to enter and execute SQL, PL/SQL, SQL*Plus and operating system commands to perform the following:
  • Format, perform calculations on, store, and print from query results
  • Examine table and object definitions
  • Develop and run batch scripts
  • Perform database administration
You can use SQL*Plus to generate reports interactively, to generate reports as batch processes, and to output the results to text file, to screen, or to HTML file for browsing on the Internet. You can generate reports dynamically using the HTML output facility of SQL*Plus, or using the dynamic reporting capability of iSQL*Plus to run a script from a web page.

How To Start the Command-Line SQL*Plus?

If you Oracle server or client installed on your windows system, you can start the command-line SQL*Plus in two ways:
1. Click Start > All Programs > Oracle ... > Start SQL Command Line. The SQL*Plus command window will show up with a message like this:
SQL*Plus: Release 10.2.0.1.0 - Production on Tue ...

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL>

2. Click Start > Run..., enter "cmd" and click OK. A Windows command window will show up. You can then use Windows commands to start the command-line SQL*Plus as shown in the tutorial exercise below:
>cd c:\oraclexe\app\oracle\product\10.2.0\server\
>.\bin\sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Tue ...

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL>

How To Get Help at the SQL Prompt?

Once SQL*Plus is started, you will get a SQL prompt like this: SQL>. This where you can enter commands for SQL*Plus to run.
To get help information at the SQL prompt, you can use the HELP command as shown in the following tutorial example:

SQL> HELP INDEX

Enter Help [topic] for help.

 @             COPY         PAUSE       SHUTDOWN
 @@            DEFINE       PRINT       SPOOL
 /             DEL          PROMPT      SQLPLUS
 ACCEPT        DESCRIBE     QUIT        START
 APPEND        DISCONNECT   RECOVER     STARTUP
 ARCHIVE LOG   EDIT         REMARK      STORE
 ATTRIBUTE     EXECUTE      REPFOOTER   TIMING
 BREAK         EXIT         REPHEADER   TTITLE
...
 COMPUTE       LIST         SET         XQUERY
 CONNECT       PASSWORD     SHOW

SQL> HELP CONNECT

 CONNECT
 -------

 Connects a given username to the Oracle Database. When you
 run a CONNECT command, the site profile, glogin.sql, and
 the user profile, login.sql, are processed in that order.
 CONNECT does not reprompt for username or password if the
 initial connection does not succeed.

 CONN[ECT] [{logon|/|proxy} [AS {SYSOPER|SYSDBA}]]

 where logon has the following syntax:
     username[/password][@connect_identifier]


What Information Is Needed to Connect SQL*Plus an Oracle Server?

If you want to connect your SQL*Plus session to an Oracle server, you need to know the following information about this server:
  • The network hostname, or IP address, of the Oracle server.
  • The network port number where the Oracle server is listening for incoming connections.
  • The name of the target database instance managed by the Oracle server.
  • The name of your user account predefined on in the target database instance.
  • The password of your user account predefined on in the target database instance.

What Is a Connect Identifier?

A "connect identifier" is an identification string of a single set of connection information to a specific target database instance on a specific Oracle server.
Connect identifiers are defined and stored in a file called tnsnames.ora located in $ORACLE_HOME/network/admin/ directory. Here is one example of a "connect identifier" definition:
FYI_XE =
  (DESCRIPTION =
    (ADDRESS =
      (PROTOCOL = TCP)
      (HOST = dba.fyicenter.com)
      (PORT = 1521)
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )
The above "connect identifier" defines "TNS_XE" with the following connection information:
  • The network hostname: dba.fyicenter.com.
  • The network port number: 1521.
  • The name of the target database instance: XE.

How To Connect a SQL*Plus Session to an Oracle Server?

In order to connect a SQL*Plus session to an Oracle server, you need to:
1. Obtain the connection information from the Oracle server DBA.
2. Define a new "connect identifier" called "FYI_XE" in your tnsnames.org file with the given connection information.
3. Run the CONNECT command in SQL*Plus as shown in the tutorial exercise below:
>cd c:\oraclexe\app\oracle\product\10.2.0\server\
>.\bin\sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Tue ...
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> CONNECT fyi/retneciyf@FYI_XE;
Connected.

SQL> SELECT SYSDATE FROM DUAL;

SYSDATE
---------
05-MAR-06


What Happens If You Use a Wrong Connect Identifier?

Of course, you will get an error, if you use a wrong connect identifier. Here is an example of how SQL*Plus react to a wrong connect identifier:
SQL> CONNECT fyi/retneciyf@WRONG;
ERROR:
ORA-12154: TNS:could not resolve the connect identifier
   specified

Warning: You are no longer connected to ORACLE.

What you need to do in this case:
  • Check the CONNECT command to make sure that the connect identifier is entered correctly.
  • Check the tnsnames.ora file to make sure that the connect identifier is defined correctly.
  • Check the tnsnames.ora file to make sure that there is no multiple definitions of the same connect identifier.
  • Check your files system to see if you have multiple copies of tnsnames.ora in different Oracle home directories, because you installed multiple versions of Oracle. If you do have multiple copies, make sure your SQL*Plus session is picking up the correct copy of tnsnames.ora.
What To Do If DBA Lost the SYSTEM Password?

If the DBA lost the password of the SYSTEM user account, he/she can go to the Oracle server machine, and run SQL*Plus on server locally with the operating system authentication method to gain access to the database. The tutorial exercise below shows you how:

(Terminal server to the Oracle server machine)
(Start SQL*Plus)
SQL>CONNECT / AS SYSDBA
Connected.

SQL> ALTER USER SYSTEM IDENTIFIED BY ssap_iyf;
User altered.

Notice that the (/) in the CONNECT command tells SQL*Plus to use the current user on local operating system as the connection authentication method.


What Types of Commands Can Be Executed in SQL*Plus?

There are 4 types of commands you can run at the SQL*Plus command line prompt:

1. SQL commands - Standard SQL statements to be executed on target database on the Oracle server. For example: "SELECT * FROM fyi_faq;" is a SQL command.

2. PL/SQL commands - PL/SQL statements to be executed by the Oracle server. For example: "EXECUTE DBMS_OUTPUT.PUT_LINE('Welcome to dba.fyicenter.com')" runs a PL/SQL command.

3. SQL*Plus commands - Commands to be executed by the local SQL*Plus program itself. For example: "SET NULL 'NULL'" is a SQL*Plus command.

4. OS commands - Commands to be executed by the local operating system. For example: "HOST dir" runs an operating system command on the local machine.

How To Run SQL Commands in SQL*Plus?

If you want to run a SQL command in SQL*Plus, you need to enter the SQL command in one or more lines and terminated with (;). The tutorial exercise below shows a good example:
SQL> SELECT 'Welcome!' FROM DUAL;

'WELCOME
--------
Welcome!

SQL> SELECT 'Welcome to FYIcenter.com tutorials!'
  2  FROM DUAL
  3  ;

'WELCOMETOFYICENTER.COMTUTORIALS!'
-----------------------------------
Welcome to FYIcenter.com tutorials!


How To Run PL/SQL Statements in SQL*Plus?

If you want to run a single PL/SQL statement in SQL*Plus, you need to use the EXECUTE command as shown in the following tutorial example:

SQL> SET SERVEROUTPUT ON

SQL> EXECUTE DBMS_OUTPUT.PUT_LINE('Welcome to FYIcenter!')
Welcome to FYIcenter!

PL/SQL procedure successfully completed.


How To Change SQL*Plus System Settings?

SQL*Plus environment is controlled a big list of SQL*Plus system settings. You can change them by using the SET command as shown in the following list:
  • SET AUTOCOMMIT OFF - Turns off the auto-commit feature.
  • SET FEEDBACK OFF - Stops displaying the "27 rows selected." message at the end of the query output.
  • SET HEADING OFF - Stops displaying the header line of the query output.
  • SET LINESIZE 256 - Sets the number of characters per line when displaying the query output.
  • SET NEWPAGE 2 - Sets 2 blank lines to be displayed on each page of the query output.
  • SET NEWPAGE NONE - Sets for no blank lines to be displayed on each page of the query output.
  • SET NULL 'null' - Asks SQL*Plus to display 'null' for columns that have null values in the query output.
  • SET PAGESIZE 60 - Sets the number of lines per page when displaying the query output.
  • SET TIMING ON - Asks SQL*Plus to display the command execution timing data.
  • SET WRAP OFF - Turns off the wrapping feature when displaying query output.

How To Look at the Current SQL*Plus System Settings?

If you want to see the current values of SQL*Plus system settings, you can use the SHOW command as shown in the following tutorial exercise:

SQL> SHOW AUTOCOMMIT
autocommit OFF

SQL> SHOW HEADING
heading ON

SQL> SHOW LINESIZE
linesize 80

SQL> SHOW PAGESIZE
pagesize 14

SQL> SHOW FEEDBACK
FEEDBACK ON for 6 or more rows

SQL> SHOW TIMING
timing OFF

SQL> SHOW NULL
null ""

SQL> SHOW ALL
appinfo is OFF and set to "SQL*Plus"
arraysize 15
autocommit OFF
autoprint OFF
autorecovery OFF
autotrace OFF
blockterminator "." (hex 2e)
cmdsep OFF
colsep " "
compatibility version NATIVE
concat "." (hex 2e)
copycommit 0
COPYTYPECHECK is ON
define "&" (hex 26)
describe DEPTH 1 LINENUM OFF INDENT ON
echo OFF
...


What Are SQL*Plus Environment Variables?

Behaviors of SQL*Plus are also controlled a some environment variables predefined on the local operating system. Here are some commonly used SQL*Plus environment variables:
  • ORACLE_HOME - The home directory where your Oracle client application is installed.
  • PATH - A list of directories where SQL*Plus will search for executable or DLL files. PATH should include $ORACLE_HOME\bin.
  • SQLPLUS - The directory where localization messages are stored. SQLPLUS should be set to $ORACLE_HOME\sqlplus\mesg
  • TNS_ADMIN - The directory where the connect identifier file, tnsnames.ora is located. TNS_ADMIN should be set to $ORACLE_HOME/network/admin.

How To Generate Query Output in HTML Format?

If you want your query output to be generated in HTML format, you can use the "SET MARKUP HTML ON" to turn on the HTML feature. The following tutorial exercise gives you a good example:

SQL> connect HR/retneciyf

SQL> SET MARKUP HTML ON

SQL> SELECT FIRST_NAME, LAST_NAME, HIRE_DATE


  2  FROM EMPLOYEES WHERE FIRST_NAME LIKE 'Joh%';

FIRST_NAME
LAST_NAME
HIRE_DATE

John

Seo

12-FEB-98

John

Russell

01-OCT-96


What Is Output Spooling in SQL*Plus?

The output spooling a nice feature of the command-line SQL*Plus tool. If the spooling feature is turned on, SQL*Plus will send a carbon copy of the everything on your screen to a specified local file.
Output spooling is used mostly for quick dump of data to local files. Here are the commands to turn on and off output spooling in SQL*Plus:
  • SPOOL fileName - Turning on output spooling with the specified file.
  • SPOOL OFF - Turning off output spooling and close the spool file.

How To Save Query Output to a Local File?

Normally, when you run a SELECT statement in SQL*Plus, the output will be displayed on your screen. If you want the output to be saved to local file, you can use the "SPOOL fileName" command to specify a local file and start the spooling feature. When you are done with your SELECT statement, you need to close the spool file with the "SPOOL OFF" command. The following tutorial exercise gives you a good example:
SQL> connect HR/retneciyf

SQL> SET HEADING OFF
SQL> SET FEEDBACK OFF
SQL> SET LINESIZE 1000
SQL> SPOOL \temp\employees.lst
SQL> SELECT * FROM EMPLOYEES;
......
SQL> SPOOL OFF
You should get all records in employees.lst with fixed length fields.


What Is Input Buffer in SQL*Plus?

Input buffer is a nice feature of the command-line SQL*Plus tool. It allows you to revise a multiple-line command and re-run it with a couple of simple commands. By default, input buffer is always turned on in SQL*Plus. The last SQL statement is always stored in the buffer. All you need is to remember to following commonly used commands:
  • LIST - Displays the SQL statement (the last executed SQL statement) in the buffer.
  • RUN - Runs the SQL statement in the buffer again. ";" is a quick command equivalent to RUN.
  • CLEAR BUFFER - Removes the SQL statement in the buffer.
  • INPUT line - Adds a new line into the buffer.
  • APPEND text - Appends more text to the last line in the buffer.
  • DEL - Deletes one line from the buffer.
  • CHANGE /old/new - Replaces 'old' text with 'new' text in the buffer.

How To Revise and Re-Run the Last SQL Command?

If executed a long SQL statement, found a mistake in the statement, and you don't want enter that long statement again, you can use the input buffer commands to the correct last statement and re-run it. The following tutorial exercise gives you a good example:
SQL> connect HR/retneciyf

SQL> SELECT FIRST_NAME, LAST_NAME, HIRE_DATE
  2  FROM EMPLOYEE WHERE FIRST_NAME LIKE 'Joh%';
FROM EMPLOYEE WHERE FIRST_NAME LIKE 'Joh%'
     *
ERROR at line 2:
ORA-00942: table or view does not exist

SQL> LIST
  1  SELECT FIRST_NAME, LAST_NAME, HIRE_DATE
  2* FROM EMPLOYEES WHERE FIRST_NAME LIKE 'Joh%'

SQL> CHANGE /EMPLOYEE/EMPLOYEES/
  2* FROM EMPLOYEES WHERE FIRST_NAME LIKE 'Joh%'

SQL> RUN
(Query output)

SQL> INPUT ORDER BY FIRE_DATE
SQL> LIST
  1  SELECT FIRST_NAME, LAST_NAME, HIRE_DATE
  2  FROM EMPLOYEE WHERE FIRST_NAME LIKE 'Joh%'
  3* ORDER BY HIRE_DATE

SQL> RUN
(Query output)

SQL> CLEAR BUFFER
buffer cleared

SQL> LIST
SP2-0223: No lines in SQL buffer.


How Run SQL*Plus Commands That Are Stored in a Local File?

If you have a group of commands that you need to run them repeatedly every day, you can save those commands in a file (called SQL script file), and using the "@fileName" command to run them in SQL*Plus. If you want to try this, create a file called \temp\input.sql with:
SELECT 'Welcome to' FROM DUAL;
SELECT 'FYIcenter.com!' FROM DUAL;
Then run the "@" command in SQL*Plus as:
SQL> connect HR/retneciyf

SQL> @\temp\input.sql

'WELCOMETO
----------
Welcome to


'FYICENTER.COM
--------------
FYIcenter.com!


How To Use SQL*Plus Built-in Timers?

If you don't have a stopwatch/timer and want to measure elapsed periods of time, you can SQL*Plus Built-in Timers with the following commands:
  • TIMING - Displays number of timers.
  • TIMING START [name] - Starts a new timer with or without a name.
  • TIMING SHOW [name] - Shows the current time of the named or not-named timer.
  • TIMING STOP [name] - Stops the named or not-named timer.
The following tutorial exercise shows you a good example of using SQL*Plus built-in timers:
SQL> TIMING START timer_1

(some seconds later)
SQL> TIMING START timer_2

(some seconds later)
SQL> TIMING START timer_3

(some seconds later)
SQL> TIMING SHOW timer_1
timing for: timer_2
Elapsed: 00:00:19.43

(some seconds later)
SQL> TIMING STOP timer_2
timing for: timer_2
Elapsed: 00:00:36.32

SQL> TIMING
2 timing elements in use


What Is Oracle Server Autotrace?

Autotrace is Oracle server feature that generates two statement execution reports very useful for performance tuning:
  • Statement execution path - Shows you the execution loop logic of a DML statement.
  • Statement execution statistics - Shows you various execution statistics of a DML statement.
To turn on the autotrace feature, the Oracle server DBA need to:
  • Create a special table called PLAN_TABLE.
  • Create a special security role called PLUSTRACE.
  • Grant PLUSTRACE role your user account

     How To Set Up Autotrace for a User Account?

·         If an Oracle user wants to use the autotrace feature, you can use the tutorial as an example to create the required table PLAN_TABLE, the required security role PLUSTRACE, and grant the role to that user:
·         SQL> CONNECT HR/retneciyf
·          
·         SQL> @\oraclexe\app\oracle\product\10.2.0\server
·           \RDBMS\ADMIN\UTLXPLAN.SQL
·         Table (HR.PLAN_TABLE) created.
·          
·         SQL> CONNECT / AS SYSDBA
·          
·         SQL> @C:\oraclexe\app\oracle\product\10.2.0\server
·            \SQLPLUS\ADMIN\PLUSTRCE.SQL
·          
·            SQL> drop role plustrace;
·            Role (PLUSTRACE) dropped.
·            
·            SQL> create role plustrace;
·            Role (PLUSTRACE) created.
·            
·            SQL> grant plustrace to dba with admin option;
·            Grant succeeded.
·          
·         SQL> GRANT PLUSTRACE TO HR;
·         Grant succeeded.
·         Remember that PLAN_TABLE table must be created under the user schema HR.


    How To Get Execution Path Reports on Query Statements?
·        
        If your user account has autotrace configured by the DBA, you can use the "SET AUTOTRACE ON EXPLAIN" command to turn on execution path reports on query statements. The tutorial exercise bellow shows you a good example:
·         SQL> CONNECT HR/retneciyf
·          
·         SQL> SET AUTOTRACE ON EXPLAIN
·          
·         SQL> SELECT E.LAST_NAME, E.SALARY, J.JOB_TITLE
·           2  FROM EMPLOYEES E, JOBS J
·           3  WHERE E.JOB_ID=J.JOB_ID AND E.SALARY>12000;
·          
·         LAST_NAME             SALARY JOB_TITLE
·         ----------------- ---------- -----------------------------
·         King                   24000 President
·         Kochhar                17000 Administration Vice President
·         De Haan                17000 Administration Vice President
·         Russell                14000 Sales Manager
·         Partners               13500 Sales Manager
·         Hartstein              13000 Marketing Manager
·          
·         6 rows selected.
·          
·         Execution Plan
·         -----------------------------------------------------------
·         Plan hash value: 3851899397
·          
·         -----------------------------------------------------------
·         Id|Operation           |Name     |Rows|Bytes| Cost|Time  
·           |                    |         |    |     |/%CPU|
·         -----------------------------------------------------------
·          0|SELECT STATEMENT    |         |  59| 2832|  4/0|00:00:01
·          1| NESTED LOOPS       |         |  59| 2832|  4/0|00:00:01
·         *2|  TABLE ACCESS FULL |EMPLOYEES|  59| 1239|  3/0|00:00:01
·          3|  TABLE ACCESS      |JOBS     |   1|   27|  1/0|00:00:01
·           |     BY INDEX ROWID |         |    |     |     |
·         *4|   INDEX UNIQUE SCAN|JOB_ID_PK|   1|     |  0/0|00:00:01
·         -----------------------------------------------------------
·          
·         Predicate Information (identified by operation id):
·         ---------------------------------------------------
·            2 - filter("E"."SALARY">12000)
·            4 - access("E"."JOB_ID"="J"."JOB_ID")


    How To Get Execution Statistics Reports on Query Statements?
·         If your user account has autotrace configured by the DBA, you can use the "SET AUTOTRACE ON STATISTICS" command to turn on execution statistics reports on query statements. The tutorial exercise bellow shows you a good example:
·         SQL> CONNECT HR/retneciyf
·          
·         SQL> SET AUTOTRACE ON STATISTICS
·          
·         SQL> SELECT E.LAST_NAME, E.SALARY, J.JOB_TITLE
·           2  FROM EMPLOYEES E, JOBS J
·           3  WHERE E.JOB_ID=J.JOB_ID AND E.SALARY>12000;
·          
·         LAST_NAME             SALARY JOB_TITLE
·         ----------------- ---------- -----------------------------
·         King                   24000 President
·         Kochhar                17000 Administration Vice President
·         De Haan                17000 Administration Vice President
·         Russell                14000 Sales Manager
·         Partners               13500 Sales Manager
·         Hartstein              13000 Marketing Manager
·          
·         6 rows selected.
·          
·         Statistics
·         ----------------------------------------------------------
·                   0  recursive calls
·                   0  db block gets
·                  16  consistent gets
·                   0  physical reads
·                   0  redo size
·                 720  bytes sent via SQL*Net to client
·                 384  bytes received via SQL*Net from client
·                   2  SQL*Net roundtrips to/from client
·                   0  sorts (memory)
·                   0  sorts (disk)

·                   6  rows processed