formatting the results in the form of reports. • It uses SQL to retrieve information from ORACLE database and lets the user create polished, well formatted reports. • The report writing and formatting features of SQL*Plus are: > Top and Bottom Titles > Column Headings > Totals and Sub-totals > Reformatting the numbers and/or texts > Control break reports. • Once the formatting is over, the user needs to execute the SQL query and SQL*Plus immediately produce the report. Defining Headers, Footers and Column Headings The Ttitle and Btitle commands are used to produce titles on a page. TTITLE/BTITLE [options] text Options are: LEFT, RIGHT, CENTER To enable (or) disable the titles, use TTITLE/BTITLE ON/OFF command. Column Headings are defined using the command COLUMN col-name/alias HEADING text FORMAT text Single quotes are required if the heading contains more than one word. The ‘|’ symbol is used in column headings to split the heading into more than one line. Column headings can be cleared by COLUMN col-name CLEAR command. Column Display Format Format Description An alphanumeric, n wide 9 numeric position 999 23 0 enforce leading zeros 099 023 $ floating dollar $99 $23 . Decimal point 99.99 , comma 9,999 MI Minus sign to right 99MI PR Parenthesize –ve numbers Displaying Page Numbers: The user can display the system-maintained values in the Title of the report. The current page number is maintained by a system variable called sql.pno Control Break Reports • Using Control break techniques, repeating column values can be grouped together. • ORDER BY clause is needed to control the break BREAK ON col-name [SKIP n / PAGE] [ON col] • Breaks can be cleared by using CLEAR BREAKS command • The COMPUTE command, together with BREAK, is used to compute and display summaries along with the details. COMPUTE function OF column ON colname ROW/PAGE/REPORT • To remove computation on a column CLEAR COMPUTES command is used. SQL*Plus Commands Command Description @ Runs the specified command file / Executes the SQL command ACCEPT Reads a line of input to a variable APPEND Adds text to the end of the line BREAK Lists the current break definition BTITLE Places title at the bottom of page CHANGE Changes the text in current line CLEAR Erases the current value(or)setting COLUMN Specifies display attributes for a col COMPUTE Standard computations on cols CONNECT Connects a given user to Oracle DEFINE Specifies a user variable DEL Deletes one or more lines of buffer DESCRIBE Lists the table structure DISCONNECT Commits pending changes and logout the current user. SQL*Plus Commands Contd., Command Description EDIT Opens OS’s text editor EXECUTE Executes a single PL/SQL command EXIT Terminates SQL*Plus GET Loads a SQL file into the buffer HOST Executes a host OS command INPUT Adds new line after the current line LIST Lists one or more lines of buffer PAUSE Waits for the user to press Return PROMPT Sends a message to user REMARK Comment in a command file RUN Lists and execute the buffer SQL st. SAVE Saves the buffer data in file SET Sets a system variable to alter the SQL*Plus environment for your current session SHOW Shows the value of SQL*Plus system variable. SQL*Plus Commands Contd., Command Description SPOOL Stores query results in a file START Executes contents of command file TTITLE Specifies title at top of a page UNDEFINE Deletes variables that you defined WHENEVER SQLERROR/OSERROR EXIT Exits SQL*Plus if SQL command or Operating System generates an error.
Setting SQL*Plus Environment Commands
ARRAYSIZE {20/n} sets the number of rows that SQL*Plus will fetch from the database at one time. AUTOCOMMIT {ON/OFF} Controls when Oracle commits pending changes to the database. COLSEP { /text} sets the text to be printed between columns. FEEDBACK {6/n/OFF/ON} Displays no of rows. HEADING {OFF/ON} Controls printing of Column Headings LINESIZE {80/n} Sets the number of characters displays in one line NEWPAGE {1/n} Sets the number of blank lines for a new page. NULL text Sets the text that represents a null value in the result of SQL statement. NUMFORMAT format Sets the default format for displaying numbers. NUMWIDTH {10/n} Sets the default width for no.s PAGESIZE {24/n} Sets the number of lines in page PAUSE {OFF/ON} SQLCONTINUE {>/text} SQLNUMBER {OFF/ON} SQLPROMPT {SQL>/text} SQLTERMINATOR {;/c/OFF/ON} UNDERLINE {-/c/ON/OFF} VERIFY {ON/OFF} Tree Walking A relational database does not store records in a hierarchical way. However, where a HIERARCHICAL relationship exists between the rows or a SINGLE table, there is a process called ‘tree walking’ which enables the hierarchy to be constructed. The hierarchy can be created by looking at the relationship between equivalent values in columns EMPNO and MGR. An employee’s MGR number is their manager’s EMPNO. LEVEL numbers are established as the tree walk occurs and represent how far nodes (rows) are removed from the ROOT (start node). Ex: break on deptno skip 1 SELECT LEVEL, deptno, empno, ename, job FROM emp CONNECT BY PRIOR EMP = MGR START WITH MGR IS NULL; Command Description SELECT It is a standard SELECT clause FROM You can select only FROM one table WHERE Restricts the rows that are visited CONNECT BY Specifies the columns where the relationship between rows exists. PRIOR Establishes the direction in which the tree is walked. START WITH Specifies where to start the walk. ORDER BY To sort the rows. Ex: SELECT LEVEL, deptno, empno, ename, job, sal FROM emp WHERE ename != ‘SCOTT’ CONNECT BY PRIOR empno = mgr START WITH MGR IS NULL;
Zooplankton and White Goby (Glossogobius Giuris Hamilton 1822) : Correlation and Fishers' Perception in Selected Sites in Laguna de Bay, Luzon Island, Philippines