18.6 DATABASE QUERIES Oracle uses a structured query language (SQL) to enable you to search the database objects and gather the information you need. The format of the database statements follows a specific syntax that includes the command, object, and source table from which to extract the data. In order to extract the data using SQL, you could execute a pre-existing script, write a script that contains the SQL statements you need, or execute the SQL statement at the database command line.18.6.1 Basics of Writing SQL Statements The following is true of SQL statements:- Begin at the SQL prompt
- Can be entered on one or more lines
- Line wraps are indicated with a number at the beginning of the continued line
- Are not case sensitive, unless indicated
- Clauses are usually placed on separate lines for readability and editing
- Tabs and indents can be used to make the code more readable
- Keywords cannot be split across lines or abbreviated
- Keywords typically are entered in uppercase
- All other words, such as table names and columns, are lowercase
- One statement can be entered at a time for processing
- End with semicolon
- Choose the rows in a table
- Choose the columns in a table
- Select data from multiple tables
18.6.2 Examples of Database Queries using SQL Login to the database. Use the sqlplus command to execute several SQL statements:# sqlplus SQL*Plus: Release 9.2.0.2.0 - Production on Sat Jan 10 12:57:48 2004 Copyright © 1982, 2002, Oracle Corporation. All rights reserved. Enter user-name: opc_op/opc_op@ov_net Connected to: Oracle9i Enterprise Edition Release 9.2.0.2.0 - 64bit Production JServer Release 9.2.0.2.0 - Production SQL> select count(*) from opc_act_messages; COUNT(*) 139 SQL>
|