Oracle Sample - Practice Queries
Oracle Sample - Practice Queries
3. A. delete from emp where rowid not in(select max(rowid) from emp group by
ename)
B. delete from emp e where rowid not in(select max(rowid) from emp where e.ename
= ename)
-------------------------------------
8) how you will get check error code and message in pl/sql block
a) sqlcode,sqlerrm
b) errcode,errm
* sqlcode & sqlerrm
a b
1 z
1 x
2 z
2 x
3 z
4 x
a) 2 b) 4 c) 3
* 4
11) which trigger will get fire first before insert , before insert for each row.
* statement level first
* row level statement
20) when rows are found what the cursor will do.
* it will work
a) 2-1-2-7
b) 2-1-2-1
c) 1-2-1-2
* 2-1-2-7
28) @ is used to
a) execute b) db-link
* both
34) display_item(:block.item)
* change the visual attribute.
a) name_in(:block.itemname)
b) copy('block.itemname',var)
c) copy(var,'block.itemname')
*copy(var,'block.itemname')
45) in a function declartion returns number and in defintion if you return boolean
* it will show error
47) create trigger trigger_name before insert on emp for each row
where empno=10
begin
end;
a) will it ececute
------------------------------------
1. How will u check the sysdate against one date field in the table.
(ie u can use the CHECK CONSTRAINT when u create table.)
But SYSDATE is not used for CHECK CONSTRAINT.
So we have to create a database trigger for checkig the values agaionst SYSDATE.
2. How will u select all the employee information those who are working in the
department in which the employee "XXXXX" is working.
---------------------------------------
9. Oracle 8 features.
Objects
Nested tables.
Partitions.
Varray.
New Dtatypes like blob,clob,bfile.
11. When u are moving the application from forms30 to froms4.5 , the database
performance will be getting reduced. How this can be eliminated when you are
moving the application from forms30 to froms4.5
1.Mid row
****************
SELECT * FROM EMP WHERE ROWNUM <
(SELECT DECODE(MOD(MAX(ROWNUM),2),0,MAX(ROWNUM)/2+2,
,1,MAX(ROWNUM)/2+1) FROM EMP)
MINUS
(SELECT * FROM EMP WHERE ROWNUM <
(SELECT MAX(ROWNUM)/2 FROM EMP))
3. No to Word
**************
select to_char(to_date('&n','j'),'jsp') from dual
5. Alternate Rows
*****************
select * from emp where rowid in (select decode(mod(rownum,2),1,rowid) from
emp)
6. Nth Max
**********
select sal from emp x
where &n= (select count(distinct(sal)) from emp where x.sal <= emp.sal)
7. 3rd Max
**********
select sal from emp
where sal >= (select max(sal) from emp where sal < (select max(sal) from emp))
8.Cumulative addition
**********************
DECLARE
D1 DATE;
TSAL NUMBER(8,2);
BEGIN
D1 := '&DATE';
SELECT SUM(SAL) INTO TSAL FROM A WHERE HIREDATE >=
TRUNC(to_date(TO_CHAR(ADD_MONTHS(d1,-2),'DD-MON-YY')),'MM') AND HIREDATE <= D1 ;
DBMS_OUTPUT.PUT_LINE(TSAL);
END;
(OR)
DECLARE
d1 date;
tsal number(5,2);
BEGIN
D1 := '&DATE';
SELECT SUM(amt) INTO TSAL FROM damt WHERE dt >=
TRUNC(to_date(TO_CHAR(ADD_MONTHS(d1,-2),'DD-MON-YY')),'MM') AND dt <= D1;
DBMS_OUTPUT.PUT_LINE(TSAL);
END;
/
(or)
declare
dt1 date;
tamt number(5,2);
begin
dt1 := '&date';
SELECT SUM(AMT) into tamt FROM DAMT
WHERE
round((months_between(to_date('&dt1','dd-mon-yy'),to_date(dt,'dd-mon-yy'))))
between 0 and 2
and dt <= dt1;
dbms_output.put_line(tamt);
end;
/
(or)
select decode(deptno,10,loc,
dname) from dept
9) Cumulative sal
*****************
select a.sal,sum(b.sal) from emp a,emp b
where b.rowid <= a.rowid group by a.rowid, a.sal
10) Index
************
create or replace PROCEDURE create_index
(index_in IN VARCHAR2,
tab_in IN VARCHAR2, col_in IN VARCHAR2)
IS
cur INTEGER := DBMS_SQL.OPEN_CURSOR;
DDL_statement VARCHAR2(200)
:= 'CREATE INDEX ' || index_in ||
' ON ' || tab_in ||
' ( ' || col_in || ')';
BEGIN
PLV.assert (INSTR (col_in, ':') = 0, 'No bind variables');
DBMS_SQL.PARSE
(cur, DDL_statement, DBMS_SQL.V7);
END;
/
12)Triangle
***********
select rpad(lpad(lpad('*',2*rownum,' *'),(20-2*rownum)/2+2*rownum,' '),20,' ')
from tab where rownum <= 10
/