SBCA ORACLE 2.6 UNIT-1 1. ANSWER ORACLE is a fourth generation relational database management system, In general, a database management system (DBMS) must be able to reliably manage a large amount of data in a multiuser environment so that many users can concurrently access the same data. All this must be accomplished while delivering high performance to the users of the database. A DBMS must also be secure from unauthorized access and provide efficient solutions for failure recovery. The ORACLE Server provides efficient and effective solutions for the major database features. ORACLE consists of many tools that allow you to create an application with ease and flexibility. You must delermine how to implement your requirements using the features available in ORACLE, along with its tools. The features and tools that you choose to use to implement your application can significantly affect the performance of your application. Several of the more useful features available to ORACLE application. developers are integrity constraints, stored procedures and packages, database triggers, cost-based optimizer, shared SQL, locking and sequences. This documentation will lead you through the main features and tools of ORACLE. It is intended to give youa partial view of what is available to you to use within the assignments. This documentation will cover ORACLE Architecture- provides a basic understanding of the "Big Picture" including the concepts and terminology of the ORACLE Server. Starting ORACLE And Other lImportant Information provides the knowledge of how to set up your account and other system environment variables. t will also provide information about how ORACLE is currently setup, which you will require, and the steps you must take to report any problems SOL'Pus (Terminal Moniton)- provides a summary of the commands that you willrequire in order to create tables and manipulate the database SQL-Loader- provides a summary of the commands that you will require to allow you to load data from a file to the database. SQL Commands -provides the syntax of some of the SaL Commands in ORACLE to help you get started. This section will only shed light on the Data Definition Language commands and wi not contain any information on querying the database (which should be covered in class). ANSWER Features of Oracle 2. lf you are using Borland's Delphi or C-Builder to develop Oracle applications, then the Direct Oracle Access component sel can help you to make a seamless integration between this great development tool and database system. Not only will your application take maximum advantage of both products, your application development process willalso benefit from the following key features: High performance Both online transaction and batch processing applications can benefit from Oracle's performance features. Direct Oracle Access, as the name suggests, directly accesses the Oracle Interface. This guarantees optimal performance for standard database access functions. Support for Array Felching, Array DML, PLUSQL Blocks, PLUSQL Tables, Local Slalement Caching and the Direct Path Load Engine enable you to optimize your application's performance crical functions even more. High performance Easy application distribution A Direct Oracle Access application does not require middleware like the BDE or ODBC, it merely requires Oracle SQL"Net or Net8. Consequently you can deploy your application without many of the version dependency or configuration problems typically involved with middleware installation. ** Application distribution Oracle Package support Most PLUSQL code in Oracle databases is programmed in packages. Direct Oracle Access provides a TOraclePackage component that allows you to easily call packaged program units without detailed declarations of these program units and their parameters. Furthermore Direct Oracle Access includes a Package Wizard that can generate classes to encapsulate the program units and record types defined in packages. This will make your Oracle packages a natural extension of the Object Pascal or C+ language. L The Package Wizard PRESIDENCY COLLEGE 1 2.6 ORACLE SBCA The dataset component in Direct Oracle Access supports Oracle record locking, record refreshing, server generaled values, automatic sequence value generation, and BLOB compression. Master/detail relations can automalically be selup t a foreign key exists between the master and detail table or if the master table contains one or more collection columns or attributes (nested table or varray). The TOracleDataSel can use much of the information in the Oracle Dictionary at run time. Server Constrainls can be checked on the client, and constraint error messages can be read from a message table. Format masks, range values and default values can also be read from the dictionary. This allows you to create applications with a minimum amount of database knowlegde' compiled into the executable, dynamically adopting changes in the database without even recompiling9it TOracleDataSet The TOracleData Set Query By Example mode The TOracleDataSet component has a Query By Example mode that enables you to provide QBE Forms in your application without any additional programming, and without any additional components or controls. The resulting QBE queries are performed on the Oracle Server, so that performance will be optimal and network traffic will be mihimal. The user can supply simple query values such as JONES or 100, can include wildcard characlers for string values SUch as JON%, and can include comparison operators such as>, , NOT, BETWEEN, IN and so on. Query By Example Oracle Monitor To monitor the database access activities of your Direct Oracle Access application you can use the Oracle Monitor utility. It displays the SQL, variables, timestamp, elapsed time, network statistics, database statistics and query execution plan of each activity. This can be helpful to find performance bottlenecks, for tuning purposes, and to solve application errors. The Oracle Montor Alert and Pipe events The Oracle Server includes a dbms_alert and dbms_pipe package for event processing. The TOracleEvent in Direct Oracle Access can function as a receiver for these events. It works in a background thread of your application, and can propagate database events to the familiar object events. These events can occur synchronously or asynchronously with the main thread of your application. ***** ** *** * ***** **** Alert and Pipe events sQL scripts If you need to execute many data definition language (DDL) statements, for example to perform the database installation part of your application, you can use the TOracleScript component. It has a property editor that allows you to develop the script and the individual commands. The extendible script language follows the basic SQL Plus syntax and supports all SQL statements. It also supports substitution variables to make your scriptscustomizable. ***** SQL Scripts Advanced Queueing To take advantage of the Advanced Queuing option of Oracle8 you can make use of the TOracleQueue component. The TOracleQueue component encapsulates the bas from a queue. Messages can be dequeued in a background thread of your application, and the events that are generated in threaded mode can occur synchronously or asynchronously with th main thread of your application. functionality of the DBMS_AQ package. It provides a convenient way to enqueue messages into a queue or to dequeue messages Session Pooling In server applications that frequently need to create sessions to process requests from client applications, it may be useful to use connection pooling. Without a poling concept, each request could lead to an actual dalabase logon and logoff. By using database sessions that can be used and reused for different requests. You can define the minimum an maximum number of sessions in the pool, define the TimeOut behavior for idle sessions in the pool, and preset the username, password and database. TOracleSessionPool cormponent, you can maintain a pooB of Support for Oracle specific features Direct Oracle Access supports many Oracle specific features. Besides the features mentioned above, it supports Oracle8 and Oracle8i features like LOB LOcators, Objects & References, XMLTYPE, Timestamps, Scrollable Queries, Password Expiration, External Procedure development, and the Oracle Services 2 PRESIDENCY COLLEGE ORACLE 2.6 SBCA for MTS 3. ANSWER SQL Commands Overview Oracle Lite uses several different types of SQL commands. This section discusses the diferent types of SQL commands. Data Definition Language (DDL) Commands Data definition language (DDL) commands enable you to perform the following tasks: Create, alter, and drop schema objects Grant and revoke privileges and roles Add comments to the data dictionary The CREATE, ALTER, and DROP commands require exclusive access to the object being acted upon. For example, an ALTER TABLE command fails if another user has an open transaction on the specified table. Data Manipulation Language (DML) Commands Data manipulation language (DML) commands query and manipulate data in existing schema objects. These.commands do not implicitly commit the current transaction. Transaction Control Commands Transaction control commands manage changes made by DML commands. Clauses Clauses are subsets of commands that modify the command. Pseudocolumns Pseudocolumns are values generated from commands that behave like columns of a table, but are not actually stored in the table. Pseudocolumns are supported by Oracle but are not part of SQL-92. 4 ANSWER Data Definition Language (DDL) Statements Data definition language (DDL) statements let you to perform these tasks: Create, alter, and drop schema objects Analyze information on a table, index, or cluster Establish auditing options Add comments to the data dictionary The CREATE, ALTER, and DROP commands require exclusive access to the specified object. For example, an ALTER TABLE statement fails if another user has an open transaction on the specified table. Oracle Database implicity commits the current transaction before and after every DDL statement. Many DDL statements may cause Oracle Database to recompile or reauthorize schema objects. For information on how Oracle Database recompiles and reauthorizes schema objects and the circumstances under which a DDL statement would cause this, see Oracle Database Concepts. DDL statements are supported by PL/SQL with the use of the DBMS_SQL package. 5. ANSWER Relational Database Management System - RDBMS A RDBMS is a term used to describe an entire suite of programs for both managing a relational database and communicating with that relational database engine. Sometimes Software Development Kit (SDK) front-end tools and complete management kits are included with relational database packages (eg: MS Access)}In other words, an RDBMS is both the database engine and any other tool that comes with in. Rebiona Databses Arelaicnaldatabase sagariedasaseldttiesdidaaandamahemaicallang.age( relaionalagebra - is aaabe bmanipuale hetaties The presertaicnddaantefamdtbesiskrowna areton Arekaicnismaeupdanumberd pes (ows) ad abues (okumms) Domains aeragedvalESwhichcanappea neah column are taken from the daman a tatatte Sae Tre AGEMbenteap t6b,otednand te AGE ateibeaniesnteag 16b5 Advantages of RDBMS Supports for very large databases. Automatic optimization of searching. 1. 2. PRESIDENCY COLLEGE ORACLE RDBMS have a simple view of the database that confirms to much of the data used in business. Structured Query Language (SQL). SBCA 3 4 5. ANSWER Ans. Data retrieval | SQL Lanquage Reference | DDL-Data Definition Language DML Data Manipulation Lanquage SIUD SELECT INSERT UPDATE DELETE 3 2. MERGE DML Data Manipulation Language S the adbreviation for Data Manipulation Language. DML is a collection of SQL commands that can be used to manipulate a data0ases oata. o language commands, which execute gueries with database objects and changes to their contents. The various DML COmnandS Can De e t reale, edit, evaluate and delete data in a database. DML commands are a subarea of SQL; the range of the SQL language is composeuO DML dnd DDL together. SIUD SIUD is the abbreviation for SELECT, INSERT, UPATE, DELETE, which are the four DML commands used for data manp ulduon See also Create SIUD Procedures INSERTEX SELECT Pleaserefer to SQL Lanquage Reference / Data Retrieval /SELECT for details. INSERT Adds one or more new rows to a specifed table. Available in gpre, DSQL, and isq Syntax INSERT (TRANSACTION transaction] INTO object [(col [. col..])] (VALUES (val [, val..]) | select_expr)} <object = tablename | viewname <valb= (variable constant | expr | function udf ([val [, val ..) INULL | USER | RDBSDB_KEY | ?} |COLLATE collation) constant>= num |'string' | charsetname 'string' sfunction= CAST (val AS datatype) UPPER (val) GEN ID (generator, val) ********* Argument Description expr A valid SQL expression that results in a single column value. select expr A SELECT that returns zero or more rows and where the number of columns in each row is the same as the number of items to be inserted. ww.ewvowww Notes on the INSERT statement In $QL and isql, you cannot use val as a parameter placeholder (like "?"). In DSQL and isql, val cannot be a variable. You cannot specify a COLLATE clause for Blob columns. Important: In SQL statements passed to DSQL, omit the terminating semicolon. In embedded applications written in C and C++, and in isql, the semicolon is a terminating symbol for the statement, so it must be included. Argument Description ** TRANSACTION transaction Name of the transaction that controls the execution of the INSERT. INTO object Name of an existing table or view into which to insert data. Col Name of an existing column in a table or view into which to insert values. VALUES (val , val..) Lists values to insert into the table or view; values must be listed in the same order as the target columns. select_expr Query that returns row values to insert into target columns. 4 PRESIDENCY COLLEGE 2.6 SBCA ORACLE Description INSERI Stores one or more new rows of data in an existing table or view. INSERT is one of the database privileges controlled by the GRANT and REVOKE Stalements. Values are inserted into a row in column order unless an optional list of target columns is provided. If the target list of columns is a subset of avauia0ie columns, detault or NULL values are automatically stored in all unisted columns. If the optional list of target columns Is omited, the VALUES clause must provide values to insert into all columns in the table To insert a single row of data, the VALUES clause should include a specific list of values to insrt. nsert muitple rows of data, specify a select_expr that retrieves existing data from another table to insert into this one. The selected columns must correspond to the columns listed for inset. mportant Itis legal to select from the same table into which insertions are made, but this practice is not advised because it may result in infinite row insertions. neRANSACTION dlause can be used in multiple transaction SQL applications to specify which transaction controls the INSERT operation. The TRANSACTION clause is not available in DSQL or isql. Examples he following statement, from an embedded SQL application, adds a row to a table, assigning values from host-language variables to two columns: EXEC SQL INSERT INTO EMPLOYEE_PROJECT (EMP_NO, PROJ_ID) VALUES (emp_no, proj_id): The next isql statement specifies values to insert into a table with a SELECT statement: INSERT INTO PROJECTS SELECT FROM NEW_PROJECTS WHERE NEW_PROJECTS.START_DATE> "6-JUN-1994; See Also: INSERT SET TRANSACTION UPDATE OR INSERT UPDATE Changes the data in all or part of an existing row in a table, view, or active set of a cursor. Avaitable in gpre, DSQL, and isql. Syntax SQL form LPDATE ITRANSACTION Transact ion), {table | vi ew} va wHERE Search_condition| WHERE CURRENT OF cursor] LORDER BY order-listj ROWS value [To upper_value] [BY Step_value] [PERCENT] [WITH TIES]]: DsQL and isql form: UPDATE {table I.view SET COl val [. col val] WHERE Search_condition ORDER BY or der_1ist] [ROWS value [To upper_value] (BY step_value] [PERCENT] [wITH TIES]1 <val>,=I coaray_dim] :variable constant function udf ([val val 1]1) tcoLLATE Collation] array_dim> [[x:]y [, [x:)y - num 'string' | charsetname 'string Const ant> efunction> CAST (val as datatype) UPPER (val) I GENID (generat or, val) expr>= A valid SQL expression that results in a single value. search _condition>= See CREATE TABLE for a full description. Notes on the UPDATE statement In SQL and isql, you cannot use val as a parameter placeholder (like *?*). In DSQL and isql, val cannot þe a variable. You cannot specify a COLLATE clause for Blob columns. Argument TRANSACTION transaction Description Name of the ransaction under control of which the statement is executed. table view SET col= val WHERE search_condition Name of an existing table or view to update. Specifies the columns to change and the values to assign to those columns. Searched update only, specifies the conditions a row must meet to be modified WHERE CURRENT OF Positioned update only;, specifies that the current row of a cursor's active set is to be modified. Not availiable in = PRESIDENCY COLLEGE 5 2.6 SBCA ORACLE DSQL and isql. Speciies columns to order, either by column name or ordinal number in the query, and the sort order (ASC or DESC) for the returned rows. Cursor ORDER BY order_list ROWS' value TO upper_value] BY step_value] IPERCENTIIWITH TIES] Value is the total number of rows to return if used by itself. Value is the starting row number to return if used with TO. Value is the percent if used with PERCENT. Upper_value is the last row or highest percent to return. If step_ value = n, returns every nth row, or n percent rows. PERCENT causes all previous ROWS values to be interpreled as percents. WI ES returns additional duplicate rows when the last value in the ordered sequence is the same as values in subsequent rows of tne reSuit set, must be used in conjunction with ORDER BY. Please also refer to ROWS syntax for Firebird 2.0 syntax, description and examples. New in Firebird 2.0: New extensions to UPDATE and DELETE Syntaxes ROWS specifications and PLAN and ORDERBY Clauses can now De use UPDATE and DELETE statements. Users can now specify explicit plans for UPDATE/DELETE stalements in order to optimize them manually. It is also possible to limit the number of aiecied rows with a ROWS clause, optionally used in combination wilh an ORDER BY clause to have a sorled record sel. Syntax UPDATE.. SET .. WHERE... PLAN <plan items>] (ORDER BY <value list>] (ROWS <value> [TO <value>]] Description UPDATE modifies one or more existing rows in a table or view. UPDATE is one of the database privileges controlled by GRANT and REVOKE. For searched updates, the optional WHERE clause can be used to restrict updates to a subset of rows in the table. Searched updates cannot update array slices Important Without a WHERE clause, a searched update modifies all rows in a table. When performing a positioned updale wilth a cursor, the WHERE CURRENT OF clause must be specified to uddate one row at a time in the aclive set. Note: When updating a blob column, UPDATE replaces the entire blob with a new value. Examples The following isql statement modifies a column for all rows in a table: UPDATE CITIES SET POPULATION = POPULATION 1.03; The next embedded SQL statement uses a WHERE clause to restrict column modification to a subset of rows: EXEC SQL UPDATE PROJECT SET PROJ_DESC :blob_id WHERE PROJ_ID = :proj_id; See also: UPDATE UPDATE OR INSERT Firebird 2.5 Release Notes OldSetClauseSemantics DELETE Removes rows in a table or in the active set of a cursor. Available in gpre, DSQL, and isal. Syntax SQL and DSQL form Important: Omit the terminating semicolon for DSQL. DELETE (TRANSACTION transaction] FROM table {WHERE search_conditio] | WHERE CURRENT OF cursor) [ORDER BY order_list ROWS value [TO upper_value] [BY step_value]|PERCENTIWITH TIES search_condition> = Search condition as specified in SELECT. isql form DELETE FROM TABLE WHERE search_condition: Argument Description TRANSACTION transaction Name of the transactlon under control of which the statement is executed; SQL only. 6 PRESIDENCY COLLEGE SBCA ORACLE Name of the table from which to delete roWs. Table 2.6 WHERE search_condition edicn condition that specifies the rows to delete; without this clause, DELETE affects all rows in tne speuliu table or view. WHERE CURRENT OF CUrsor Specities that the current row in the active set of cursor is to be deleled. ORDER BY order_list Es coumns to order, either by column name or ordinal number in the guery, and the sort order (ASC or DESC) for the returned rows. ROWS' value TO upper_value] BY step_value) PERCENTJIITH TIES Value is the total number of rows to return if used by itself. Value is the starting row number to return if used with TO. Value is the percentif used with PERCENT. Upper_value is the last row or highest percent to relurn. f step_value= n, returns every nth row, or n percent rows. PERCENT causes all previous ROWS values to be interpreted as percents. n Esetums addlitional duplicate rows when the last value in the ordered sequence is the same as values in subsequent rows of the resuit set, must be used in conjunction with ORDER BY. Please also refer to ROWS syntax for Firebird 2.0 syntax, description and examples. New in Firebird 2.0: New extensions toUPDATE, and DELETE Svntaxes- ROWS specifications and PLAN and ORDER BY clauses can now be used in UPDATE and DELETE stalements. Users can now specify explicit plans for UPDATE/DELETE statements in order to optimize them manually. It is also possible to limit the number of affected rows with a ROWS clause, optionally used in combination with an ORDER BY clause to have a sorted recordset. Syntax DELETE FROM. PLAN <plan items>] ORDER BY <value list>] ROWS value> [TO <value>|] Description DELETE specifies one or more rows to delete from a table or DELETE is one of the database privileges controlled by the GRANT and REVOKE statements The TRANSACTION clause can be used in multiple transaction SQL applications to specilfy which transaction controls the DELETE operation. The TRANSACTION clause is not available in DSQL or isql. For searched deletions, the optional WHERE dlause can be used to restrict deletions to a subset of rows in the table. Important Without a WHERE clause, a searched delete removes all rows from a table. When performing a positioned delete with a cursor, the WHERE CURRENT OF clause must be specified to delete one row at atime from the active set. Examples The following isql statement deletes all rows in a table: DELETE FROM EMPLOYEE_PROJECT The next embedded SQL statement is a searched delete in an embedded application. It deleles all rows where a host-language variable equals a column value. EXEC SQL DELETE FROM SALARY_HISTORY WHERE EMP_NO = :emp_ num; The following embedded SQL statements use a cursor and the WHERE CURRENT OF option to delete rows from CITIES with a population less than the host variable, min_pop. They declare and open a cursor that finds qualitying cities, fetch rows into the cursor, and delete the current row pointed to by the cursor. EXEC SQL DECLARE SMALL_CITIES CURSOR FOR SELECT CITY, STATE FROM CITIES WHERE POPULATION < min_pop; EXEC SQL OPEN SMALL_CITIES; EXEC SQL FETCH SMALL_CITIES INTO cityname, :statecode; WHILE (ISQLCODE) (EXEC SQL DELETE FROM CITIES WHERE CURRENT OF SMALL_CITIES; PRESIDENCY COLLEGE SBCA ORACLE 2.6 EXEC SQL FETCH SMALL_CITIES INTO :cityname, :statecode;} EXEC SQL CLOSE SMALL_CITIES; See also DELETE MERGE MERGE is used to combine the data of multiple tables. It is something of a combination of the INSERT and UPDATE elements. See also MERGE MERGE statement GuestHons 2/ou mean by Onacle9 Eplin 9 txpleiz in ddailee abouf h tredaras o Onaele 9 hohcet do Onaele9 Expleinhe elouikiecelon ot saL9 tollewinq Common ols, inaart, dalt, Cnerle, Saleed9 RDBN whaf en cema ackerlayu ob RD 9MS hwhat ts G. sha 1 DHL plainhe Comonds 6 DHL