You are on page 1of 8

ORACLE

What is difference between a PROCEDURE & FUNCTION ?


A function can be called from sql statements and queries while procedure can be called in a begin end block only. In case of function, only it takes IN parameters, IN case of procedure take IN,OUT,INOUT parameters.. In case of function,it must have return type. In case of procedure,it may or may not have return type. We can use DDL in Procedure using Execute Immediate statement while that is not possible in functions

Difference between implicit and explicit cursor's. ? rowid and rownum

No Need to declare implicit cursors, oracle creates, process and closes automatically. In explicit cursor it should be declared and closed by the user.

Every record in a database is uniquely identified by system generated value called Rowid. It Is a 18 character hexma decimal value. These Rowid's are physically existence. It is a pseduocolumn which generates the sequence of numeric values based on the position of the records in the output. These ROWNUM'S logically generated.

Advantage and disadvantage of Cursor?

Cursors are used for storing, managing and retrieving data. Each time we fetch a row from the cursor, it result a network round trip, where as a normal select statement query make only one round trip.

How we can create a table in PL/SQL block. insert records into it???
l_stmt VARCHAR2(200); BEGIN l_stmt := 'create table '|| p_table_name || ' as (select * from emp )'; execute IMMEDIATE l_stmt; END;

Name the tables where characteristics of Package, procedure and functions are stored ?
User_objects, User_Source and User_error.

How to debug the procedure ?


put a dbms output_putline statement which will display that your procedure is executing successfully up to which stage.

What is pl/sql? what are the advantages of pl/sql?


In SQL we can manipulate the data, we can't process data through Sql command for doing that we need a programming language such as PL/SQL ,its an extension of SQL used to manipulate as well as process the data. There are 14 types of DML TRIGGER But we can fire only 12 types of triggers, because remaining 2 types of triggers fire on View. 1. Before insert on ROW LEVEL TRIGGER 2. 1. AFTER insert on ROW LEVEL TRIGGER 3. Before insert on STATEMENT LEVEL TRIGGER 4. After insert on STATEMENT LEVEL TRIGGER 5. Before update on ROW LEVEL TRIGGER 6. After update on ROW LEVEL TRIGGER 7. Before update on STATEMENT LEVEL TRIGGER. 8. After update on STATEMENT LEVEL TRIGGER. 9. Before Delete on STATEMENT LEVEL TRIGGER. 10 After Delete on STATEMENT LEVEL TRIGGER. 11. Before Delete on ROW LEVEL TRIGGER. 12 After Delete on ROW LEVEL TRIGGER

Can Commit,Rollback ,Savepoint be used in Database Triggers?If yes than HOW? If no Why?With Reasons
No, Once trigger execution is complete then only a transaction can be said as complete and then only commit should take place. Otherwise deadlock situation occur as a result we will get a error in the transaction.

Explain how procedures and functions are called in a PL/SQL block ?


Function can be called from SQL query + explicitly as well e.g 1)select empno,salary,fn_comm(salary)from employee; 2)commision=fn_comm(salary); Procedure can be called from begin-end clause. e.g. Begin ( proc_comm(salary); ) end

What will happen after commit statement ?


After commit statement, all changed data will be saved in permenent database. After commit all the locks on the database tables are leased.

How to disable multiple triggers of a table at at a time?


ALTER TABLE<TABLE NAME> DISABLE ALL TRIGGER

In pl/sql functions what is use of out parameter even though we have return statement.

With out parameters you can get the more than one out values in the calling program. It is recommended not to use out parameters in functions. If you need more than one out values then use procedures instead of functions.

How to avoid using cursors? What to use instead of cursor and in what cases to do so?
loop dbms_output.put_line(emprec.empno); end loop; no exit statement needed implicit open,fetch,close occurs

When the number of rows returned by query is small (around 100) then explicit cursor can be avoided for emprec in (select * from emp)

How we can create a table through procedure ?


create procedure p1 is begin EXECUTE IMMEDIATE 'CREATE TABLE temp AS SELECT * FROM emp ' ; END; /

? ROWTYPE and TYPE RECORD ?

% ROWTYPE is to be used whenever query returns a entire row of a table or view. TYPE rec RECORD is to be used whenever query returns columns of different table or views and variables. E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp ename %type ); e_rec emp% ROWTYPE cursor c1 is select empno,deptno from emp; e_rec c1 %ROWTYPE.

Difference %TYPE and %ROWTYPE ?


%ROWTYPE allows us to assign a variable with an entire table row. The %TYPE assign a variable with a single column type.

In a Distributed Database System Can we execute two queries simultaneously ? Justify ?


As Distributed database system based on 2 phase commit,one query is independent of 2 nd query so of course we can run.

? UNIQUE and PRIMARY KEY constraints?

A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.

Difference Between oracle 9i and 10G


1) 2) 3) 4) 5) faster data movement with expdp and impdp Dbms_scheduler package replaces dbms_job for scheduling Ability to rename tablespaces Passwords for db links are encrypted ASM Automated storing manager

3rd Highest salary from emp table ?

SELECT DISTINCT (a.sal) FROM EMP A WHERE 3 = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B WHERE a.sal<=b.sal);

Oracle Installed version information ?


select banner from v$version;

Any three PL/SQL Exceptions? PL/SQL Cursor Exceptions?


Cursor_Already_Open, Invalid_Cursor

Too_many_rows, No_Data_Found, Value_Error, Zero_Error, Others

What is Raise_application_error ?

The RAISE_APPLICATION_ERROR is a procedure defined by Oracle that allows the developer to raise an exception and associate an error number and message with the procedure other than just Oracle errors. EXCEPTION when NO_DATA_FOUND then RAISE_APPLICATION_ERROR(-20201,'manager is not a valid employee');

Escape special characters when building SQL queries?


SELECT name FROM emp WHERE id LIKE '%\_%' ESCAPE '

Generate primary key values for a table?


UPDATE cmg SET seqno = ROWNUM; CREATE SEQUENCE cmg_seq_name START WITH 1 INCREMENT BY 1; UPDATE cmg SET seqno = cmg_seq_name.NEXTVAL;

Retrieve 12th row from a table?


SELECT * FROM ( SELECT ENAME,ROWNUM RN FROM EMP WHERE ROWNUM < 13 ) WHERE RN = 12;

Retrieve Rows from 90 to 100

SELECT * FROM (SELECT ENAME,ROWNUM RN FROM EMP WHERE ROWNUM < 101) WHERE RN between 91 and 100; SELECT * FROM tableX WHERE rowid in (SELECT rowid FROM tableX WHERE rownum <= 7 MINUS SELECT rowid FROM tableX WHERE rownum < 5);

select TOP 9 rows from a table?


SELECT * FROM (SELECT * FROM cmg ORDER BY cust_id DESC) WHERE ROWNUM < 10;

CASE statements in SQL.

SELECT ename, CASE WHEN sal>1000 THEN 'Over paid' ELSE 'Under paid' END FROM emp;

Drop a column from a table?


ALTER TABLE cmg DROP COLUMN cust_id;

Add a column in a table?


alter cmg t1 add ( customer varchar2(16) );

Change Oracle password?


1) Alter user custom identified by ranjeet; 2) password; 3) password migr;

? Indexing ? ? Query ?

Indexing is a technique for determining how quickly specific data can be found.

Query is the commands used to communicate with data base. The query language can be classified into data

definition language and data manipulation language.

? Correlated subquery ?
Query that is executed for every row of the parent is correlated subquery. And it is used to bring back a set of rows to be used by the parent query. Nt:- Columns from the subquery cannot be referenced anywhere else in the parent query

? Trigger?

It is an PL/SQL block that can be created to automatically execute for insert, update, and delete statements against a table.

? Stored-procedures? Advantages ?.
It is a set of SQL Statements that perform a user defined operation and returns the result to the client. It reduce network traffic

? Normalization ?

It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs) and primary key to achieve the properties Minimizing redundancy Minimizing insertion, deletion and update anomalies.

? Exceptions handled in PL/SQL? Some Internal exceptions ?

If any Error occurs, than exception handler allows to continue further execution, if no critical issue that can terminate the process. Enables in the declarations area of subprogram specifications. There is an exception named OTHERS that catch all other exceptions which is not defined internally/user defined

Disable all users whose names starts with OPS$ ?


INSERT INTO SYSTEM.PRODUCT_USER_PROFILE VALUES ('SQL*Plus', 'OPS$%', 'CONNECT', NULL, NULL, 'DISABLED', NULL, NULL);

Copy data from one database to another in SQL*Plus?


COPY FROM SCOTT/TIGER@LOCAL_DB TO SCOTT/TIGER@REMOTE_DB

Check if somebody modified any code?


SELECT OBJECT_NAME, TO_CHAR(CREATED,'DD-Mon-RR HH24:MI') CREATE_TIME, TO_CHAR(LAST_DDL_TIME, 'DD-Mon-RR HH24:MI') MOD_TIME, STATUS USER_OBJECTS LAST_DDL_TIME > '&CHECK_FROM_DATE';

FROM WHERE

Search PL/SQL code for a string/ key value ?


SELECT FROM WHERE type, name, line user_source UPPER(text) LIKE '%&KEYWORD%';

Protect PL/SQL source code?


wrap iname=myscript.sql oname=xxxx.plb ORACLE_HOME/bin

Privileges granted on table by a user to others?


Insert, update, delete, select, references, index, execute, alter, all

System tables contain details on privileges granted and obtained?


USER_TAB_PRIVS_MADE USER_TAB_PRIVS_RECD

System table contains details on constraints on all the tables ?


USER_CONSTRAINTS

? TRUNCATE and DELETE ?

TRUNCATE is DDL command and DELETE is DML. DELETE can be rolled back. We can use WHERE in delete

Copy only Table structure.


In Where clause we have to write FALSE condition CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;

? DESC in SQL?

Describe schema and select rows from table in descending order. SELECT * FROM EMP ORDER BY ENAME DESC

? CASCADE CONSTRAINTS?
Is used with the DROP command, to drop a parent table even when a child table exists.

DBA
29. When a user process fails, what background process cleans up after it? PMON 31. How would you determine what sessions are connected and what resources they are waiting for? Use of V$SESSION and V$SESSION_WAIT 32. Describe what redo logs are. Redo logs are logical and physical structures that are designed to hold all the changes made to a database and are intended to aid in the recovery of a database. 33. How would you force a log switch? ALTER SYSTEM SWITCH LOGFILE; 37. Name a tablespace automatically created when you create a database. The SYSTEM tablespace. 38. When creating a user, what permissions must you grant to allow them to connect to the database? Grant the CONNECT to the user. 43. How would you determine who has added a row to a table? Turn on fine grain auditing for the table. 44. How can you rebuild an index? ALTER INDEX <index_name> REBUILD; 47. How can you gather statistics on a table? The ANALYZE command. 48. How can you enable a trace for a session? Use the DBMS_SESSION.SET_SQL_TRACE or Use ALTER SESSION SET SQL_TRACE = TRUE; 50. Name two files used for network connection to a database. TNSNAMES.ORA and SQLNET.ORA ============ DB_LINK====================== drop public database link GBMTOFINACLE; Database link dropped. create public database link GBMTOFINACLE connect to GBM identified by gbm using 'GBMMIG1'; ============ DB_LINK======================

You might also like