Professional Documents
Culture Documents
A.) select count (*) from table will give the number of rows in
The table including null values.
2. Re: what is the different between unique+not null & primary key, Answer
A)In a relation, we can create only one primary key where as we can create
multiple unique+not null constrains.
Primary key uses clustered index where are unique +Not null uses non
clustered index
Answer
Join index will not affected until we change the column name
or data type of the column which we have used in join condition.
Constraints
1.are used to limit the type of data that can go into a table.
2.it can be specified when a table is created or after the table is
created.
3.Direct validation like the column should not contain null
values then you can choose Constraints.
4.Constraints will check for exiting rows.
5.constraines provide stoned error message.
Answer:2 Direct validation like the column should not contain null
values then you can choose Constraints.
Answer
SELECT OWNER,OBJECT_NAME,To_char(CREATED,'MON/DD/YYYY'),
to_char(CREATED,'HH:MM PM') from ALL_OBJECTS WHERE
OBJECT_TYPE ='TABLE' AND OBJECT_NAME ='EMP_TEST';
Answer
It is a composite datatype used in PLSQL programming.
You can not use Commit Inside Trigger. It will not get complied.
commit,rollback and savepoint cannot be used in a trigger
directly, but it can be called in a stored procedure
present in the trigger. however it is usually avoided as it
might have sideeffects in transactions.
example :
SELECT EMPNAME,SALARY
FROM
(SELECT EMPNAME,
SALARY,
RANK() OVER(ORDER BY SALARY) SAL_RANK
FROM EMP)
WHERE SAL_RANK < = 10
Answer
functions:
1.The parameters are input values and output values
2.The functions will return a value
3.The functions will be called with in sql
Procedures:
1.The parameters are input values and output values
2.The procedures will not return any value
3.The procedures will not be called with in sql
SQL> desc a;
Name Null? Type
------------------------------- -------- ----
A VARCHAR2(2)
B NUMBER(3)
A B
-- ---------
N 500
N 800
N 600
W 899
W 458
W 900
6 rows selected.
SQL> desc b;
Name Null? Type
------------------------------- -------- ----
A VARCHAR2(2)
B NUMBER(3)
no rows selected
2 rows created.
O
SQL> select * from b;
A B
-- ---------
N 800
W 900
update Sales_summary
set Sales=(select max(Sales)from Sales_data where
Region=®ion) where Region=®ion;
A:
Answer
when we fire any DML operation a memory is alocated. this
memory area is called context area or cursor. data is retieved and stored
in this area
Answer
Answer :2
IN: Inner query executes first and drives the outer query.
Consider table tab1 has 1000 rows and table tab2 has 1000
rows.
overhead.
Thumb rule:
1) If the majority of the filtering are in the sub query
then use IN.
1) If the majority of the filtering are in the outer query
then use EXISTS.
Answer
suppose you have two databases: db1 and db2
you have to select one of them
as
sql>use db1;
then use
sql>select * from tab;
it will show you the listing required.!
Answer :2
Answer
Let Table name : Employee
Let the columns: Employee_name, Salary
20. How would you go about increasing the buffer cache hit
ratio?
1. You have just had to restore from backup and do not have
any control files. How would you go about bringing up this
database?
5. Where would you look for errors from the database engine?
Answer
21)What are the new features in Oracle 10g. Compared to Oracle 9i?
Answer
Answer
creating a copy of the disk at some separate place and keep
on updating corresponding to the original disk is called
disk mirroring or disk shadowing.
Answer
equi join ,
non-equi join,
self join,
outer join,
cross join.
Cross Join: When join condition is missing then all rows from one table
gets joined with all rows from other table..
Join Conditions
---------------
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.
Cartesian Product
-----------------
If two tables in a join query have no join condition,
Oracle returns their Cartesian product. Oracle combines
each row of one table with each row of the other. A
Cartesian product always generates many rows and is rarely
useful. For example, the Cartesian product of two tables,
each with 100 rows, has 10,000 rows. Always include a join
condition unless you specifically need a Cartesian product.
If a query joins three or more tables and you do not
specify a join condition for a specific pair, the optimizer
may choose a join order that avoids producing an
intermediate Cartesian product.
Outer Join
----------
Self Join
---------
Answer
primary key is a key which always accept unique value.
secondary key is a key which when you are making primary key
for more than one column as primary key for retrieving of
reords.
eg.
create table tnam
(ano number,
bno number,
bname char(12),
primary key(ano,bno))
Answer
Answer
you can use 3 different collections for it...
declare
type name_typ is table of emp.empname%type;
type id_typ is table of emp.empid%type;
type sal_typ is table of emp.sal%type;
name_tab name_typ;
id_tab id_typ;
sal_tab sal_typ;
begin
name_tab := name_typ('ramit','rohan');
id_tab := id_typ(10,20);
sal_tab := sal_typ(21000,22000);
for all i in name_tab.first .. name_tab.last
Answer
In Layman tounge -
---------------
Whenever any named block in PL/SQL is created using CREATE
OR REPLACE clause, and as we compile it will get stored in
database, henceforth other code snippets can call/use this
block which ulimately resides in database after creation
i.e. "stored in database". And thus will move along
database if ever we move the database.
In oracle way -
---------------
Answer
Answer
Answer
You can use Select..ConnectBY.. PRIOR clause in Oracle to
generate the data in tree structure. Google for the apt
syntax and usage.
Answer
Answer
in char it allocates the memory space as static where as in
varchar2 it allocates the memory space as dynamic
OR
Answer
31. When the mutating error will comes? and how it will be
resolved?
EX.:-
create or replace trigger xyz
after
update
on abc
for each row
referencing :OLD as OLD :NEW as NEW
begin
select max(salary) from abc;
update abc
set location_id=:NEW.location_id
where dept_id=105;
end;
------------------------------------------------------------
In the above example you are updating same table which is
under transaction so mutation problem occur here.
Solution on this is
SQL> BEGIN
2 UPDATE employee
3 SET salary = salary *2
4 WHERE id = '01';
5
6 IF not SQL%ISOPEN THEN
7 DBMS_OUTPUT.PUT_LINE('closed');
8 END IF;
9 END;
10 /
closed
Ex:
Create table emp
(eno number,
ename varchar(5),
dob date,
sal number,
dno number,
Primary Key(eno, ename) -- Composite Index
);
if value format same like this then you can use substr
function also for it like this:-
ORACLE_HOME
ORACLE_SID
PATH
$sqlplus
$scott/tiger
36. Hello All, Could any well write a query for the following
scenario?
Account(table name)
No Name Amount
1 ABCD 2000.00
2 DEFG -2000.00
3 GHIJ 3000.50
4 JKLM 4000.00
5 MNOP 6000.00
38. how to delete duplicate rows from a specified table(only single table)
how do you know which join is need to be used?
41. With out using count() function. How to the find total
number of rows in a table?
Here rownum is a keyword which can gives unique number for individual rows
42. Please let me know if UNION ALL and Natural Join does the
same operation and are same?
no,union all and natural join is not same. for example tave
two tame emp and dept
emp table
dept table
deptid deptno
1 10
2 20
if i join this two tables
(empid = deptid)
Example:
select a.emp_id, b.dept_id from
emp a, dept b
where a.dept_id=b.dept_id
and a.sal < 3000
union all
select a.emp_id, b.dept_id from
emp a, dept b
where a.dept_id=b.dept_id
and a.sal > 6000
end PK_TEST;
But, following code will not work as p1( v1 IN varchar) and
p1(v3 IN varchar) has the same type of arguments.
--NOT WORK
create or replace package PK_TEST AS
end PK_TEST;
begin
dbms_output.put_line(' The input data for v1 is: '||v1);
end;
begin
dbms_output.put_line(' The input data for v2 is: '||v2);
end;
end;
/
begin
test.P3('Testing Procedure P3');
end;
question simply ask for the total of both the columns and
their difference, all in one 'select' statement.
48. I have doubt that any one tell ref cursor comes in sql
pl/sql? pls clarify?
UPDATE T
SET A = B, ENVDOR_NUMBERB = A
UPDATE T
SET A = B,B=A;
update T
set A:=A+B,
B:=A-B,
A:=A-B;
out put:3
53. I have one Excel file with 1,50,000 Records. Now I need to
load that whole file into Oracle Database with same columns
in Excel sheet .
I need PLSQL Procedure or used by SQL PLUS
3.If you are using SQL Developer one option is there for
importing data from excel/CSV or any other files.
first u need to create table which contains all columns in
excel. then right click on that table it will give option
for import excel data to the table
54. What is a REF CURSOR? Compare strong and week ref cursor types.
For the weak ref cursor the structure does not need to be
known at compile time.
56. How One can easily select all even, odd, or Nth rows from a
table using SQL queries?
57. what are the differences among these table level lock
modes - IN SHARE MODE, IN SHARE UPDATE MODE, IN EXCLUSIVE
MODE ?
in share mode :
this mode is for read only on entire table.
we can not make changes to table.
any user can have a lock in share mode at same time.
in exclusive mode :
this acquires lock on entire table.
another user can not have any lock on that table.
59. how to create user in sql and how to set password for that?
using semaphore
61. what is the difference between the query and corelated query?
A Query is evaluated once for each and every row from the
parent statement is called correlated Query.
like
select * from emp outer where sal= ( select avg(sal) from
emp e where dept.e=dept.outer) --> corelated query
When 1st main query is executed then the result of the main
query is used in teh where clause of sub query then this
type of sub query is called as co-related sub query.
Oracle RAC allows multiple computers to run the Oracle RDBMS software
simultaneously while accessing a single database, thus providing a
clustered database.
The first node created in the Cluster is the Master Node and
all other nodes in the Cluster nbehaves like Slaves.
Note: Use ASM (logical location for physical disk groups) for
the best performance).
Create ASM instance for each node
Stored procedure will return the values based on the OUT parameters
stored procedure can not return a value using the return statement.
though a stored procedure can contain a return
statement but should not return a value.simply "return".
in a manner,stored procedure can return values to the
calling block through the OUT,INOUT parameter modes.
1 name1 3000
1 name2 2000
1.select email_id,user_id,substr(email_id,instr
(email_id,'@'),length(email_id)) from mail_id;
email_id user_id
joy@yahoo.com joySmith
waine@gmail.com WaineR
@gmail.com tr222
@yahoo.com huip
------- DATA-----------------
Un-Used Blocks
Now let us delete the data and see the pointer of HWM
DATA
------- Empty Blocks Un-Used Blocks
Full Table
Scan
As you seen above by deleting the data , HWM does
not move. The main disadvantage of this is that oracle
always read the blocks up to high water mark in case of
full table scan . You may have ever notice that doing a
count(*) on empty table , takes time to show you 0 rows.
The reason for delay is setting of HWM at higher position.
73. I want to know the difference between A Record Type and a Table?
75. Write one update command to update seqno field of a table on the basis
of row number?
You can update the seqno which is having the rownum=1 only.
for eg:
If you have a table dept in scott user, you can try the
following command:-
update dept
set deptno=90
where rownum=1;
the above will update the record of the table which having
the rownum=1. and if you want to update some other record
then you have to make query to make the required record as
the first record of the table.
<http://www.sqlteam.com/article/find-nth-maximum-value-in-
sql-server>
2) How this query works?
<http://www.dbapool.com/forumthread/topic_4361.html>
For explanation let a table emp with sal column like below
sal
1200
1300
1500
1200
1250
1700
1250
2000
select max(sal) from emp where sal < (select max(sal) from emp
82. What is pragma exception and how, when, where us Rank Answer Posted By?
Example
declare
salary number;
FOUND_NOTHING exception;
Pragma exception_init(FOUND_NOTHING ,100);
begin
select sal in to salaryfrom emp where ename ='ANURAG';
dbms_output.put_line(salary);
exception
WHEN FOUND_NOTHING THEN
dbms_output.put_line(SQLERRM);
end;
Q.select to_char(4.40453E+15) from dual;