Page 6 of 9 FirstFirst ... 45678 ... LastLast
Results 101 to 120 of 194

Thread: Geeks - Tip of the Day

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Oracle Built-In packages - I

    Dbms_Metadata.Get_Ddl
    It is used to retrieve complete database object definitions (metadata) from dictionary. By specifying the type of object, for example, tables, indexes, or procedures optional selection criteria, such as owner etc.

    Code:
     
    EX:- set heading off; 
         set pages 999; 
         set long 5000; 
         
         select dbms_metadata.get_ddl('table','emp','cmsjan') 
         from dual; 
     
         Here table is object type 
              emp is object name 
              cmsjan is schema name.
    To get whole schema table definitions

    Code:
     
        set heading off 
        Set pagesize 0 
        set long 90000 
        set feedback off 
        spool cmsjanschema.sql 
     
        select dbms_metadata.get_ddl('table',x.table_name) 
        from user_tables x; 
    
        spool off; 
        set feedback on; 
        set heading on;



  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Oracle Built-in Packages - II

    DBMS_UTILITY provides various utility procedures and functions.

    In this package Get_time function provides elapsed time in seconds interval. Finds out the current time in 100th's of a second.

    Code:
    Example
       DECLARE
       time_before BINARY_INTEGER;
       time_after  BINARY_INTEGER;
       
       BEGIN
       time_before := DBMS_UTILITY.GET_TIME;
       CMSRPT_MONTHWISETARGET_INS('200607','200708','Sugar Cane');     
       time_after := DBMS_UTILITY.GET_TIME;
       
       DBMS_OUTPUT.PUT_LINE (time_after - time_before);
       
       END;
    
    OUTPUT
    SQL> @krk;
    623
    
    i.e. it takes 6.23 seconds time to execute the procedure.



  3. #3
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Oracle Built-In Packages - III

    Generally we use v_$version to know oracle version number as follows

    Code:
     
    sql> select * 
       2 from sys.v_$version; 
    oracle9i enterprise edition release 9.2.0.6.0 - production 
    pl/sql release 9.2.0.6.0 - production 
    core 9.2.0.6.0 production 
    tns for 32-bit windows: version 9.2.0.6.0 - production 
    nlsrtl version 9.2.0.6.0 - production
    The pl/sql package dbms_db_version supplies several useful constants that you can use in your code to determine the currently running version of oracle. This package is introduced in oracle9i version release 2. This package contains no functions and procedures. It contains only a series of constants to determine running version.

    Code:
     
    sql> set serveroutput on; 
    sql> exec dbms_output.put_line (dbms_db_version.version); 
    9 
    Here 9 is oracle version number


    Last edited by krishnaindia2007; 06-27-2008 at 12:06 AM.

  4. #4
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Oracle Built-In Packages - IV

    Using DBMS_RANDOM package functions and procedures we can generate random numbers , strings and dates.

    The value function in dbms_random is used to generate random numbers. This function comes in two specifications

    1. DBMS_RANDOM.VALUE( )
    2. DBMS_RANDOM.VALUE( low IN NUMBER, high IN NUMBER)

    Value function without arguments generates a random number greater than or equal to 0 and less than 1, with 38 digits of precision.

    Code:
    Ex:- SQL> SELECT dbms_random.value() FROM dual;
     
              DBMS_RANDOM.VALUE()
              -------------------
                 .480358
    VALUE function with two arguments generates a number in between low values and high value. The high value is not included as a possible value.

    Code:
    Ex:- The following function generates a random number in between 0 and 99
    
         SQL> SELECT TRUNC(DBMS_RANDOM.VALUE(0, 100)) 
              FROM DUAL;
              
              TRUNC(DBMS_RANDOM.VALUE(0,100))
              -------------------------------
                   92



  5. #5
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Oracle Built-In Packages- V

    The string function in dbms_random package generates random text string.

    Syntax:- dbms_random.string(opt, len);

    Here len determines length of the string

    Opt Specifies What the returning string looks like. It can take any one of the following codes.
    'u' or 'U' - returning string in uppercase alpha characters
    'l' or 'L' - returning string in lowercase alpha characters
    'a' or 'A' - returning string in mixed case alpha characters
    'x' or 'X' - returning string in uppercase alpha-numeric characters
    'p' or 'P' - returning string in any printable characters.

    Code:
    Ex:- 
     SQL> SELECT dbms_random.string('u', 10) StringEx 
          FROM dual;
    
          StringEx
          --------------------
          YYHFTNZAUU
    We can also generate date random values using to_char function with Julian date format.For example, to generate random dates during the year 2007, first determine the date integer for January 1, 2007

    Code:
    SQL> SELECT TO_CHAR(TO_DATE('01/01/07','mm/dd/yy'),'J')
         FROM DUAL;
    
    TO_CHAR
    -------
    2454102
    Now we can use the above date integer 2454102 to generate random numbers using DBMS_RANDOM.VALUE with a low_value of 2452641 and a high_value of 2452641+364, and convert it to a date.

    Code:
    SQL> SELECT TO_DATE(TRUNC(DBMS_RANDOM.VALUE(2454102,2454102+364)),'J') 
      2  FROM DUAL;
    
    TO_DATE(T
    ---------
    20-JUL-07



  6. #6
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Julian Day

    A Julian day for a date is number of days since 01-JAN-4712 BC inclusive.

    Code:
    SQL> SELECT to_char(sysdate,'J') 
      2  FROM   dual;
    
    TO_CHAR
    -------
    2454646
    Oracle uses julian date internally for date arithmetic. For example, when adding a number to a date, Oracle first converts the date to a Julian day, then performs the addition,and then converts the resulting Julian day back into a date.

    Generally we use this julian date format to convert a number to words

    Code:
    SQL> SELECT to_char( to_date('4500','J'), 'JSP') 
      2  FROM   dual;
    
    TO_CHAR(TO_DATE('4500','J'
    --------------------------
    FOUR THOUSAND FIVE HUNDRED


    Last edited by krishnaindia2007; 06-27-2008 at 10:41 PM.

  7. #7
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    on delete cascade and cascade constraints
    on delete cascade :- when rows from parent table are deleted causing all rows in child tables with dependent foreign key values to also be deleted example
    Code:
     
    sql> create table test_one ( x number constraint test_one_pk primary key); 
    table created. 
    Sql> create table test_two (y number constraint test_one_fk references 
                                test_one(x) on delete cascade); 
    table created. 
    Sql> insert into test_one values(1); 
    1 row created. 
    Sql> insert into test_one values(2); 
    1 row created. 
    Sql> insert into test_one values(3); 
    1 row created. 
    Sql> insert into test_two values(1); 
    1 row created.
    Now delete a row from parent table. It will automatically delete dependent foriegn key value from child table.
    Code:
     
    sql> delete from test_one where x = 1; 
    1 row deleted. 
    Sql> select * from test_one; 
    x 
    --------- 
    2 
    3 
    sql> select * from test_two; 
    no rows selected
    Cascade Constraints:- when cascade constraints is specified , first it deletes all foreign keys that reference the table to be dropped, then drops the table.
    Code:
     
    sql> drop table test_one cascade constraints; 
    table dropped. 
    Sql> select constraint_name from user_constraints 
       2 where table_name = 'test_two'; 
    no rows selected


    Last edited by krishnaindia2007; 07-03-2008 at 02:09 AM.

  8. #8
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    How dates are stored internally?

    Each date value in oracle takes seven bytes of space.
    The first two bytes represent the century and year respectively.
    The 3rd and 4th bytes represent the month and the day of that month respectively.
    The last three bytes represent the hour, minute, and second.

    Date value do not have any format . When you query date value it will display the value in default date format that is specified by the initialization parameter NLS_DATE_FORMAT.

    To following statement will display your current session date settings
    Code:
    SQL> SELECT value 
         2   FROM   nls_session_parameters
         3   WHERE  parameter  = 'NLS_DATE_FORMAT';
    
    VALUE
    -------------------
    DD-MON-YY
    
    SQL> SELECT ename, hiredate 
      2  FROM   emp
      3  WHERE  ename = 'SMITH';
    
    ENAME      HIREDATE
    ---------- ---------
    SMITH      17-DEC-80  -- Output is in NLS_DATE_FORMAT
    SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YY';

    Session altered.

    Code:
    SQL>  SELECT ename, hiredate 
      2   FROM   emp
      3   WHERE  ename = 'SMITH';
    
    ENAME      HIREDATE
    ---------- --------
    SMITH      17/12/80


    Last edited by krishnaindia2007; 07-04-2008 at 01:45 AM.

  9. #9
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    How to prevent oracle from using an index?

    We can do it in four different ways.
    1. adding an expression to index
    Code:
     
     sql> select x 
        2 from test_data 
        3 where x+0 = 256;
    2. using function on indexed column

    Code:
     
    sql> select x 
       2 from test_data 
       3 where to_number(x) = 250;
    3. specifying no_index hint
    Code:
     
    sql> select /*+ no_index(test_data) */ x 
       2 from test_data 
       3 where to_number(x) = 250;
    4. specifying the full hint
    Code:
     
     sql> select /*+ full(test_data) */ x 
        2 from test_data 
        3 where to_number(x) = 250;


    Last edited by krishnaindia2007; 07-04-2008 at 10:13 PM.

  10. #10
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    DDL Statements – Auto Commit

    Auto commit or implicit commit will takes place before and after every DDL statement. DDL will always commit, even if it is unsuccessful (Run time errors). But it will not commit a transaction in case of syntax errors or semantic errors..

    Example
    Code:
    SQL> CREATE TABLE TEST_DATA (X NUMBER);
    Table created.
    
    SQL> INSERT INTO TEST_DATA VALUES(1);
    1 row created.
    
    SQL> INSERT INTO TEST_DATA VALUES(2);
    1 row created.
    
    
    SQL> CREATE TABLE TEST_NEW (XX NUMBEER);
    CREATE TABLE TEST_NEW (XX NUMBEER)
                              *
    ERROR at line 1:
    ORA-00902: invalid datatype
    -- It is runtime  error. Auto commit will takes place.
    
    SQL> ROLLBACK;
    Rollback complete.
    
    SQL> SELECT * FROM TEST_DATA;
    
            X
    ---------
            1
            2
    Example for syntax error

    Code:
    SQL> TRUNCATE TABLE TEST_DATA;
    Table truncated.
    
    SQL> INSERT INTO TEST_DATA VALUES(1);
    1 row created.
    SQL> INSERT INTO TEST_DATA VALUES(2);
    1 row created.
    
    SQL> CREATE TABLETEST_NEW (XX NUMBER);
    CREATE TABLETEST_NEW (XX NUMBER)
           *
    ERROR at line 1:
    ORA-00901: invalid CREATE command
    
    -- It is syntax error. It will not commit transaction.
    SQL> ROLLBACK;
    Rollback complete.
    
    SQL> SELECT * FROM TEST_DATA;
    no rows selected



  11. #11
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Composite Index - When It Will Be Used?

    An index that is created on multiple columns of a table is called composite index.

    If you create a composite index on three columns for example a,b,c of a table

    composite index will be used for abc, ab, a combination of columns in where clause .

    Composite index will not be used for bc,b and c combinations of columns in where clause.

    Here is the example
    Code:
     
    sql> create table test_data ( a number, b number, c number); 
    table created. 
    --- to insert 500 records 
    sql> declare 
    2 i number; 
    3 begin 
    4 for i in 1..500 
    5 loop 
    6 insert into test_data values(i,i,i); 
    7 end loop; 
    8 commit; 
    9 end; 
    10 / 
    pl/sql procedure successfully completed. 
    Sql> create index test_data_idx on test_data(a,b,c); 
    index created.
    Ex1:- ab combination will use index
    Code:
     
    sql> set autotrace on explain; 
    sql> select * from test_data 
    2 where a = 100 
    3 and b = 100; 
    execution plan 
    ---------------------------------------------------------- 
    0 select statement optimizer=choose 
    1 0 index (range scan) of 'test_data_idx' (non-unique)
    Ex2:- bc combination in where clause will not use index
    Code:
     
    sql> select * from test_data 
    2 where b = 100 
    3 and c = 100; 
    execution plan 
    ---------------------------------------------------------- 
    0 select statement optimizer=choose 
    1 0 table access (full) of 'test_data'


    Last edited by krishnaindia2007; 07-07-2008 at 10:35 PM.

  12. #12
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    What is a datablock?

    ORACLE database’s data is stored in data blocks.
    One data block corresponds to a specific number of bytes of physical database space on disk.
    A data block size is specified for each ORACLE database when the database is created.
    The standard block size is specified by the initialization parameter DB_BLOCK_SIZE and is specified in INIT.ORA file .
    ORACLE database’s data block can be of size 2K, 4K, 8k, 16K or 32K.
    The default block size for oracle 10g is 8K.
    A small block size is useful if you’re working with small rows and you’re doing a lot of index lookups.
    Larger block sizes are useful in report applications when you’re doing large table scans.


  13. #13
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    A privilege is the right to execute a particular type of SQL statement or to access a database object owned by another user.

    Oracle privileges are of two types

    1. System privileges :- Enable user to perform particular task in the database

    2.Object privileges:- Enable user to access or manipulate particular object in the database

    Use grant command to add a privilege to user and revoke command to delete a privilege from user.

    There are no cascading effects when a system privilege is revoked. But revoking object privilege has cascading effect.

    i.e. If user X grant a system privilege with admin option to user y
    User y grant a system privilege to user z.
    User x revoke the system privilege from user y
    still user z has the privilege that user y granted him

    Where as in case of object privileges
    If x user revoke the privilege from user y then the user z also losses the privilges granted by y.


  14. #14
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    You can’t grant object privileges on some schema objects, such as clusters, indexes, triggers, and database links. You control the use of these types of objects with a system privilege instead.


  15. #15
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    UNLIMITED TABLESPACE cannot be granted to a role.


  16. #16
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    There is no CREATE INDEX privilege. CREATE TABLE includes the CREATE INDEX and the ANALYZE commands


  17. #17
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    A control file records the physical structure of the database.
    It contains
    Name and location of datafiles and redo log files
    Data base name
    Time stamp of database creation.

    Use the following query to find the size of control file
    select sum(record_size) from v$controlfile_record_section


  18. #18
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    Query to find locked objects

    select oracle_username, os_user_name,locked_mode,object_name,object_type
    from v$locked_object a, dba_objects b
    where a.object_id=b.object_id


  19. #19
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    To Disable Archive Log Mode

    1. Shut Down the database

    2. Comment Archive log destinations in parameter file
    # LOG_ARCHIVE_DEST_1=”location=/u02/ica/arc1”
    # LOG_ARCHIVE_DEST_2=”location=/u02/ica/arc2”

    3. Startup Mount

    4. ALTER DATABASE NOARCHIVELOG;

    5. Shutdown the database and take full offline backup.


  20. #20
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Geeks - Tip of the Day

    How to export data based on a query?

    EXP file=f1.dmp log=f1.log tables=y query=\"WHERE DEPTNO=10\"


Page 6 of 9 FirstFirst ... 45678 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact