Answered Questions

  • Find Base Table of the View

    Views are created on the basis of base tablesWhat is the query to know the base table of the view? How to know the details of base table?

    Prem_p

    • Apr 28th, 2011

    Guys, you don't need a dba privilege for this.Run the query:select * from USER_DEPENDENCIES where  type='VIEW' and name=''This will give you the dependent object information (name , type of the obje...

  • Index Use

    If you have a three columns table with one index on 2nd Column. In the SELECT statement you retrived column 1, can index be used or not?

    geetha

    • Jul 30th, 2011

    Index will be used if the retrieval is based on an indexed column .if the where clause uses a column with index then the query will be executed based on that index.

  • Single Row Function

    Display details of employees having same char at the star and end postition of their namelike abishikathis name have last character and first character is same

  • How do you print the last n rows or the first n rows of a table ?

    Star Read Best Answer

    Editorial / Best Answer

    nirmal1in  

    • Member Since Jan-2010 | Jan 17th, 2010


    This can be accomplished in following way:

    Example: table - emp

    For First n rows:

    SELECT * FROM
    (SELECT empno,ename,job,row_number() over (order by ename desc) a
    FROM emp) x
    WHERE x.a < 5 --- say n is 5 display first 5 records

    For last n rows:

    SELECT * FROM
    (SELECT empno,ename,job,row_number() over (order by ename) a
    FROM emp) x
    WHERE x.a < 5

    FROM )WHERE .a<

    This query can be used for finding nth row also say n = 5

    SELECT * FROM
    (SELECT empno,ename,job,row_number() over (order by ename desc) a
    FROM emp) x
    WHERE x.a = 5

    deepthi

    • May 17th, 2012

    Code
    1. SELECT rownum,a.*FROM(SELECT rownum,b.*FROM emp b ORDER BY rownum DESC) a WHERE rownum <&n;

  • What is the difference between procedure and function and package, which is the fastest

    Varun Tiwari

    • Jul 4th, 2013

    Function Procedure 1. Can be used as column Cant used in select statement in select statement 2. Can be used in where Cant used in where condition c...

  • What  are % TYPE and % ROWTYPE ? What are the advantages of using these over datatypes?

     %  TYPE  provides  the data type of a variable or a database column to that variable. % ROWTYPE  provides the record type that represents a entire row of a table or view or columns selected in the cursor. The advantages are : I. Need not  know about variable's data typeii.  If  the  database  definition of a column in a table changes, the...

    PRADEEP

    • Oct 16th, 2012

    %rowtype is associated entire table(if we want to declare all columns then we need to declare %rowtype).

    %type is associated with one column .(if we want to declare entire column then we need to declare %type).

    Yaseen

    • Aug 9th, 2012

    If using %type and %rowtype , no need to know the the data type of the table column . and once the development is finished , the type of column is changed it will not effect the coding.

  • What is a join

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: NK

    • Jun 29th, 2005


    A join is a query that combines rows from two or more tables, views, or materialized views. Oracle performs a join whenever multiple tables appear in the query's FROM clause. The query's select list can select any columns from any of these tables. If any two of these tables have a column name in common, then you must qualify all references to these columns throughout the query with table names to avoid ambiguity. 
     
    Most join queries contain WHERE clause conditions that compare two columns, each from a different table. Such a condition is called a join condition. To execute a join, Oracle combines pairs of rows, each containing one row from each table, for which the join condition evaluates to TRUE. The columns in the join conditions need not also appear in the select list. 
     
    To execute a join of three or more tables, Oracle first joins two of the tables based on the join conditions comparing their columns and then joins the result to another table based on join conditions containing columns of the joined tables and the new table. Oracle continues this process until all tables are joined into the result. The optimizer determines the order in which Oracle joins tables based on the join conditions, indexes on the tables, and, in the case of the cost-based optimization approach, statistics for the tables. 
     

  • What is difference between TRUNCATE & DELETE

    Answer posted by Scott on 2005-05-25 18:30:04: TRUNCATE is a DDL command and cannot be rolled back. All of the memory space is released back to the server. DELETE is a DML command and can be rolled back.  Both commands accomplish identical tasks (removing all data from a table), but TRUNCATE is much faster.

    Star Read Best Answer

    Editorial / Best Answer

    Answered by: Prangya Sahu

    • Nov 21st, 2005


    1>TRUNCATE is a DDL command whereas DELETE is a DML command.

    2>TRUNCATE is much faster than DELETE.

    Reason:When you type DELETE.all the data get copied into the Rollback Tablespace first.then delete operation get performed.Thatswhy when you type ROLLBACK after deleting a table ,you can get back the data(The system get it for you from the Rollback Tablespace).All this process take time.But when you type TRUNCATE,it removes data directly without copying it into the Rollback Tablespace.Thatswhy TRUNCATE is faster.Once you Truncate you cann't get back the data.

    3>You cann't rollback in TRUNCATE but in DELETE you can rollback.TRUNCATE removes the record permanently.

    4>In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like DELETE .Trigger get fired.

    5>You cann't use conditions(WHERE clause) in TRUNCATE.But in DELETE you can write conditions using WHERE clause.

    Shahida Sultana

    • Mar 6th, 2014

    TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesnt use as much undo space as a DELETE.

    saravanan

    • Sep 18th, 2012

    Delete & truncate command will delete entries from a table.. where as we can delete a single entry using delete but incase of truncate it wont be possible..

    using truncate will delete the log files,buffer storage in a table permanently but incase of delete it wont