oracle_faq2.doc

Upload: jyoti-bansal

Post on 14-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 ORACLE_Faq2.doc

    1/25

    How to change UserID and Password in Oracle.what are differenct types of joins. explain outer join.How to print output in Oracle.

    what is a data control component.

    why do we use DBMS ?what are logical objects in RDBMS (tables & views).what do you know about IDL?can we maintain mirror data in different databases.Data Integrity constraint is(a)to ensure the presence of primary key

    What is indexing in databases?What is atomicity?

    What is DBMS and RDBMS ?

    types of DBMS,queries

    Difference between Unique and primary

    what is a cursor

    types of cursors

    normalization

    normal forms

    whis is the best normal form

    what is an os

    what exactly os consists ?

    Types of joins ?

    what is a trigger ?

    can we create a table in oracle which is not in firstnormal formdifference between dbms and rdbmssql queries

  • 7/30/2019 ORACLE_Faq2.doc

    2/25

    types of indexing

    DML,DDL, SQL querry,primary key, whts a null

    diff btw DDL,DML, whts parallel DML,

    whts normalization explain with example till 3NF6>need for normalization

    Difference btw oracle 8.0,8i,9iWhat are pseudo columns? Give an example.(CURRVAl,LEVEL,NEXTVAL,ROWID,ROWNUM)

    What are synonyms? Example(An alias name to the table, which is used for locationtransparency)

    CREATE SYNONYM emp2 FOR emp@newyork;

    SELECT ename, job INTO my_ename, my_jobFROM emp2WHERE empno = my_empno;

    What are snapshots?What is indexing? What are its advantages?What is cluster? Advantages.

    How do you add primary key to the table alreadyexisting.What is table space?What partitioning. How many types of partitions?What is mutating table.When a table is in state of transition it is said to bemutating.

    Eg: If a row has been deleted then the table is said to

    be mutating and no operations can be done on the table

    except select.

    What is the keyword type?What is exists?What is a cursor? What are the types?

    Two types of cursors: implicit and explicit. PL/SQL declares a cursor implicitly for

    all SQL data manipulation statements, including queries that return only one row.

  • 7/30/2019 ORACLE_Faq2.doc

    3/25

    However, for queries that return more than one row, you must declare an explicit

    cursor or use a cursor FOR loop.

    Three commands to control the cursor: OPEN, FETCH, and CLOSE.

    Initialize the cursor with the OPEN statement, which identifies the active set.

    Then, you use the FETCH statement to retrieve the first row.

    You can execute FETCH repeatedly until all rows have been retrieved.

    Release the cursor with the CLOSE statement.

    DECLARE

    CURSOR c1 IS SELECT ename FROM emp;

    name1 emp.ename%TYPE;

    name2 emp.ename%TYPE;name3 emp.ename%TYPE;

    BEGIN

    OPEN c1;

    FETCH c1 INTO name1; -- this fetches first row

    FETCH c1 INTO name2; -- this fetches second row

    FETCH c1 INTO name3; -- this fetches third row

    ...

    CLOSE c1;

    END;

    Four attributes of cursor: %NOTFOUND, %FOUND, %ROWCOUNT, and

    %ISOPEN

    What is SGA?

    The SGA is a shared memory region allocated by the Oracle that contains Data and

    control information for one Oracle Instance.

    It consists of Database Buffer Cache and Redo log Buffer.

    How do you override function/procedures in oracle?What is raise_application_error.What are datafiles?What are the default table spaces?What are the background processes in oracle?What are control files?What is the minimum privilege for the user to connectdatabase.

  • 7/30/2019 ORACLE_Faq2.doc

    4/25

  • 7/30/2019 ORACLE_Faq2.doc

    5/25

    ORACLE

    Doubts:

    WHAT R SYNONYMS AND SEQUENCES IN PL/SQL; How can you store a image in the database.

    what do you mean by where current of C1

    LONG RAWdata type is used for storing BLOB's (binary large objects).( i.e. graphics and

    images)

    What is sound? ex built in function

    What is to_number, to_char?

    Integrity: the quality or state of being complete; unbroken condition; wholeness; entirety.

    Consistency: agreement, holding firmly.

    Constrain: to force into, or hold in, close bounds

    Introduction to OracleOracle is a comprehensive operating environment that packs the power of mainframe

    relation database management system into users micro computer. It provides a set of

    functional programs that user can use as tools to build structures and perform tasks.Because applications are developed on oracle are completely portable to the other versions

    of the programmer can create a complex application in a single user, environment and

    them move it to a multi user platform. Users do not have to be an expert to appreciateOracle but the better user understand the program, the more productively and creatively he

    can use the tools it provides

    Relational Database Management system

    A Relational Database Management System (RDBMS) can perform a wide

    range of tasks. It acts as a transparent interface between the physical storage and the logicalpresentation of data. It provides a set of more or less flexible and sophisticated tools for handling

    information.

    Users can use the tools to

    Define a Database

    Query the Database

    Add, Edit and Delete data.

    Modify the structure of the Database. Communicate with in the Networks.

    Exports and Imports the data.

    Security.

    Oracle the Right Tool

    To keep track of records is often the best reason to consider buying asoftware package. Choosing a proven product increase the chance that we will get a system

    capable of meeting all our needs .Oracle has had many years in the relational market to often on

  • 7/30/2019 ORACLE_Faq2.doc

    6/25

    the large, Complex applications. Although Oracle demands greater expertise on the part of the

    application developed, an application developed oracle will be able to keep pace with growth andchange in the world at large.

    Oracle Gives You Security and ControlOracle has several features that ensure the integrity of the data base. If an interruption

    occurs in processing, a Rollback can reset the database to a point before the disaster. If a restore is

    necessary, Oracle has a Roll forward command for recreating your database to its mast resent savepoint.

    Oracle provides user with several functions for securing data. Grant and Revoke

    commands limit access to information down to the row and column levels. Views are valuable

    feature for limiting access to the primary tables in the database.

    The Oracle Environment

    Oracle is a modular system that consists of the Oracle database and several functionalprograms. Oracles tools do four major things of work.

    1. Database Management.

    2. Data access and Manipulation.

    3. Programming4. Connectivity.

    Database Management Tools

    This (is usually known as RDBMS by oracle) includes the core programs for Oracles

    database management system, the Oracle database with its associated tables and views, which are

    stores information related to every fact of the database system. User name, user access rights, tableattribute, storage information and auditing data for disaster recovery are stored in the data

    dictionary.

    The Database Administrator

    The person responsible for a Database is called the Database Administrator (DBA).TheDBA has a special set of privileges and has completed over the database. Any system with more

    than one user should have a DBA. The functions of DBA include.Creating primary database storage structures.

    Modifying the structure of the database.

    Backing up and restoring the database.Monitoring database performance and efficiency.

    Transferring data between database and external files.

    Manipulating the physical location of the database.

    THE END USER

    End user has fewer complexes but equally important tasks. They must be able to Query the database.

    Generate printed output.

    Share data with or secure data from others.

    Use non-export methods to update the database.

    Define applications from a user point of view.

  • 7/30/2019 ORACLE_Faq2.doc

    7/25

    WHY ORACLE?

    Oracle is an open system i.e. The database is accessed by different data access

    languages like SQL, Visual Basic, Power Builders, Delphi, VC++,JAVA etc.

    Oracle supports database up to gigabytes in size.* Oracle supports large number of concurrent users.

    * Oracle supports true client/server environment. If enable processing to be spilt between

    database server and the client application programs.* Oracle provides high level of data security in terms of users, passwords privileges, and

    permissions.

    * Oracle database behaves same on all platform line Windows, Unix, Dos, Mainframes

    etc.

    Structure of Oracle Database:

    Physical structure:

    One or more data files, two of more log files, one control file.

    Logical structure:

    Table spaces,Segments, Extents, Data blocks.

    The data files contain all user data in terms of tables, index, and views. The log filescontain the information to open and be recovered, of Undone after a transaction (Rollback).

    The control file physical data, media information to open and manage data files .If the

    control file is damaged the server will not be able to open or use the database even if the databaseis undamaged.

    What are the Back ground processes in Oracle and what are they. ?

    There are basically 9 Processes but in a general system we need to mention the first fivebackground processes. They do the house keeping activities for the Oracle and are common in

    any system.

    a) Data Base Writer (DBWR):

    Data Base Writer Writes Modified blocks from Database buffer cache to Data Files. This is

    required since the data is not written whenever a transaction is committed.

    B)LogWriter(LGWR) ::

    LogWriter writes the redo log entries to disk. Redo Log data is generated in redo log buffer

    of SGA. As transaction commits and log buffer fills, LGWR writes log entries into a online redo

    log file.

    c) System Monitor (SMON):

    The System Monitor performs instance recovery at instance startup. This is useful forrecovery from system failure.

    d)Process Monitor(PMON) ::

    The Process Monitor performs process recovery when user Process fails. Pmon Clears and

    Frees resources that process was using.

    e) CheckPoint(CKPT) ::

    At Specified times, all modified database buffers in SGA are written to data files by

    DBWR at Checkpoints and Updating all data files and control files of database to indicate the

    most recent checkpoint.

    f)Archieves(ARCH) ::

  • 7/30/2019 ORACLE_Faq2.doc

    8/25

    The Archiver copies online redo log files to archival storal when they are busy.

    g) Recoveror(RECO) ::

    The Recoveror is used to resolve the distributed transaction in network

    h) Dispatcher (Dnnn):

    The Dispatcher is useful in Multi Threaded Architecture

    i) Lckn ::

    We can have upto 10 lock processes for inter instance locking in parallel sql.

    NORMALIZATION

    Normalization is a process of simplifying the relationship between data elements in a

    record. Through Normalization a collection of data in a record structure is replaced by successiverecord structures that are simpler and more predictable and therefore more manageable. It is

    process of reducing redundancy and eliminating the anomalies. (Anomaly means inconsistent

    state.)

    Normalization is carried out for four reasons:

    To Structure the data so that any pertinent relationships between entities can be

    represented.

    To permit simple retrieval of data in response to query and report requests.

    To simplify the maintenance of the data through updates, insertions, and deletion

    To reduce the need to restructure or reorganize data when new application requirements

    arise.

    Normalization can improve the quality of design for an application.

    There are totally Five Normal Forms (Rules) out of which, any database should necessarily satisfy

    three of them, those Three Normal Forms are as follows:

    First normal form is achieved when all repeating groups are removed so that a record isof fixed length. A repeating group, the re-occurrence of a data item within a record, is actuallyanother relation. Hence, it is removed from the record and treated as an additional record structure,

    or relation.

    Second Normal form should be in first normal form and no partial dependency exists.

    Means if we have a composite primary key (combination of 2 or more fields) then all the non keys

    must depend on the composite primary key. no attribute should depend upon the part of key.(forexample if Rollno and SSno is a composite key, then no other field in that particular table should

    be depedent upon either Rollno or ssno individually)

    Third Normal form is achieved when Transitive Dependencies are removed from a recorddesign.

    The general case is as follows:

    A, B and C are three data items in a record. If C is functionally dependent on B (2nd N.F) andB is functionally dependent on A Then C is functionally dependent on A Therefore, a Transitive

    Dependency exists.

    In data management, transitive dependency is a concern because data can inadvertently belost when the relationship is hidden. In the general case above, if A is deleted, then B and C are

    deleted also, whether or not this is intended. This problem is eliminated by designing the record

  • 7/30/2019 ORACLE_Faq2.doc

    9/25

    for third normal form. Conversion to third normal form removes the transitive dependency by

    splitting the relation into two separate relations.

    BCNF must be 3NF and every determinant is a candidate key. Candidate key is other than

    primary key, which uniquely identify each row in the table.For example ssno is PK then rollno becomes Candidate key.

    4NF and 5NF are depends on instance. We can not give a proper def.bcz it all depends on joins.

    CODDs 12 RULES" for a fully Relational DBMS

    INTRODUCTION

    According to Elmasri and Navathe (1994), Dr. E. F. Codd, the originator of the relational

    data model, published a two-part article in Computer World (Codd, 1985) that lists 12 rules forhow to determine whether a DBMS is relational and to what extent it is relational. These rules

    provide a very useful yardstick for evaluating a relational system. Codd also mentions that,

    according to these rules, no fully relational system is available yet. In particular, rules 6, 9, 10, 11,

    and 12 are difficult to satisfy.

    THE 12 RULES

    Rule 1: The Information Rule

    All information in a relational database is represented explicitly at the logical level in

    exactly one way by values in tables.All data is represented in the form of relations/tables (with rows and columns)Simple

    Consistent and versatile

    Rule 2: Guaranteed Access Rule

    Each and every datum (atomic value) in a relational database is guaranteed to be logicallyaccessible by resorting to a table name, primary key value, and column name. All Data is uniquely

    identified and accessible via this identity.

    Rule 3: Systematic Treatment of Null Values

    Null values (distinct from empty character string or a string of blank characters and distinct

    from zero or any other number) are supported in the fully relational DBMS for representing

    missing information in a systematic way, independent of data type.

    Rule 4: Dynamic On-line Catalog based on the Relational Model

    The database description is represented at the logical level in the same way as ordinarydata, so authorized users can apply the same relational language to its interrogation as they apply

    to regular data.

    Rule 5: Comprehensive Data Sublanguage Rule

    A relational system may support several languages and various modes of terminal use (for

    example, the fill-in-blanks mode). However, there must be at least one language whose statements

    are expressible, per some well-defined syntax, as character strings and whose ability to support all

  • 7/30/2019 ORACLE_Faq2.doc

    10/25

    of the following is comprehensible: data definition, view definition, data manipulation (interactive

    and by program), integrity constraints, and transaction boundaries (begin, commit, and rollback).

    Rule 6: View Updating Rule

    All views that are theoretically updateable are also updateable by the system.Views are virtual tables. They appear to behave as conventional tables except that they are built

    dynamically when the query is run. This means that a view is always up to date. It is not always

    theoretically possible to update views. One problem exists when a view relates to part of a tablenot including a candidate key. This means that potential updates would violate the entity integrityrule.

    Rule 7: High-level Insert, Update, and Delete

    The capability of handling a base relation or a derived relation as a single operand applies

    not only to the retrieval of data but also to the insertion, update, and deletion of data. i.e. The user

    should be allowed to Delete, Update a set of tuples (rather than row by row)

    Rule 8: Physical Data Independence

    Application programs and terminal activities remain logically unimpaired whenever any

    changes are made in either storage representation or access methods. i.e. Users and programs arenot dependent on the physical structure of the database.

    Rule 9: Logical Data Independence

    Application programs and terminal activities remain logically unimpaired when

    information-preserving changes of any kind that theoretically permit unimpairment are made to

    the base tables. Users and Programs are independent of the logical structure of the database, i.e.the logical structure of the data can evolve with minimal impact on the programs.

    Rule 10: Integrity Independence

    Integrity constraints specific to a particular relational database must be definable in the

    relational data sublanguage and storable in the catalog, not in the application programs. Aminimum of the following two integrity constraints must be supported:

    1. Entity integrity: No component of a primary key is allowed to have a null value.2. Referential integrity: For each distinct non-null foreign key value in a relational database,

    there must exist a matching primary key value from the same domain.

    Rule 11: Distribution Independence

    A relational DBMS has distribution independence. Distribution independence implies that

    users should not have to be aware of whether a database is distributed. Applications should stillwork in a distributed database (DDB).

    Rule 12: Nonsubversion RuleIf a relational system has a low-level (single-record-at-a-time) language, that low-level

    language cannot be used to subvert or bypass the integrity rules or constraints expressed in the

    higher-level (multiple-records-at-a-time) relational language.

    If there is a record at a time interface (e.g. via 3GL), Security and integrity of the databasemust no be violated. There should be no backdoor to bypass the security imposed by the DBMS.

    On the basis of the above rules, there is no fully relational DBMS available today.

  • 7/30/2019 ORACLE_Faq2.doc

    11/25

    Questions and Answers:

    What is Pseudo Column?USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL

    How to Display output in PL/SQL?

    We first set serveroutput on at SQL Prompt. And then in sql programming we specifyas dbms_output.put_line(hdjhd || sakdha);

    No Displays are allowed in PL/SQL programming with select statement

    Write about Commands and Keywords?

    Alter : ALTER TABLE EMP ADD . , MODIFY . ;

    for a in 1..10 loop .. end loop;

    loop exit when a= g.losal;

    Outer join: ***********e.deptno(+)=d.deptno;

    Different types of Keys?

  • 7/30/2019 ORACLE_Faq2.doc

    12/25

    Foreign Key: This is a referential integrity constraint and specifies the values of primary

    key in other table and is mentioned as:DEPTNO number(2) REFERENCES DEPT(DEPTNO);

    The clause ON DELETE CASCADE added to REFERENCES clause tells Oracle to delete the

    dependent rows when we delete the row in the parent table.

    Unique Key: If declared, then does not accept duplicate and also NULL values. And can

    have many unique key fields.

    Primary Key: Similar to Unique key but, also maintains an index on primary key and alsoused to connect two tables.

    Write about cursors?

    Implicit (SQL is implicit by default) and Explicit cursors.EXIT WHEN C1%NOTFOUND, IF C1%FOUND THEN, IF C1%ISOPEN THEN,

    FOR LOOP in CURSOR will:

    1) Open the cursor.2) Fetches the records from cursor one by one.

    3) Keeps the track of number of records in the cursor.

    Super Dynamism in Cursors is obtained by passing the values as parameters (i.e. pass by value)

    i.e., for x in c1 (a,b)Multiple Cursors: These are nothing but nested cursors..

    In Implicit Cursors there is no need of declaration of cursors, by default system will create

    a cursor whenever a query is writtenand the conditions are like if SQL%NOTFOUND

    If SQL%ROWCOUNT > 2 will keep a count of the number of records updated.

    SQL is a keyword and cannot be used to name as a cursor name explicitly.

    Difference between group functions and single row functions?

    Group Function Single Row Function

    A group function operates a single row functionon many rows returns one and result for one row.

    returns single result.Not allowed in Pl/sql procedural Allowed in Pl/Sql Procedural statements

    e.g. SUM(),AVG,MIN,MAX etc e.g. UPPER,LOWER,CHR...

    Difference between DECODE and TRANSLATE?

    DECODE is value by value TRANSLATE is character bycharacter replacement. replacement.

    Ex SELECT DECODE ('ABC','A',1,'B',2,'ABC',3) eg SELECT

    from dual; o/p 3 TRANSLATE('ABCGH','ABCDEFGHIJ', 1234567899)

    FROM DUAL; o/p 12378

    (DECODE command is used to bring IF, THEN, ELSE logic to SQL. It tests for the IF values(s)and then applies THEN value(s) when true, the ELSE value(s) if not.)

    Difference between TRUNCATE and DELETE?

    TRUNCATE deletes much faster than DELETE

    Truncate Delete

    It is a DDL statement It is a DML statement

    It is a one way trip, cannot One can RollbackROLLBACK

    Doesn't have selective features (where clause) Has

  • 7/30/2019 ORACLE_Faq2.doc

    13/25

    Doesn't fire database triggers Does

    It requires disabling of referential Does not requireConstraints.

    What is a CO-RELATED SUBQUERY?

    A CO-RELATED SUBQUERY is one that has a correlation name as table or view designator in

    the FROM clause of the outer query and the same correlation name as a qualifier of a search

    condition in the WHERE clause of the sub query.eg SELECT field1 from table1 X WHERE field2>(select avg(field2) from table1 Ywhere field1=X.field1);

    (The subquery in a correlated subquery is revaluated for every row of the table or view

    named in the outer query.)

    What are various joins used while writing SUBQUERIES?

    Self join-Its a join foreign key of a table references the same table.

    Outer Join--Its a join condition used where one can query all the rows of one of the

    tables in the join condition even though they don't satisfy the join condition.

    Equi-join--Its a join condition that retrieves rows from one or more tables in which one or

    more columns in one table are equal to one or more columns in the second table.

    What are various constraints used in SQL?

    NULL, NOT NULL, CHECK, DEFAULT

    What are different Oracle database objects?

    TABLES, VIEWS, INDEXES, SYNONYMS, SEQUENCES, TABLESPACES etc

    What is difference between Rename and Alias?

    Rename is a permanent name given to a table or column whereas Alias is a temporaryname given to a table or columns which do not exist once the SQL statement is executed.

    What is a view ?

    A view is stored procedure based on one or more tables, its a virtual table.

    What are various privileges that a user can grant to another user?

    SELECT, CONNECT, RESOURCES

    What is difference between UNIQUE and PRIMARY KEY constraints?

    A table can have only one PRIMARY KEYwhereas there can be any number ofUNIQUEkeys. The columns that compose PK are automatically define NOT NULL, whereas a column that

    compose a UNIQUEis not automatically defined to be mandatory must also specify the column is

    NOT NULL.

    Can a primary key contain more than one column?

    Yes

    How you will avoid duplicating records in a query?

    By usingDISTINCT

    What is difference between SQL and SQL*PLUS?

  • 7/30/2019 ORACLE_Faq2.doc

    14/25

    SQL*PLUS is a command line tool where as SQL and PL/SQL language interface and

    reporting tool. Its a command line tool that allows user to type SQL commands to be executeddirectly against an Oracle database. SQL is a language used to query the relational database

    (DML, DCL, and DDL). SQL*PLUS commands are used to format query result, Set options, Edit

    SQL commands and PL/SQL.

    Which data type is used for storing graphics and images ?

    LONG RAWdata type is used for storing BLOB's (binary large objects).

    How will you delete duplicating rows from a base table?

    DELETE FROMtable_name A WHERErowid> (SELECT min (rowid) from table_name B where

    B.table_no=A.table_no);CREATE TABLEnew_tableAS SELECT DISTINCT * FROMold_table;

    DROPold_table

    RENAMEnew_table TO old_table DELETEFROM table_name A

    WHERErowidNOT IN(SELECT MAX (ROWID) FROMtable_name

    GROUP BYcolumn_name)

    What is difference between SUBSTR and INSTR?

    SUBSTR returns a specified portion of a string eg SUBSTR ('BCDEF', 4) output BCDE

    INSTR provides character position in which a pattern is found in a string.eg INSTR('ABC-DC-F','-',2) output 7 (2nd occurrence of '-')

    There is a string '120000 12 0 .125, how you will find the position of the decimal place?

    INSTR('120000 12 0 .125',1,'.')

    output 13

    There is a '%' sign in one field of a column. What will be the query to find it?

    '\' should be used before '%'.

    When you use WHERE clause and when you use HAVING clause?

    HAVING clause is used when you want to specify a condition for a group function and it is

    written after GROUP BY clause

    The WHERE clause is used when you want to specify a condition for columns, single rowfunctions except group functions and it is written before GROUP BY clause if it is used.

    Which is faster - IN or EXISTS?

    EXISTS is faster than IN because EXISTS returns a Boolean value whereas IN returns a

    value.

    What is an OUTER JOIN?

    Outer Join--Its a join condition used where you can query all the rows of one of the tables

    in the join condition even though they dont satisfy the join condition.

    What is a pseudo column? Give some examples?

    It is a column that is not an actual column in the table.

    e.g. USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL.

  • 7/30/2019 ORACLE_Faq2.doc

    15/25

    Suppose customer table is there having different columns like customer no, payments. What

    will be the query to select top three max payments?

    SELECT customer_no, payments from customer C1 WHERE 3

  • 7/30/2019 ORACLE_Faq2.doc

    16/25

    COMMIT;

    END;

    What is use of a cursor variable? How it is defined?

    A cursor variable is associated with different statements at run time, which can holddifferent values at run time. Static cursors can only be associated with one run time query. A

    cursor variable is reference type (like a pointer in C).

    Declaring a cursor variable:TYPE type_name IS REF CURSOR RETURN return_type type_name is the name ofthe reference type,return_type is a record type indicating the types of the select list that

    will eventually be returned by the cursor variable.

    What should be the return type for a cursor variable? Can we use a scalar data type as

    return type?

    The return type for a cursor must be a record type. It can be declared explicitly as a user-defined or%ROWTYPE can be used. eg TYPE t_studentsref IS REF

    CURSOR RETURN students%ROWTYPE

    How you open and close a cursor variable. Why it is required?OPEN cursor variable FOR SELECT...Statement

    CLOSE cursor variable In order to associate a cursor variable with a particular

    SELECT statement OPEN syntax is used. In order to free the resources usedfor the query CLOSE

    statement is used.

    How you were passing cursor variables in PL/SQL 2.2 ?

    In PL/SQL 2.2 cursor variables cannot be declared in a package.This is because the storage

    for a cursor variable has to be allocated using Pro*C or OCI with version 2.2,the only means ofpassing a cursor variable to a PL/SQL block is via bind variable or a procedure parameter.

    Can cursor variables be stored in PL/SQL tables.If yes how.If not why?

    No, a cursor variable points a row which cannot be stored in a two-dimensional PL/SQL table.

    Difference between procedure and function ?

    Functions are named PL/SQL blocks that return a value and can be called with argumentsprocedure a named block that can be called with parameter. A procedure all is a PL/SQL statement

    by itself, while a Function call is called as part of an expression.

    What are different modes of parameters used in functions and procedures ?

    IN, OUT, INOUT.

    What is difference between a formal and an actual parameter ?

    The variables declared in the procedure and which are passed, as arguments are called actual,

    the parameters in the procedure declaration. Actual parameters contain the values that are passed

    to a procedure and receive results. Formal parameters are the placeholders for the values of actualparameters.

    Can the default values be assigned to actual parameters?

    Yes

  • 7/30/2019 ORACLE_Faq2.doc

    17/25

    Can a function take OUT parameters? If not why?

    No. A function has to return a value, an OUT parameter cannot return a value.

    What is syntax for dropping a procedure and a function ?

    Drop Procedure procedure_nameDrop Function function_name

    What are ORACLE PRECOMPILERS?Using ORACLE PRECOMPILERS, SQL statements and PL/SQL blocks can be contained inside3GL programs written in C,C++,COBOL,PASCAL, FORTRAN,PL/1 AND ADA.

    The Precompilers are known as Pro*C,Pro*Cobol,...

    This form of PL/SQL is known as embedded pl/sql,the language in which pl/sql is embedded isknown as the host language.

    The prcompiler translates the embedded SQL and pl/sql ststements into calls to the precompilerruntime library.The output must be compiled and linked with this library to creater an executable.

    What is OCI? What are its uses?

    Oracle Call Interface is a method of accessing database from a 3GL program. Uses--Noprecompiler is required, PL/SQL blocks are executed like other DML statements.

    The OCI library provides

    -functions to parse SQL statements-bind input variables

    -bind output variables

    -execute statements-fetch the results

    Difference between database triggers and form triggers ?

    a) Data base trigger(DBT) fires when a DML operation is performed on a data base table.Form

    trigger(FT) Fires when user presses a key or navigates between fields on the screenb) Can be row level or statement level No distinction between row level and statement level.

    c) Can manipulate data stored in Oracle tables via SQL Can manipulate data in Oracle tables aswell as variables in forms.

    d) Can be fired from any session executing the triggering DML statements. Can be fired only

    from the form that define the trigger.e) Can cause other database triggers to fire.Can cause other database triggers to fire,but not other

    form triggers.

    What is an UTL_FILE.What are different procedures and functions associated

    with it ?

    UTL_FILE is a package that adds the ability to read and write to operating system filesProcedures associated with it are FCLOSE, FCLOSE_ALL and 5 procedures to output data to afile PUT, PUT_LINE, NEW_LINE, PUTF, FFLUSH.PUT,

    FFLUSH.PUT_LINE,FFLUSH.NEW_LINE. Functions associated with it are FOPEN, ISOPEN.

    Can you use a commit statement within a database trigger ?

    No

    What is maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE

    function?

  • 7/30/2019 ORACLE_Faq2.doc

    18/25

    1,000,000

    What is index ?

    INDEX is a general term for an ORACLE / SQL feature used primarily to speed execution an

    impose UNIQUENESS upon certain data. INDEX provides a faster access method to one tablesdata than doing a full table scan.

    There are several types of Indexes :

    UNIQUE INDEX, COMPRESSED INDEX, CONCATENATED INDEX. An Index has an entryfor each value found in the tables Indexed field(s) ( except those with a NULL value ) andpointer(s) to the rows having that value.

    What is Data Dictionary ?

    The DATA DICTIONARY is a comprehensive set of tables and views owned by the DBA

    users SYS and SYSTEM, which activates when ORACLE is initially installed, and is a cental

    source of information for the ORACLE RDBMS itself and for all users of ORACLE. The tablesare automatically maintained by ORACLE, and holds a set of views and tables containing

    information about the database objects, users, privileges, events, and use.

    What is a package ?A PACKAGE is a PL/SQL object that groups PL/SQL types, variables, SQL cursors,

    exceptions,procedures, and functions.Each package has a specification and a body. The

    specification shows the object you can access when you use the package. The body fully definesall the objects and can contain additional objects used only for the internal workings. You can

    change the body (for example, by adding procedures to the packages) without invalidating any

    object that uses the package.

    What is Schema ?

    A SCHEMA is a collection of objects.SCHEMA objects are logical structures that directly refer to the databases data.

    SCHEMA objects include structures such as tables, views, synonyms, sequences, indexes,clusters, stored procedures and data links.

    1. What is a View ? Why is it required to define a View ?

    A View is a database object that is a logical representation of a table. It is derived from a

    table but has no storage space of its own and often may be used in the same manner as a table.Advantage: 1. Security 2. Complex query can be replaced.

    2. Can we create a View without a table ?

    Yes, Using the FORCE option in the CREATE VIEW syntax.

    Ex: CREATE FORCE VIEW view_name as SELECT column name, columnname..

    FROM table_name;

    3. What is the difference between a SYNONYM and a VIEW ?

    A SYNONYM is a name assigned to a table or view that may thereafter be used to refer it.

    If you access to another users table, you may create a synonym for it and refer to it by thesynonym alone, without entering the users name as a qualifier.

    Difference: A View can be based on MULTIPLE Tables whereas a SYNONYM is based on a

    single object only.

    4. What is SNAPSHOT ? What is a SNAPSHOT LOG ?

  • 7/30/2019 ORACLE_Faq2.doc

    19/25

    A SNAPSHOT is a means of creating a local copy of remote data. A snapshot can be

    used to replicate all or part of a single table, or to replicate the result of a query against multipletables. The refreshes of the replicated data can be done automatically by the database ( at time

    intervals you specify ) or manually.Snapshot Log is the table associated with the Master Table of

    the Snap shot.

    5. What is a DATABASE trigger ? What is a DATABASE Procedure ?

    A DATABASE TRIGGER is a stored procedure associated with a table that ORACLE7automatically executes on one or more specified events (BEFORE or AFTER anINSERT,UPDATE or DELETE) affecting the table. Triggers can execute for the table as a whole

    or for each affected row in the table.

    A PACKAGED PROCEDURE is a built-in PL/SQL procedure that is available in allforms. Each packaged procedure executes a SQL*FORMS function, such as moving to a field or

    executing a query.

    8. What is a CURSOR ?

    A work area in memory where ORACLE stores the current SQL statement. For a query ,

    the area in memory also includes column headings and one row retrieved by the SELECT

    statement.

    10. Can we pass a PARAMETER to CURSOR ? What is SQL%ROWCOUNT ?

    We can pass parameter to CURSOR. Eg: OPEN CUSOR(VASAN).

    SQL%ROWCOUNT is used to count the number of rows returned by an SQL DML statement. Itwill return zero if the DML statement doesnt return any row.

    15. Can we use a funtion inside an INSERT statement ?

    Yes. Eg: INSERT INTO EMP(COMM ) VALUES ( SAL*0.05 ) WHERE DEPTNO = 20;

    16. What is TRUNCATE table ?

    TRUNCATE table is a DDL command used to remove all the rows from the specified

    table or cluster instantly. Eg: TRUNCATE TABLE table_name;

    17. What is ROWID ? What are its components ?

    ROWID is the logical address of a row, and it is unique within the database.The ROWID

    is broken into three sections: left,middle,, and right (corresponding to 00001F20,000C, AND

    0001, just shown). The numbering is in hexadecimal notation.The left section is the block in the file, the middle is the row sequence number within the

    block(numbering starts with 0, not 1), and the right is the file number within the database. Note

    that the file numbers are uniquewithin the whole database. The tablespace they are in is notrelevant to the ROWID.

    ROWID can be selected, or used in a where clause, but cannot be changed by an insert,

    update, or delete. However it can changeif the table it is in is exported and imported.

    21. Name any ORACLE defined EXCEPTION ?

    CURSOR_ALREADY_OPEN, NO_DATA_FOUND, INVALID_NUMBER.

    22. Can we define our OWN EXCEPTION ? How to raise it ?

    In the DECLARATION part define a variable of type exception. In the excecution part call

    the exception using RAISE exception_name. In the exception part handle the exception usingWHEN exception_name.

  • 7/30/2019 ORACLE_Faq2.doc

    20/25

    23. What is a PRAGMA ?

    It is a directive to the COMPILER, rather than a piece of executable code. Eventhough itappears in the program, it is not executable. It gives instructions to the compiler.

    24. Difference between CHAR and VARCHAR2 ?

    CHAR(size) - It is a fixed length character data, size characters long. It is padded with

    BLANKS ON RIGHT to the full length ofsize. DEFAULT - 1 bytes, MAXIMUM - 255 bytes.

    VARCHAR2(size) - It is a varable length char string having a maximum ofsizebytes.MAXIMUM - 2000 bytes.

    25. What is a CURSOR FOR LOOP ?

    The CURSOR FOR LOOP lets you implicitly OPEN a cursor, FETCH each row returnedby the query associated with the cursor and CLOSE the cursor when all rows have been processed.

    26. What are the possible CONSTRAINTS defined on a TABLE ?

    NOT NULL, UNIQUE KEY, PRIMARY KEY, FOREIGN KEY and CHECK constraints.

    27. What is APPLICATION PARTITIONING ?

    PL/SQL is the language used for both client-side Oracle forms applications and server-sidedatabase triggers and stored procedures and there is a PL/SQl engine in both Oracle forms

    Runform and the Oracle7 Server.

    This means that you can take advantage of application patitioning to execute applicationcode on either the client or the server.

    Application partitioning allows you to optimize performance and resource usage by storing

    and executing procedures either locally or at the server, which makes the most sense for yourparticular application and configuration.

    28. Difference between a STORED PROCEDURE and a STORED FUNCTION ?

    Unlike procedures, FUNCTIONS returns a VALUE to the caller. This value is returned

    thro the RETURN command/keywordwithin the function.Functions dont use the IN, OUT | IN OUT arguments, which are available for

    PROCEDURES.

    29. How to RUN PROCEDURES from SQL PROMPT ?

    Use EXECUTEProcedure_name command.

    30. How to TRAP ERRORS in procedures ?

    Use SHOW_ERRORS. this will display all the errors associated with the most recentlycreated procedural object. This command will check the VIEW_ERRORS data dictionary for the

    ERRORS associated with the most recent compilation attempt for that procedural object.

    SHOW_ERRORS will display the LINE and COLUMN NO. for each error, as well as thetext of the error message.

    DBMS_OUTPUT package allows you to use 3 debugging functions within your package. You

    must set SERVER OUTPUT ON before executing the procedure object you will be debugging.PUT - Puts multiple o/ps on same line.

    PUT_LINE - Puts each o/p on a separate line.

    NEW_LINE - Used with PUT; Signals the END of current o/p line.

    38. What is the DIFFERENCE between PRE-QUERY and POST-QUERY ?

  • 7/30/2019 ORACLE_Faq2.doc

    21/25

    PRE-QUERY fires ONLY ONCE during EXECUTE-QUERY or COUNT-QUERY

    processing, just before Oracle Forms constructs and issues the SELECT statement to identify rowsthat match the query criteria.

    POST-QUERY fires each time for records placed on the blocks list of records.

    41. What is the DIFFERENCE between EXPLICIT CURSOR & IMPLICIT CURSOR ?

    IMPLICIT CURSORS are automatically opened by issuing a SELECT statement. But the

    EXPLICIT cursors are to be opened using OPEN, fetching is done using FETCH and closingusing CLOSE.

    42. What is the difference between ROWID and ROWNUM ?

    ROWID is the logical address of the row, whereas ROWNUM returns the sequence no. inwhich the row was retrieved when first feched from a table.

    43. What is the RESULT of the statement ?

    SELECT EMPNO, NAME,SAL FROM EMP WHERE ROWNUM >2;

    Result : 0, No rows will be selected.

    44. How do you evaluate performance ?Using SQL TRACE. It is an utility that can monitor and report on database performance

    when one or more queries are run against the database.

    It is used to gather statistics when running the query (i.e) reports on CPU time spent on thequery, the total no. of rows processed and statistics related to parsing and cache performance.

    53. What is a DEAD LOCK ?

    A DEAD lock is a rare situation in which two or more user processes of a database cannot

    complete their tansactions.This occurs because each process is holding a resource that the other

    process requires (such as a row in a table) in order to complete.

    63. What does GROUP BY statement do ?GROUP BY statement causes a SELECT statement to produce ONE SUMMARY ROW

    for all selected rows that have identical values in one or more specified column or expressions.Each expe\ressionin the SELECT clause must be one of the following :

    1] A CONSANT

    2] A Function without parameters3] A GROUP function like SUM , AVG.

    4] Matched IDENTICALLY to a expression in the GROUP BY clause.

    75. Difference between SQL and PL/SQL ?

    SQL is the ANSI industry standard language, used to manipulate information in a

    relational database.PL/SQL is the procedural language extension to Oracles SQL language.

    SQL PL/SQL

    1. It is flexible, Powerful and easy to learn.

    2. It is a non-procedural language. It

    a] Processes set of records rather than

    just one at a time andb] Provides automatic navigation to the

    data.

    1. PL/SQL block can contain any no. of

    SQL statements combined with thefollowing :

    a] Flow of control statements such as

    IF..THEN, ELSE, EXIT and GOTO.b] Repetition statements such as FOR ..

    LOOP and WHILE .. LOOP.

  • 7/30/2019 ORACLE_Faq2.doc

    22/25

    3. It provides commands for avariety oftasks including :

    a] Querying data

    b] Creating,Updating and Replacingobjects and Inserting, Updating

    and Deleting rows.

    4] All RDBMS supports SQLThus one can transfer the skills gained

    with SQL from one

    RDBMS to another.

    Programs written in SQL are portable,they can often be moved from one database

    to another with little modification.

    c] Assignment statements such as X := Y +

    Z

    2. PL/SQL allows you to logically group a

    set of statements and send them to theRDBMS as a single block.

    3. Procedural capabilities.4. Improved performance.5. Enhanced productivity

    6. Portability

    7. Integration with the RDBMS.

    77. What is the purpose of OUTER JOIN ?

    An OUTER JOIN returns all the rows returned by simple join as well as those rows from

    one table that do not match any row from the other table. The symbol (+) represents the outer join.

    78. Difference between EQUI JOIN and OUTER JOIN ?EQUI JOIN returns rows from both the tables provided they both have the same

    column_name in the where clause. The symbol (=) represents the EQUI JOIN.

    For OUTER JOIN see previous answer.

    79. Define NORMALIZATION ?

    NORMALIZATION is the process of putting things right, making them normal. It is apart of analysis necessary to understand a business, and build a useful application.

    The normalization of data ensures

    a] Minimization of duplication of data.b] Providing flexibility to support different funtional requirements.

    c] Enabling the model to be translated to database design.

    STEPS INVOLVED IN NORMALIZATION

    1] Ensure that all the ENTITIES are uniquely identified by a combination of attributes.

    2] Remove repeated attributes or group of attributes, to place the entities in the first

    normal form.3] Remove attributes that are dependent on only part of the identifier.

    4] Remove attributes that are dependent on attributes which are not part of the identifier.

    85. What is the Purpose of ERASE command ?

    ERASE removes an indicated Global variable & releases the memory associated with it

    What is LookUp table ?

    When a foreign key exists in a table, the foreign key's table is sometimes referred to as a

    lookup table. The DEPARTMENT table in our example is a lookup table for the EMPLOYEE

    table. The value of an employee's department can be looked up in the DEPARTMENT table.

  • 7/30/2019 ORACLE_Faq2.doc

    23/25

    MULTIPLE CHOICE QUESTIONS

    11. The purpose of defining an index is

    (A) Enhance Sorting Performance (B) Enhance Searching Performance

    (C) Achieve Normalization (D) All of the above

    12. A transaction does not necessarily need to be

    (A) Consistent (B) Repeatable (C) Atomic (D) Isolated

    13. To group users based on common access permission one should use

    (A) User Groups (B) Roles (C) Grants (D) None of the above

    14. PL/SQL uses which of the following

    (A) No Binding (B) Early Binding (C) Late Binding (D) Deferred Binding

    15. Which of the constraint can be defined at the table level as well as at the column level

    (A) Unique (B) Not Null (C) Check (D) All the above

    16. To change the default date format in a SQLPLUS Session you have to(A) Set the new format in the DATE_FORMAT key in the windows Registry.

    (B) Alter session to set NLS_DATE-FORMAT.

    (C) Change the Config.ora File for the date base.(D) Change the User Profile USER-DATE-FORMAT.

    17. Which of the following is not necessarily an advantages of using a package rather thanindependent stored procedure in data base.

    (A) Better performance. (B) Optimized memory usage.

    (C) Simplified Security implementation. (D) Encapsulation.

    18. Integrity constrains are not checked at the time of(A) DCL Statements. (B) DML Statements.

    (C) DDL Statements. (D) It is checked all the above cases.

    19. Roll Back segment is not used in case of a

    (A) DCL Statements. (B) DML Statements. (C) DDL Statements. (D) all of the above.

    QUERIES

    Where do we use distinct keyword ?

    Distinct is used to avoid duplicating records

    DELETEFROM table_name A

    WHERE rowid>(SELECT min(rowid) from table_name B where

    B.table_no=A.table_no);

  • 7/30/2019 ORACLE_Faq2.doc

    24/25

    CREATE TABLE new_table AS SELECT DISTINCT * FROM old_table;

    DROP old_table

    RENAME new_table TO old_table

    DELETE FROM table_name AWHERE rowid NOT IN (SELECT MAX(ROWID) FROM table_name

    GROUP BY column_name)

    How you will avoid your query from using indexes ?

    SELECT * FROM empWhere emp_no+' '=12345;

    i.e you have to concatenate the column name withspace within codes in the where condition.

    SELECT /*+ FULL(a) */ ename, emp_no from emp

    where emp_no=1234;i.e using HINTS

    Guidelines for developers working with Databases

    Should follow the Hungarian Style in naming the Database name (SQL server), Schema

    name(Oracle), field/column name in the respective databases.

    Example:

    EmployeeName ------ CorrectEmpName, empname, emp_name ------ Incorrect

    If the Column/Table name exceeds more than 30 characters the developer can go for

    abbreviated names, but it should be completely relevant to the work what the table is

    doing.

    For Example: The ProjectSpecificPreferencesDetails Table can be named ProjSpecPrefDetails,

    which is meaningful and also satisfies the field/columns length.

    Avoid using UnderScores( _ ) while naming Columns and Tables.

    Should use the concepts of Stored Procedures (SQL Server), Procedures (Oracle),

    Functions, Triggers where ever necessary in the database design Try to avoid unnecessary

    connections in the database server in a loop. Using Procedures,

    Functions and Triggers solves this problem. Another alternative is to get the whole datainto the client and try to solve the problem in the client level only, instead of interacting

    with the server for several times in a loop.

  • 7/30/2019 ORACLE_Faq2.doc

    25/25

    Should follow the Normalization concepts properly. Try to achieve the Third Normal Form

    for the data base which is designed, it is considered to be more efficient.(Normal Forms are

    discussed below)

    No table in the database should be independent. Every table should be related with one or

    the other table.

    Should follow the concept of index in the database. Multiple indexing is advisable if there

    is an assumption of storing huge data. Retrieval of data will be faster if indexes are used.