Friday, May 30, 2014

HOW CAN YOU FIND THE NAMES OF THE EMPLOYEES WHOSE SALARIES ARE SAME?

SQL> select e1.ename,e1.sal ,e2.ename,e2.sal from emp e1,emp e2 where e1.sal=e2.sal 
           and
           e1.empno!=e2.empno;

ENAME       SAL    ENAME       SAL
_______     ____    ________    _____
WARD       1250     MARTIN     1250
MARTIN    1250    WARD        1250
SCOTT      3000     FORD           3000
FORD        3000     SCOTT        3000

Tuesday, May 27, 2014

PRINTING Nth HIGHEST SALARY

SQL> select sal from emp e where 3=(select count(distinct sal) from emp where e.sal>=sal);

 SAL
----
1100



SQL> SELECT A.ENAME,A.SAL FROM (SELECT ENAME,SAL,DENSE_RANK() OVER (ORDER BY SAL)  RK FROM EMP)  A WHERE RK=2;

ENAME       SAL
---------- ----
JAMES       950

Friday, May 16, 2014

DID U KNOW THIS.................................WE CAN LOAD COMBINED PHYSICAL RECORDS...................

There may be chances that we get the data in which each row starts with a special character like '@','#','$' etc.Then we will have to use continueif to load the data from such kind of flat file into staging table.

There may be scenerios where we need to load two or three rows of the flat-file as a single row in the staging table then we will use Concatenate option to acheive that requirement.

USING CONTINUEIF:
load data
infile *
replace
continueif this (1)= '@'
into table vnk_emp
fields terminated by ','
optionally enclosed by '"'
trailing nullcols
(
c1,
c2,
c3,
c4 char terminated by whitespace
)
BEGINDATA
@1,2,
    3,4
@5,6,
    7,8

USING CONCATENATE:
load data
infile *
replace
concatenate 2
into table vnk_emp
fields terminated by ','
optionally enclosed by '"'
trailing nullcols
(
c1,
c2,
c3,
c4 
)
BEGINDATA
1,2,
3,4
5,6,
7,8

Staging table:
Create table vnk_emp(c1 number,
                                   c2 number,
                                   c3 number,
                                   c4 number
                                  )

Thursday, April 24, 2014

HA...... HA........... WE CAN CREATE A PROCEDURE FOR DISPLAYING OUTPUT.......................................EEEEEEEEEEEEEEEEEEEEE

SQL> CREATE OR REPLACE PROCEDURE DISPLAY(ARG VARCHAR2)
  2  AS
  3  BEGIN
  4  DBMS_OUTPUT.PUT_LINE(ARG);
  5  END;
  6  /

Procedure created.

SQL>
SQL> BEGIN
  2  DISPLAY('hai');
  3  END;
  4  /

PL/SQL procedure successfully completed.

SQL> SET SERVEROUTPUT ON
SQL> /
hai

PL/SQL procedure successfully completed.

SQL>
SQL> BEGIN
  2  DISPLAY('hai'||'HELLO');
  3  END;
  4  /
haiHELLO

PL/SQL procedure successfully completed.