Thursday, 7 June 2012

RESPONSIBILITIES AND USER


Every module having one application and    one/more responsibilities.
 

 An application is a collection of forms ,reports&pl/sql subprograms whic are related to specific bussiness functionality.



Responsibility: It is a role authorized to access specific Forms and Programs of a
particular Module. A responsibility is a collection of Menus, Request Groups and Data
Groups. Menus and Data Groups are mandatory to a responsibility.


Menu:  A menu is a collection of Sub‐Menus and Functions.


Request Group (RG): It is a collection of concurrent Programs. It is used to request
programs from the responsibility.

Data Group (DG): It is a collection of Modules used to integrate one or more
Modules for cross application transfer of data, cross application reporting and cross
application reference. If we want to get data from other Modules we need to define those
modules in the Data Group



we have mainly two types of dattagroups 
  1. standard datagroup
  2. standard MRC
we can create new or can use existing data groups.


TABLES:
  1. user table : fnd_user
Responsibility tables
  1. fnd_responsibility_b
  2. fnd_responsibility_TL
_tl tables hav a special columns called langunage it supports multiple langunages.


Request group tables 
  1. fnd_request_groups
  2. fnd_request_groups_units.
menu tables 
  1. fnd_menus
  2. fnd_menu_types
  3. fnd_menu_entries.
function tables are 

  1. fnd_form_functions


concurrent program tables
  1. fnd_concurrent_programs_b
  2. fnd_concurrent_programs_tl
concurrent resuest tables 

  1. fnd_concurrent_request_b
  2. fnd_concurrent_request_tl.



Wednesday, 6 June 2012

REPORTS



Report Builder Components
Report Builder Components are

1. Data Model
2. Layout Model
3. Object Navigator
4. Report Triggers
5. Parameter Form
6. Program Units
7. Attached Libraries

Data Model
The Report Editor's Data Model view enables you to define and modify the data model objects for a report.

Data Model Comprises tool Palette which Comes with several Options They are:





1. Select
2. Magnify
3. SQL Query
4. Ref Cursor Query
5. Express Query
6. Summary Column
7. Formula Column
8. Placeholder Column
9. Cross Product
10. Data Link





The tool palette is a set of tools you can use to create and manipulate objects. Click a tool to activate it for a single operation, or double-click a tool to "lock" it for multiple operations. The tools in the tool palette vary depending on the Report Editor view.

Select
The Selector toolbar provides tools to help you select or arrange dimension values that meet your criteria. The Selector toolbar is displayed at the top of the Selector dialog box.

Magnify
To magnify a hard-to-see portion of your report or reduce the image to get a sense of your report's overall layout.

SQL Query
The SQL Query Statement property is a SQL SELECT statement that retrieves data from the database for your report. Enter a valid SELECT statement not to exceed 64K. The upper limit may vary between operating systems All features of the SELECT statement are supported, except the INTO and FOR UPDATE clauses.

In building your SELECT statement, you can do the following:

1. Use the Tables and Columns dialog box
2. Insert comments
3. Insert bind and lexical references
4. Review SQL errors

Required/Optional : Required

Ref Cursor Query
A ref cursor query uses PL/SQL to fetch data. Each ref cursor query is associated with a PL/SQL function that returns a strongly typed ref cursor. The function must ensure that the ref cursor is opened and associated with a SELECT statement that has a SELECT list that matches the type of the ref cursor.

You base a query on a ref cursor when you want to:

1. more easily administer SQL
2. avoid the use of lexical parameters in your reports
3. share data sources with other applications, such as Form Builder
4. encapsulate logic within a subprogram

Express Query
--------

Summary Column
A summary column performs a computation on another column's data.
Using the Report Wizard or Data Wizard, you can create the following summaries:
sum, average, count, minimum, maximum, % total.

You can also create a summary column manually in the Data Model view, and use the Property Palette to create the following additional summaries: first, last, standard deviation, variance.

Formula Column
A formula column performs a user-defined computation on another column(s) data, including placeholder columns.

Placeholder Column
A placeholder is a column for which you set the data type and value in PL/SQL that you define.

You can set the value of a placeholder column in the following places:
1. The Before Report Trigger, if the placeholder is a report-level column
2. A report-level formula column, if the placeholder is a report-level column
3. A formula in the placeholder's group or a group below it

Cross Product
The Cross Product Group property is the group that contains the source groups of the Horizontal and Vertical Repeating Frames. The cross product group correlates values between one or more groups to produce the data in the matrix.

Values Enter a valid cross product group name.
Applies to matrices
Required/Optional required
Default blank

Data Link
Data links relate the results of multiple queries. A data link (or parent-child relationship) causes the child query to be executed once for each instance of its parent group.
When you create a data link in the Data Model view of your report, Report Builder constructs a clause (as specified in the link's Property Palette) that will be added to the child query's SELECT statement at runtime.

Layout Model
The Report Editor's Layout Model view enables you to define and modify the layout model objects for a report. In this view, objects and their property settings are represented symbolically to highlight their types and relationships.

This is the view where you can design your Report Layout.

Object Navigator
The Object Navigator provides a hierarchical display of all major objects in a report or template, including attached libraries and external queries. Using this view, you can take such actions as select an object, bring up the Property Palette for an object, edit an object's PL/SQL, drag and drop PL/SQL program units, and search for an object by name.

Report Triggers
Report triggers execute PL/SQL functions at specific times during the execution and formatting of your report. Using the conditional processing capabilities of PL/SQL for these triggers, you can do things such as customize the formatting of your report, perform initialization tasks, and access the database.

To create or modify a report trigger, use Report Triggers in the Object Navigator. Report triggers must explicitly return TRUE or FALSE. Report Builder has five global report triggers which are fired in the following sequence.

1. Before Parameter Form trigger
2. After Parameter Form trigger
3. Before Report trigger
4. Between Pages trigger
5. After Report trigger

1. Before Parameter Form trigger
The Before Parameter Form trigger fires before the Runtime Parameter Form is displayed. From this trigger, you can access and change the values of parameters, PL/SQL global variables, and report-level columns. If the Runtime Parameter Form is suppressed, this trigger still fires. Consequently, you can use this trigger for validation of command line parameters.
Definition Level Report

On Failure
Displays an error message and then returns to the place from which you ran the report.

2. After Parameter Form trigger
The After Parameter Form trigger fires after the Runtime Parameter Form is displayed. From this trigger, you can access parameters and check their values. This trigger can also be used to change parameter values or, if an error occurs, return to the Runtime Parameter Form. Columns from the data model are not accessible from this trigger. If the Runtime Parameter Form is suppressed, the After Parameter Form trigger still fires. Consequently, you can use this trigger for validation of command line parameters or other data.

Definition Level Report

On Failure
Returns to the Runtime Parameter Form. If the Form is suppressed, then returns to place from which you ran the report.

3. Before Report trigger
The Before Report trigger fires before the report is executed but after queries is parsed and data is fetched.
Definition Level Report

On Failure
Displays an error message and then returns to the place from which you ran the report.

4. Between Pages trigger
Between Pages trigger fires before each page of the report is formatted, except the very first page. This trigger can be used for customized page formatting. In the Runtime Previewer or Live Previewer, this trigger only fires the first time that you go to a page. If you subsequently return to the page, the trigger does not fire again.
Definition Level report
On Failure
Displays an error message when you try to go to the page for which the trigger returned FALSE. The Between Pages trigger does not fire before the first page.

5. After Report trigger
The After Report trigger fires after you exit the Runtime Previewer, or after report output is sent to a specified destination, such as a file, a printer, or a mailid. This trigger can be used to clean up any initial processing that was done, such as deleting tables.
Note, however, that this trigger always fires, whether or not your report completed successfully.
Definition Level Report

On Failure
Does not affect formatting because the report is done. You can raise a message, though, to indicate that the report did not run correctly

Note: The After-Report trigger does not fire when you are in the Live Previewer.

Layout Model Properties

In this Layout model, we have several Options

Frames:
Frames are used to surround other objects and protect them from being overwritten or pushed by other objects.
For example, a frame might be used to surround all objects owned by a group, to surround column headings, or to surround summaries.
When you default the layout for a report, Report Builder creates frames around report objects as needed; you can also create a frame manually in the Layout Model view.

Repeating Frames
Repeating frames surround all of the fields that are created for a group's columns. The repeating frame prints (is fired) once for each record of the group.
When you default the layout for a report, Report Builder creates repeating frames around fields as needed; you can also create a repeating frame manually in the Layout Model view.

Text
This allows to embed the text in the layout view.

Field
A field is the layout container for each column in the layout. A field is owned by the object surrounding it, typically a repeating frame, unless the field is a summary (in which case it is owned by a frame).

Anchor
Anchors are used to determine the vertical and horizontal positioning of a child object relative to its parent. The end of the anchor with a symbol on it is attached to the parent object...

Parameter Form
The Report Editor's Parameter Form view enables you to create a Runtime Parameter Form for your report. You can select pre-defined system parameters for your form using the Parameter Form Builder, or you can create your own.

Program Units
Program units are packages, functions, or procedures that you can reference from any PL/SQL within the current report.

Stored program units (also known as stored subprograms) can be compiled separately and stored permanently in an Oracle database, ready to be executed. Once compiled and stored in the data dictionary, they are schema objects, which can be referenced by any number of applications connected to that database.
Stored program units offer higher productivity, better performance, memory savings, application integrity, and tighter security. For example, by designing applications around a library of stored procedures and functions, you can avoid redundant coding and increase your productivity.

Stored program units are stored in parsed, compiled form. So, when called, they are loaded and passed to the PL/SQL engine immediately. Also, they take advantage of shared memory. So, only one copy of a program unit need be loaded into memory for execution by multiple users.

Attached Libraries
Attached libraries are external PL/SQL libraries that you have associated with a report or another external library. When an external library is attached, you can reference its packages, functions, and procedures from within your report. For example, if you attached an external library name MYLIB to your report and it contained a function named ADDXY, then you could reference ADDXY from any PL/SQL in the report.

Report Customizations
You can customize business intelligence reports by both content and layout. You also have the option to add columns, filter the data and sort the resulting information. For example, you can add another column for a running total, or insert grand totals and subtotals as you need them. In layout, you can change column headings, report titles and the order of columns. You can also display the data in graphical form, such as bar graphs or pie charts.

Customization is enhancement of new features to the Existing Report Content and Layout depending on the new requirement.

Tuesday, 29 May 2012

Unix commands reference



files and directories

 


print,clear and making directories
pwd : Display the current directoryclear :Clears the screenmkdir temp :Create a directorymkdir -p temp/junk :Create nested directories


Change directory

cd bob
cd .. (parent directory)cd - (previous directory)cd (home directory)cd ~bill (home directory of user bill):: Changing directories

copy command



cp source.txt dest.txt : Copy a file to anothercp file1.txt file2.txt destination_dir :Copy files to a directory


cp -r source_dir dest_dir
rsync -a source_dir/ dest_dir/:
Copy directories recursively

Link move,remove commands:
ln -s linked_file link :Create a symbolic link

mv source_file dest_file ::Rename a file, link or directory

rm file1.txt file2.txt ::Remove files or links
rmdir ron :Remove empty directoriesrm -rf ron :Remove non-empty directories

Listing files

ls :List all files (not starting with .) in the current directoryls -l :Display a long listingls -a :List all the files in the current directory,including ones (starting with .)ls -t :List by time (most recent files first)ls -S :List by size (biggest files first)ls -r :List with a reverse sort orderls -ltr :Long list with most recent files last


Displaying file contents

 
cat file1:Displays contents of a filecat file1 file2:Concatenate and display file contents:more file1
(or)
less file1:
Displays the contents of a file (stopping at each page)more file1 file2

(Or)
less file1 file2
  :Display the contents of several files (stopping at each page)head -10 file :Display the first 10 lines of a filetail -10 file :Display the last 10 lines of a file

Displaying startup files
cat /proc/cpuinfo :view CPU information

cat /proc/meminfo :view RAM information

cat /proc/dma :view IRQ, DMA, and I/O data

cat /proc/modules :lists devices inserted into kernel as modules

dmesg | tail
:displays hardware detected at last boot

tail /var/log/boot.log
:view system processes successful or not


File name pattern matching
cat *:Concatenate all filescat .*:Concatenate all filescat *.log:Concatenate all files ending with .logls *read*: List files with read in their namels *.?:List all files ending with . and asingle character



Handling file contents
grep ron readme.txt :Show only the lines in the file readme.txt containing the string 'ron'grep -i ron readme.txt :Case insensitive searchgrep -v ron readme.txt :Showing all the lines but the ones containing a substring:grep -r substring dir :Search through all the files in a directory

sort readme.txt :Sort lines in a given file:sort -u readme.txt (unique):Sort lines, only display duplicate ones once


Hard Drives

had :primary master IDE hdb :primary slave IDEhdc :secondary master IDEhdd :secondary slave IDE

sda :first SCSI hard disksdb :second SCSI hard diskhda1, hda2, hda3, and hda4:four primary partitions of primary master drivehda5:first logical drive of primary master drive
Changing file access rights


chmod 777 readme.txt :Add all permissions to a file
chmod 700 readme.txt
:Give owner full permissions, all else no permissionschmod 755 readme.txt :Give owner full permissions, all else read and write onlychmod 555 readme.txt :Give a file read and execute permissions for all

chmod u+w readme.txt
:Add write permissions to the current userchmod g+r readme.txt :Add read permissions to users in the file groupchmod o+x readme.txt :Add execute permissions to other userschmod a+rw readme.txt :Add read + write permissions to all users
chmod a+rX *:
Make executable files executable by all
chmod -R a+rX dir :(recursive)Make the whole directory and its contents
accessible by all users


Comparing files and directories


 

diff readme.txt readme.bak :Comparing 2 filesgvimdiff file1 file2 :Comparing 2 files (graphical)tkdiff file1 file2
kompare file1 file2

diff -r dir1 dir2: Comparing 2 directories

Looking for files


 

find . -name "*log*" : Find all files in the current (.) directory and its subdirectories with log in their namefind . -name "*.pdf" exec xpdf {} ';' : Find all the .pdf files in dir and subdirectories and run a command on eachlocate "*pub*" :Quick system-wide file search by pattern
(caution: index based, misses new files)


Redirecting command output


 

ls *.png > image_files :Redirect command output to a filels *.jpg >> image_files :Append command output to an existing filecat *.log | grep error :Redirect command output to the input of
another command

Job control


 

ps -ef :Show all running processes:top : Live hit-parade of processes (press P, M, T: sort by Processor, Memory or Time usage)kill 543 (number found in ps output):Send a termination signal to process number 543:kill -9 543:Have the kernel kill process 543kill -9 -1:Kill all processes (at least all user ones)xkill (click on the program window to kill)::Kill a graphical application


File and partition sizes

du -sh dir1 dir2 file1 file2: Show the total size on disk of files ordirectories (disk usage)wc file (word count):Number of bytes, words and lines in filedf -h . : Show the size, total space and free space of the
current partition:
df –h:Display these info for all partitions


Compressing

 


gzip readme.txt (.gz format)bzip2 readme.txt (.bz2 format, better): Compress a file called readme.txt

gunzip readme.txt.gz
bunzip2 readme.txt.bz2 :
Uncompress a file

Archiving


tar zcvf archive.tar.gz dir/:Create a compressed archive (tape archive)tar jcvf archive.tar.bz2 dir/ (better)


tar ztvf archive.tar.gz
tar jtvf archive.tar.bz2 :
Test (list) a compressed archivetar zxvf archive.tar.gz
tar jxvf archive.tar.bz2 :
Extract the contents of a compressed archive

tar options:
c: create
t: test
x: extract
j: on the fly bzip2 (un)compression
z: on the fly gzip (un)compression

Using 7-zip: (better compression than bzip2!)
7z a archive.7z <files> (add: create)7z l archive.7z (list)7z x archive.7z (extract)
7-zip compressed tar archive
(keeps user and group information)
tar cf - dir | 7z a -si dir.tar.7z (create)7z x -so dir.tar.7z | tar xf - (extract)

Handling zip archives
zip -r archive.zip <files> (create)unzip -t archive.zip (test / list)unzip archive.zip (extract)


Printing


lpr Pqueue f1.ps f2.txt (local printer): Send -PostScript or text files to queuelpq -Pqueue :List all the print jobs in queuecancel 123 queue : Cancel a print job number in queuepdf2ps doc.pdf :Print a PDF filelpr doc.ps

ps2pdf doc.ps
xpdf doc.pdf
: View a PostScript file


User management


who :List users logged on the systemwhoami :Show which user I am logged asgroups user :Show which groups user belongs tofinger user :Tell more information about usersu - ron :Switch to user ron:su - (switch user):Switch to super user (root)su (keep same directory and environment)

 


Time management

sleep 60 :Wait for 60 seconds:date :Show the current date:time command :Count the time taken by a command:

Command help
 

grep --help : Basic help (works for most commands):man grep : Access the full manual page of a command:


Misc commands


 


bc -l : Basic command-line calculator



Basic system administration



chown -R newuser:newgroup dir ::Change the owner and group of a directory and
all its contents:
shutdown -r +5:Reboot the machine in 5 minutes:shutdown -h now : Shutdown the machine now:ifconfig -a : Display all available network interfaces:ifconfig eth0 207.46.130.108:Assign an IP address to a network interfaceifconfig eth0 down :Bring down a network interfaceroute add default gw 192.168.0.1:Define a default gateway for packets to
machines outside the local network
route del default : Delete the default route:ping 207.46.130.108: Test networking with another machine:fdisk /dev/hda1:Create or remove partitions on the first IDE
hard disk:
mkfs.ext3 /dev/hda1:Create (format) an ext3 filesystem:mkfs.vfat -v -F 32 /dev/hda2:Create (format) a FAT32 filesystem:

mount /dev/uba1 /mnt/usbdisk :Mount a formatted partitionmount -o loop initrd.img /mnt/initrd: Mount a filesystem image (loopback device):umount /mnt/usbdisk: Unmount a filesystem: uname -a
uname –r:
Check the system kernel versions

 
Simple VI commands
vi : Start vivi readme.txt : Start vi with the file readme.txt

press the i key : change into insert mode

press the escape key : change into the command modeq! : quit without saving

wq or ZZ: quit and save w :save file

w readme.txt :save and give filename


Sunday, 27 May 2012

SAMPLE SQL QUERIES


QUERIES
------------------------------------------------------------------------------------------------------------------------------------------------------------------
1..display all group function on sal?
sql>SELECT MAX(SAL),MIN(SAL),SUM(SAL),AVG(SAL),COUNT(SAL)
FROM EMP;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
2..DISPLAY THOSE EMPLOYEE WHOSE SALARY IS EVEN NO?
SQL>SELECT EMPNO,ENAME,SAL
           FROM EMP
WHERE MOD(SAL,2)=0;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3..DISPLAY THOSE EMPLOYEES WHOSE SALARY KEEPS DECIMAL DIGIT?
SQL>SELECT EMPNO,ENAME,SAL
          FROM EMP
       WHERE SAL LIKE %.%;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
4..DISPLAY THE 3% OF SAL UPTO TWO DECIMAL DIGIT?

SQL>SELECT EMPNO,ENAME,SAL*.03,ROUND(SAL*.03,2)
          FROM EMP;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
5..DISPLAY THE EMPLOYEE WHOSE NAME HAS CHAR 'A'?
SQL>SELECT EMPNO,ENAME
FROM EMP
WHERE ENAME LIKE 'A%';
------------------------------------------------------------------------------------------------------------------------------------------------------------------
6..DISPLAY THE NAME IN UPPERCASE,JOB IN LOWER CASE?
SQL>  SELECT UPPER(ENAME),LOWER(JOB)
FROM EMP;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
7..DISPLAY THE NAME WITH 5 LEADING MINUS SIGN?
SOL..SELECT ENAME,'-----'||ENAME   FROM EMP;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
          

8..DISPLAY THE EMPLOYEE NAME,JOB,ANNUAL SAL,AND
    TOTAL COMPENSATION FOR ALL EMPLOYEES;
SQL>SELECT ENAME,JOB,(SAL+NVL(COMM,0))*12
FROM EMP
------------------------------------------------------------------------------------------------------------------------------------------------------------------
9..DISPLAY THE DIFFERENT TYPE OF JOB IN EMP?
SQL>SELECT DISTINCT JOB
          FROM EMP;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
10..DISPLAY THE EMPLOYEE WHOSE COMM IS MORE THAN 25% OF SALARY?
SQL>SELECT ENAME,SAL
FROM EMP
WHERE COMM>(SAL*.25);
11..DISPLAY THE NAME,JOB,AND MGR FOR EMPLOYEE 
WHOSE SALESMAN OR MANAGER?
SQL>SELECT EMPNO,ENAME,MGR,JOB
FROM EMP
WHERE JOB = 'SALESMAN' OR JOB='MANAGER';
------------------------------------------------------------------------------------------------------------------------------------------------------------------
12..DISPLAY THE NAME,JOB,SAL WITH THE FOLLOWING CONDITION
  A)     WHERE DEPTNO=20 OR DEPTNO=10 AND JOB=MANAGER;
SQL>SELECT ENAME,JOB,SAL,DEPTNO
FROM EMP
WHERE(( DEPTNO=20 OR DEPTNO=10) AND JOB='MANAGER');

B)WHERE DEPTNO=20 OR(DEPTNO=10 AND JOB='MANAGER')?
SQL>SELECT EMPNO,ENAME,JOB,SAL,DEPTNO
FROM EMP
WHERE DEPTNO=20 OR(DEPTNO=10 AND JOB='MANAGER')
ORDER BY DEPTNO;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
C)WHERE (DEPTNO=20 OR DEPTNO=10)AND JOB='MANAGER'?
SELECT EMPNO,ENAME,JOB,SAL,DEPTNO
FROM EMP
WHERE (DEPTNO=20 OR DEPTNO=10)AND JOB='MANAGER'
ORDER BY DEPTNO;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
13>DISPLAY EMPLOYEES WHOSE EMPNO IS GREATER THAN 
7799 AND LESS THEN 7901?
SQL>SELECT EMPNO,ENAME,JOB,SAL,DEPTNO
FROM EMP
WHERE EMPNO>7799 AND EMPNO<7901
------------------------------------------------------------------------------------------------------------------------------------------------------------------
14>DISPLAY THE NAME WHICH START WITH 'J',
ENDS WIH 'S' AND HAVING THE CHAR  'E' IN THE NAME?
SQL>SELECT EMPNO,ENAME
FROM EMP
WHERE ENAME LIKE 'J%E%S';
------------------------------------------------------------------------------------------------------------------------------------------------------------------
15>DISPLAY THE NAME OF 05 CHARS AND ENDS WITH 'S'?
SQL>SELECT EMPNO,ENAME
FROM EMP
WHERE ENAME LIKE '____S';
------------------------------------------------------------------------------------------------------------------------------------------------------------------
16>DISPLAY DEPT WISE TOTAL SALARY

SQL>select deptno,sum(sal) from emp group by deptno;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
17>DISPLAY AVG(SUM(SAL),SUM(AVG(SAL) AND SEE THE DIFFERENCE>
SQL>SELECT AVG(SUM(SAL)),SUM(AVG(SAL))
,AVG(SUM(SAL))-SUM(AVG(SAL))
FROM EMP GROUP BY EMPNO;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
18>DISPLAY THE DEPT WHICH HAVING TWO 
     OR MORE EMPLOYEE OF SAME JOB?

------------------------------------------------------------------------------------------------------------------------------------------------------------------

19>DISPLAY THE EMPLOYEE WHO JOIN THE COMPANY OTHER THAN 
THE YEAR 81?
SQL>SELECT * FROM EMP
WHERE HIREDATE NOT BETWEEN '01-JAN-81' AND '31-DEC-81';

------------------------------------------------------------------------------------------------------------------------------------------------------------------
20>DISPLAY THE EMPNO,ENAME,JOB USING SUB QUERY IN PLACE OF 
        TABLE----INLINE VIEW?
SQL>DOUBT SHOULD BE CLARFIED

------------------------------------------------------------------------------------------------------------------------------------------------------------------
21>DISPLAY THOSE EMPLOYEES WHOSE GRADE IS 3 
AND JOB OTHER THAN MANAGER?
SQL>/SELECT E.EMPNO,E.ENAME,S.GRADE,E.JOB
FROM EMP E,SALGRADE S
WHERE E.SAL BETWEEN S.LOSAL AND S.HISAL
AND S.GRADE=3 AND
E.JOB NOT IN('MANAGER');
------------------------------------------------------------------------------------------------------------------------------------------------------------------
24>DISPLAY THE EMPLOYEES WHO GET MAX(SAL) IN HIS DEPT?
/
SELECT EMPNO,ENAME,SAL,DEPTNO
FROM EMP
WHERE SAL IN(SELECT MAX(SAL) FROM EMP);
------------------------------------------------------------------------------------------------------------------------------------------------------------------
25>DISPLAY THE EMPNO,ENAME,JOB,DEPTNO,DNAME,LOC
       WITH DEPT WHICH AS NO EMPLOYEES?
SQL>
------------------------------------------------------------------------------------------------------------------------------------------------------------------
26>DISPLAY MANAGERS NAMES 
    AND TOTAL SALARY PAID FOR EMPLOYEE UNDER THEM?
SQL>SELECT B.ENAME,SUM(A.SAL)
FROM EMP A,EMP B
WHERE B.EMPNO=A.MGR
GROUP BY B.ENAME;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
27>DISPLAY THE GRADES AND TOTAL SALARY PAID FOR   EACH GRADE?
SQL> SELECT B.GRADE,SUM(A.SAL)
  2  FROM EMP A,SALGRADE B
  3  WHERE A.SAL BETWEEN LOSAL AND HISAL
  4  GROUP BY B.GRADE;
------------------------------------------------------------------------------------------------------------------------------------------------------------------

28>DISPLAY EACH DEPT NAME AND NO OF EMPLOYEES     WORKING IN IT  ?
SQL> SELECT A.DEPTNO,B.DNAME,COUNT(*)
  2  FROM EMP A,DEPT B
  3  WHERE A.DEPTNO=B.DEPTNO
  4  GROUP BY A.DEPTNO,B.DNAME;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
29>DISPLAY EACH JOB CATAGORIES  AND NO OF EMPLOYEES WORKING IN IT?
SQL> SELECT DISTINCT JOB,COUNT(*)
  2  FROM EMP
  3  GROUP BY JOB;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
30>DISPLAY  MANAGER  WHO ARE MANAGER FOR LEAST NO OF  EMPLOYEES?
SQL> SELECT A.ENAME,COUNT(*)
  2  FROM EMP A,EMP B
  3  WHERE A.EMPNO=B.MGR
  4  GROUP BY A.ENAME;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
31>DISPLAY MANAGER WHO ARE MANGER FOR LEAST NO OF EMPLOYEES
SQL>
  1  SELECT A.ENAME,COUNT(*)
  2  FROM EMP A,EMP B
  3  WHERE A.EMPNO=B.MGR
  4  GROUP BY A.ENAME
  5  HAVING COUNT(*)=(SELECT MIN(COUNT(*))
  6                   FROM EMP
  7*                  GROUP BY ENAME);
------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL>
  1  SELECT A.ENAME,COUNT(*)
  2  FROM EMP A,EMP B
  3  WHERE A.EMPNO=B.MGR
  4  GROUP BY A.ENAME
  5* HAVING COUNT(*)<3;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
32>DISPLAY LEAST 3 SALARY PAID EMPLOYEE
SQL>SELECT  ROWNUM,ENAME,SAL
FROM (SELECT ROWNUM,ENAME,SAL
      FROM EMP
      ORDER BY SAL)
GROUP BY ROWNUM,SAL,ENAME
HAVING ROWNUM<=3;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
33>DISPLAY THE DEPT WHERE MINIMUM NO OF EMPLOYEES WORKING?
SQL>SELECT DEPTNO,COUNT(*)
FROM EMP
GROUP BY DEPTNO
HAVING COUNT(*)=(SELECT MIN(COUNT(*))
                                     FROM EMP
                                     GROUP BY DEPTNO);
------------------------------------------------------------------------------------------------------------------------------------------------------------------

34>DISPLAY THE ROW B/W 6 th  AND 10th?
SQL>SELECT ROWNUM,EMPNO,ENAME,SAL,JOB
FROM EMP
WHERE ROWNUM<10
MINUS
SELECT ROWNUM,EMPNO,ENAME,SAL,JOB
FROM EMP
WHERE ROWNUM<6;
------------------------------------------------------------------------------------------------------------------------------------------------------------------

35>DISPLAY 9 ROW?
SQL>SELECT ROWNUM,ENAME
FROM EMP
GROUP BY ROWNUM,ENAME
HAVING ROWNUM=9;
------------------------------------------------------------------------------------------------------------------------------------------------------------------

36>DISPLAY THE 4 th ROW AND THE LAST ROW?
SQL>SELECT ROWNUM,ENAME
   FROM EMP 
   GROUP BY ROWNUM,ENAME
   HAVING ROWNUM=4
   UNION 
   SELECT ROWNUM,ENAME
    FROM EMP 
   GROUP BY ROWNUM,ENAME
   HAVING ROWNUM=(SELECT MAX(ROWNUM)FROM EMP);
------------------------------------------------------------------------------------------------------------------------------------------------------------------

37>DISPLAY THE LAST 10 ROWS?
SQL.SELECT ROWNUM,ENAME
FROM EMP 
MINUS
SELECT ROWNUM,ENAME
FROM EMP 
WHERE ROWNUM<=(SELECT MAX(ROWNUM)-10 FROM EMP);

------------------------------------------------------------------------------------------------------------------------------------------------------------------
38>DISPLAY THE LAST 1st 6 ROWS?
SQL>SELECT ROWNUM,ENAME
       FROM EMP
       GROUP BY ROWNUM,ENAME 
     MINUS
         SELECT ROWNUM,ENAME
         FROM EMP 
        GROUP BY ROWNUM,ENAME
         HAVING ROWNUM>=7;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
39>DISPLAY ALTERNATIVE ROWS?
SQL>SELECT ROWNUM,ENAME
          FROM EMP
          GROUP BY ROWNUM,ENAME 
           HAVING MOD(ROWNUM,2)=0
------------------------------------------------------------------------------------------------------------------------------------------------------------------
40>DISPLAY THE EMPLOYEE WHO GET SAME SALARY?
SQL> SELECT * FROM EMP
WHERE SAL IN(SELECT SAL FROM EMP
              GROUP BY SAL
              HAVING COUNT(SAL)>1)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
41>DISPLAY 'A' IF SAL IS MORE THAN COMM  ELSE 'B'?
SQL>SELECT SAL ,COMM,
DECODE(
GREATEST(SAL,NVL(COMM,0)),SAL,'A',COMM,'B') 
FROM EMP;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
42>DISPLAY THE EMPLOYEE WHO WORK WITH BLAKE AND HAVING GRADE>=3?
SQL>SELECT A.ENAME,G.GRADE
        FROM EMP A,EMP B,SALGRADE G
        WHERE B.EMPNO=A.MGR
       AND B.SAL BETWEEN G.LOSAL AND G.HISAL
      AND B.ENAME LIKE 'BLAKE'
      AND G.GRADE>=3;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
43>DISPLAY THOSE EMPLOYEES WHOSE MANAGER GETTING SALARY>=3000?
SQL>SELECT A.ENAME,A.JOB
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
AND B.SAL>=3000;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
44>DISPLAY THE JOB WHICH HAVING MORE EMPLOYEES OF GRADE 3?
SQL>SELECT A.JOB,COUNT(*),G.GRADE
   FROM EMP A,SALGRADE G 
   WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
  GROUP BY A.JOB,G.GRADE
  HAVING COUNT(*)>(SELECT MAX(COUNT(*)) FROM EMP
                   GROUP BY EMPNO)
  AND G.GRADE=3;
------------------------------------------------------------------------------------------------------------------------------------------------------------------
45> DISPLAY THE GRADE WHICH HAVING MORE EMPLOYEES?
SQL>SELECT COUNT(*),G.GRADE
   FROM EMP A,SALGRADE G 
   WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
  GROUP BY G.GRADE
  HAVING COUNT(*)>(SELECT MAX(COUNT(*)) FROM EMP
                                      GROUP BY JOB)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
46>PRINT WEBNOLOGY AS WEB-NO-LOGY?
SQL>SELECT 'WEBNOLOGY'
      ,DECODE('WEBNOLOGY'
      ,'WEBNOLOGY'
      ,'WEB_NO_LOGY'
      ) FROM DUAL


------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------
1.DISPLAY THOSE EMPLOYEES WHO GET SAME SALARY?
SQL>SELECT A.ENAME,A.SAL
FROM EMP A
WHERE SAL IN(SELECT B.SAL FROM  EMP B
                            GROUP BY B.SAL
HAVING COUNT(*)>1)
------------------------------------------------------------------------------------------------------------------------------------------------------------------


2>DISPLAY LAST 5 RECORDS?
SQL>SELECT ROWNUM,ENAME
  FROM EMP
  MINUS
  SELECT ROWNUM,ENAME
  FROM EMP
  WHERE ROWNUM<=(SELECT MAX(ROWNUM)-5 FROM EMP)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THE ALTERNATIVE RECORDS?
SQL>SELECT ROWNUM,ENAME
FROM EMP
GROUP BY ROWNUM,ENAME
HAVING MOD(ROWNUM,2)=1
------------------------------------------------------------------------------------------------------------------------------------------------------------------

4>DISPLAY THOSE EMPLOYEES WHO ARE NOT MANAGER?
SQL>SELECT ENAME,JOB
FROM EMP
WHERE JOB NOT IN('MANAGER')
------------------------------------------------------------------------------------------------------------------------------------------------------------------
5>DISPLAY THE THIRD HIGEST PAID EMPLOYEE?
SQL>SELECT ROWNUM,ENAME,SAL
          FROM(SELECT ROWNUM,ENAME,SAL FROM EMP
          ORDER BY SAL DESC)
          GROUP BY ROWNUM,ENAME,SAL
           HAVING ROWNUM=3
------------------------------------------------------------------------------------------------------------------------------------------------------------------
6>DISPLAY 7th RECORD?
SOL>SELECT ROWNUM ,EMPNO,ENAME
FROM(SELECT ROWNUM,EMPNO,ENAME
             FROM EMP
             ORDER BY ROWNUM ASC)
GROUP BY ROWNUM,EMPNO,ENAME
HAVING ROWNUM=7
------------------------------------------------------------------------------------------------------------------------------------------------------------------
7>DISPLAY RECORDS B/W 10th TO 12th?
SQL>SELECT ROWNUM ,EMPNO,ENAME
FROM(SELECT ROWNUM,EMPNO,ENAME
             FROM EMP
             ORDER BY ROWNUM ASC)
GROUP BY ROWNUM,EMPNO,ENAME
HAVING ROWNUM BETWEEN 10 AND 12
------------------------------------------------------------------------------------------------------------------------------------------------------------------
8>DISPLAY LAST RECORD?
SQL>SELECT ROWNUM,EMPNO,ENAME
FROM EMP
GROUP BY ROWNUM,EMPNO,ENAME
HAVING ROWNUM=(SELECT MAX(ROWNUM)FROM EMP)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
10>DISPLAY TH E EMPLOYEE WHO GET MAX SAL IN THEIR            DEPT?
SQL>SELECT ENAME,SAL
FROM EMP
WHERE SAL IN(SELECT MAX(SAL) FROM EMP)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
11>DISPLAY THE EMPLOYEE WHO GWT MORE SALARY THAN AVG SALARY IN THEIR DEPT?
SQL>SELECT ENAME,SAL
FROM EMP
WHERE SAL >(SELECT AVG(SAL) FROM EMP)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
12>DISPLAY THE NAME OF MANAGER FOR EACH EMPLOYEE?
SQL>SELECT A.ENAME,B.ENAME
FROM EMP A, EMP B
WHERE A.MGR=B.EMPNO
------------------------------------------------------------------------------------------------------------------------------------------------------------------
13>DISPLAY THE EMPLOYEE WHO JOIN THE DEPT BEFORE THEIR MANAGER?
SQL>SELECT A.ENAME
FROM EMP A, EMP B
WHERE A.MGR=B.EMPNO
AND A.HIREDATE>B.HIREDATE
------------------------------------------------------------------------------------------------------------------------------------------------------------------
14>DISPLAY THE FIRST FIVE HIGHEST PAID EMPLOYEE?
SQL>SELECT ROWNUM ,SAL
FROM(SELECT SAL
FROM EMP
ORDER BY SAL)
GROUP BY ROWNUM,SAL
HAVING ROWNUM<=5
------------------------------------------------------------------------------------------------------------------------------------------------------------------

15>DISPLAY LAST FIVE LEAST PAID EMPLOYEES?


16>PRINT LIKE
                               *
                           *     *
                       *       *        *
                   *      *    *      *  *
SQL>SELECT LPAD('  ',3,'*')
FROM DUAL
UNION
SELECT LPAD('  ',4,'*')
FROM DUAL
UNION
SELECT LPAD('  ',5,'*')
FROM DUAL
UNION
SELECT LPAD('  ',6,'*')
FROM DUAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------
17>PRINT LIKE
         A
         AS
         ASH
         ASHO
         ASHOK
SQL>SELECT LPAD('  ',3,'A')
FROM DUAL
UNION
SELECT LPAD('  ',4,'AS')
FROM DUAL
UNION
SELECT LPAD('  ',5,'ASH')
FROM DUAL
UNION
SELECT LPAD('  ',6,'ASHO')
FROM DUAL
UNION
SELECT LPAD('  ',7,'ASHOK')
FROM DUAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------
18>DISPLAY THE HIEARCHIES OF EMPLOYEES?
SQL>SELECT LPAD(' ',LEVEL*3,'')||ENAME
FROM EMP
START WITH MGR IS NULL
CONNECT BY PRIOR EMPNO=MGR
------------------------------------------------------------------------------------------------------------------------------------------------------------------
19>DISPLAY THE MANAGER WHO HAS MORE THAN 
   THREE EMPLOYEES UNDER HIM?
SQL>SELECT A.ENAME,COUNT(*)
        FROM EMP A,EMP B
        WHERE A.EMPNO=B.MGR
        GROUP BY A.ENAME
       HAVING COUNT(*)>3
------------------------------------------------------------------------------------------------------------------------------------------------------------------
20>DISPLAY THE EMPLOYEE WHO HAS SAME JOB IN DEPT?

------------------------------------------------------------------------------------------------------------------------------------------------------------------
21>DISPLAY ALL MANAGER NAME?
SQL>SELECT A.ENAME,A.EMPNO,COUNT(*)
       FROM EMP A,EMP B
       WHERE A.EMPNO=B.MGR
       GROUP BY A.ENAME,A.EMPNO
------------------------------------------------------------------------------------------------------------------------------------------------------------------
22>DISPLAY THE MANAGER NAME UNDER WHOM SALESMAN WORKS?
SQL>SELECT B.ENAME,B.DEPTNO,A.JOB,A.ENAME,A.DEPTNO
         FROM EMP A,EMP B
         WHERE A.MGR=B.EMPNO
         AND A.JOB='SALESMAN'
------------------------------------------------------------------------------------------------------------------------------------------------------------------
23>DISPLAY THE EMPLOYEE WHO WORKS IN 
       THEIR MANAGER DEPT?
SQL>SELECT A.ENAME
           FROM EMP A
           WHERE A.DEPTNO=(SELECT B.DEPTNO FROM EMP B
           WHERE A.MGR=B.EMPNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
24>DISPLAY THE EMPLOYEE WHO WORKS WITH FORD 
                                       AND GETTING SAME SALARY?
SQL>SELECT A.ENAME
  FROM EMP A,EMP B
   WHERE B.EMPNO=A.MGR
   AND  B.ENAME='FORD'
   AND A.SAL=B.SAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------
26>DISPLAY THE EMPLOYEE WHO WORKS IN DEPT=20
               AND JOB LIKE SALES DEPT?

SQL>SELECT ENAME,DEPTNO,JOB
          FROM EMP
        WHERE DEPTNO=20
        AND JOB='SALESMAN';
------------------------------------------------------------------------------------------------------------------------------------------------------------------
27>DISPLAY THE MANAGER NAME AND THEIR DEPT NAME?

SQL>SELECT A.ENAME,D.DNAME
         FROM EMP A,EMP B,DEPT D
          WHERE A.MGR=B.EMPNO
         AND A.DEPTNO=B.DEPTNO
        GROUP BY A.ENAME,D.DNAME
------------------------------------------------------------------------------------------------------------------------------------------------------------------
28>DISPLAY THE EMPLOYEE NO EVEN/ODD?
SQLSELECT EMPNO FROM EMP
WHERE MOD(EMPNO,2)=1

SQL>SELECT EMPNO FROM EMP
WHERE MOD(EMPNO,2)=O
------------------------------------------------------------------------------------------------------------------------------------------------------------------
29>DISPLAY THE RECORD NO OF EMP/DEPT TOGETHER AS
SQL>SELECT 'DEPT'TABL ,COUNT(*)RECORDNO  
         FROM DEPT
        UNION
            SELECT 'EMP' TABL ,COUNT(*)RECORDNO  
             FROM EMP
------------------------------------------------------------------------------------------------------------------------------------------------------------------
30>DISPLAY THE SALARY OF ALL MANAGER?
SQL>SELECT A.ENAME,A.SAL
    FROM EMP A,EMP B    
       WHERE A.MGR=B.EMPNO
------------------------------------------------------------------------------------------------------------------------------------------------------------------
31>DISPLAY THE EMPLOYEE WHO JOINED FIRST HALF OF THE MONTH?
SQL>SELECT ENAME,JOB,HIREDATE
FROM EMP
WHERE SUBSTR(HIREDATE,1,2)BETWEEN 1 AND 15
------------------------------------------------------------------------------------------------------------------------------------------------------------------

32>DISPLAY THE MIDDLE CHAR OF NAME ,
IF NAMES KEEPS ODD NUMBER OF CHARACTERS?
SQL>SELECT ENAME,SUBSTR(ENAME,ROUND(LENGTH(ENAME)/2),1)
FROM EMP

------------------------------------------------------------------------------------------------------------------------------------------------------------------
33>DISPLAY EMPLOYEES WHOSE NAME AND THEIR MANAGER NAME START 
WITH SAME CHARCTER?
SQL>SELECT A.ENAME,B.ENAME
        FROM EMP A, EMP B
         WHERE A.MGR=B.EMPNO
           AND ASCII(A.ENAME)=ASCII(B.ENAME)
------------------------------------------------------------------------------------------------------------------------------------------------------------------



                      CO-RELATED QUERIES
                     =-=-=-=-=-=-=-=-=-=-
------------------------------------------------------------------------------------------------------------------------------------------------------------------

1>DISPLAY THOSE EMPLOYEES WHOSE DEPT IS SAME AS THEIR MANAGER DEPT?
SQL>SELECT A.ENAME,A.DEPTNO
          FROM EMP A
           WHERE A.DEPTNO=(SELECT B.DEPTNO FROM EMP B
                                              WHERE A.MGR=B.EMPNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
2>DISPLAY THOSE EMPLOYEES WHO SAL IS GREATER THEN THE AVG SAL OF DEPT?
SQL.SELECT A.ENAME,A. SAL
      FROM EMP A
      WHERE A.SAL>(SELECT AVG(SAL) FROM EMP B WHERE        A.DEPTNO=B.DEPTNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THE EMPLOYEE WHO JOINED BEFORE HIS MANAGER?
SQL>SELECT A.ENAME,A.HIREDATE
        FROM EMP A 
         WHERE A.HIREDATE<(SELECT B.HIREDATE FROM EMP  B
        WHERE A.MGR=B.EMPNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------

4>DISPLAY THOSE EMPLOYEE WHO 
     JOINED IN SAME DATE AS THEIR MANAGER?
SQL>SELECT A.ENAME,A.HIREDATE
        FROM EMP A
          WHERE A.HIREDATE=(SELECT B.HIREDATE FROM EMP  B
                                                  WHERE A.MGR=B.EMPNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
5>DISPLAY  THOSE MANAGER WHOSE SALARY IS 
       GREATER THAN THEIR EMPLOYEE?
SQL>SELECT A.ENAME,A.SAL
         FROM EMP A
            WHERE A.SAL>(SELECT B.SAL FROM EMP  B
            WHERE A.MGR=B.EMPNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
6>DISPLAY THOSE EMPLOYEES WHOSE JOB='MANAGER' 
       AND DO NOT HAVE SUBORDINATES
SQL>SELECT B.ENAME,COUNT(A.ENAME)
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
GROUP BY B.ENAME
HAVING COUNT(A.ENAME)<=0


------------------------------------------------------------------------------------------------------------------------------------------------------------------
7>DISPLAY THOSE EMPLOYEES WHOSE SALARY IS SAME AS THEIR MANAGER
        SALARY
SQL>SELECT A.ENAME,A.SAL
         FROM EMP A
            WHERE A.SAL=(SELECT B.SAL FROM EMP  B
            WHERE A.MGR=B.EMPNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
8>DISPLAY MANAGER WHOSE SALARY IS LESS THAN THEIR EMPLOYEES SALARY
SQL> SELECT A.ENAME,A.SAL
         FROM EMP A
            WHERE  A.EMPNO IN(SELECT B.MGR
                                               FROM EMP B
                                            WHERE A.SAL<B.SAL)

------------------------------------------------------------------------------------------------------------------------------------------------------------------


                                       JOINS QURIES
                                      -=-=-=-=-=-=-=-     
------------------------------------------------------------------------------------------------------------------------------------------------------------------
1>DISPLAY MANAGERS AND THEIR SALARY GRADES?
SQL>SELECT A.ENAME,A.SAL,G.GRADE
           FROM EMP A,SALGRADE G
          WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------
           AND A.JOB='MANAGER'

2>DISPLAY THE EMPLOYEES NAMES AND 
DEPT NAMES BUT SALARY SHOULD BE 2000 AND MORE?
SQL>SELECT A.ENAME,D.DNAME
            FROM EMP A,DEPT D
           WHERE A.DEPTNO=D.DEPTNO
            AND A.SAL >=2000
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THE EMPLOYEES NAMES AND 
DEPT NAMES BUT SALARY IS MORE THAN 2000?
SQL>SELECT A.ENAME,D.DNAME
        FROM EMP A,DEPT D
         WHERE A.DEPTNO=D.DEPTNO
         AND A.SAL >2000
------------------------------------------------------------------------------------------------------------------------------------------------------------------

4>DISPLAY EMPLOYEES NAMES WHOSE GRADE IS 3 AND THEIR JOB IS
    CLERCK OR SALESMAN?
SQL>SELECT A.ENAME,G.GRADE,A.JOB
         FROM EMP A,SALGRADE G
         WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
         AND G.GRADE=3 /
        AND (A.JOB='CLERCK' OR A.JOB='SALESMAN')

------------------------------------------------------------------------------------------------------------------------------------------------------------------
5>DISPALY THE EMPLOYEES NAME AND THEIR SALARY GRADE
SQL>SELECT A.ENAME,G.GRADE,A.JOB
         FROM EMP A,SALGRADE G
------------------------------------------------------------------------------------------------------------------------------------------------------------------
         WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL

6>DISPLAY THE EMPLOYEES NAME 
       AND THEIR MANAGERS NAME?
SQL>SELECT A.ENAME,B.ENAME
         FROM EMP A, EMP B
------------------------------------------------------------------------------------------------------------------------------------------------------------------
         WHERE A.MGR=B.EMPNO

7>DISPLAY THE EMPLOYEE AND MANAGERS NAMES AND       HIREDATES OF THOSE EMPLOYEES WHO JOINED BEFORE        THEIR MANAGER?
SQL>SELECT A.ENAME,B.ENAME,A.HIREDATE
        FROM EMP A, EMP B
       WHERE A.MGR=B.EMPNO
       AND A.HIREDATE<B.HIREDATE

------------------------------------------------------------------------------------------------------------------------------------------------------------------
                        GROUP BY
                      _-_-_-_-_-_-_
------------------------------------------------------------------------------------------------------------------------------------------------------------------
1>DISPLAY ALL THE DEPARTMENT NAMES AND TOTAL      SALARY PAID FOR EACH DEPT?
SQL>SELECT DEPTNO,SAL,COUNT(*)
           FROM EMP
          GROUP BY DEPTNO,SAL 
------------------------------------------------------------------------------------------------------------------------------------------------------------------
2>DISPLAY JOB AND TOTAL SALARY PAID FOR EACH JOB?
SQL>SELECT A.JOB,SUM(B.SAL)
FROM EMP A,EMP B
WHERE A.EMPNO=B.EMPNO
GROUP BY A.JOB
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY LOCATIONWISE AND JOB WISE TOTAL SALARY?
SQL>SELECT A.JOB,SUM(B.SAL)
FROM EMP A,EMP B
WHERE A.EMPNO=B.EMPNO
GROUP BY A.JOB
UNION
SELECT D.LOC,SUM(A.SAL)
FROM EMP A,DEPT D
WHERE A.DEPTNO=D.DEPTNO
GROUP BY D.LOC
------------------------------------------------------------------------------------------------------------------------------------------------------------------
4>DISPLAY THE NAMES OF MANAGER WITH TOTAL NO EMPLOYEES WORKING UNDER THEM?
SQL>SELECT B.ENAME,COUNT(A.ENAME)
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
GROUP BY B.ENAME
------------------------------------------------------------------------------------------------------------------------------------------------------------------

5>DISPLAY GRADES AND NO. OF EMPLOYEES AVAILABLE FOR EACH GRADE?
SQL>SELECT G.GRADE,COUNT(A.ENAME)
FROM EMP A,SALGRADE G
WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
GROUP BY G.GRADE
------------------------------------------------------------------------------------------------------------------------------------------------------------------
                    

                           HAVING CLAUSE
                        -_-_-_-_-_-_-_-_-_-_
1.DISPLAY MANAGERS WHO ARE HAVING THREE OR MORE 
   SUBORDINATE
SQL>SELECT B.ENAME,COUNT(A.ENAME)
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
GROUP BY B.ENAME
HAVING COUNT(A.ENAME)>3
------------------------------------------------------------------------------------------------------------------------------------------------------------------

2.DISPLAY DEPARTMENT WHICH PAYING MORE THAN 10000
    SALARIES PER MONTH  
SQL>DOUBTS
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THOSE GRADES FOR WHICH ATLEAST 2      EMPLOYEES ARE AVAILABLE?
SQL>SELECT G.GRADE,COUNT(A.ENAME)
       FROM EMP A,SALGRADE G
        WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
      GROUP BY G.GRADE
        HAVING COUNT(A.ENAME)>=2
 -----------------------------------------------------------------------------------------------------------------------------------------------------------------
4>DISPLAY THE DEPARTMENT  WHERE MAXIMUM NO OF     EMPLOYEES WORKING?
SQL>SELECT DEPTNO,COUNT(ENAME)
         FROM EMP
         GROUP BY DEPTNO


------------------------------------------------------------------------------------------------------------------------------------------------------------------

               OTHER QUERIES USING(GROUP BY/HAVING)
      ===================================
1>DISPLAY THE MANAGER NAMES AND TOTAL SALARY PAID      FOR EMPLOYEES UNDER THEM?
      SELECT B.ENAME,SUM(A.SAL)
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
GROUP BY B.ENAME 
------------------------------------------------------------------------------------------------------------------------------------------------------------------

2>DISPLAY THE GRADES AND TOTAL SALARY PAID FOR EACH GRADE?
SQL>SELECT G.GRADE,SUM(A.SAL)
FROM EMP A,SALGRADE G
WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
GROUP BY G.GRADE
------------------------------------------------------------------------------------------------------------------------------------------------------------------

3>DISPLAY EACH DEPT NAME AND NO OF EMPLOYEES    WORKING IN IT?
SQL>SELECT D.DNAME,COUNT(A.ENAME)
FROM EMP A ,DEPT D
WHERE A.DEPTNO=D.DEPTNO
GROUP BY D.DNAME
------------------------------------------------------------------------------------------------------------------------------------------------------------------

4>DISPLAY EACH JOB CATAGORY AND NO OF EMPLOYEE    WORKING FOR IT?
SQL>SELECT A.JOB,COUNT(B.ENAME)
FROM EMP A,EMP B
WHERE A.EMPNO=B.EMPNO
GROUP BY A.JOB
------------------------------------------------------------------------------------------------------------------------------------------------------------------
5>DISPLAY MANAGERS WHO ARE MANAGERS FOR LEAST 
NO OF WMPLOYEES
SQL>SELECT B.ENAME,COUNT(A.EMPNO)
FROM EMP A,EMP B
WHERE B.EMPNO=A.MGR
GROUP BY B.ENAME
HAVING COUNT(A.EMPNO)>=(SELECT MAX(COUNT(A.EMPNO))
                                                     FROM EMP
                                                 GROUP BY B.ENAME )
------------------------------------------------------------------------------------------------------------------------------------------------------------------



7.>  DISPLAY THE DEPT WHERE MIN NO OF EMPLOYEES               WORKING?
SQL>SELECT DEPTNO,COUNT(EMPNO)
FROM EMP
GROUP BY DEPTNO          
HAVING COUNT(EMPNO)>=(SELECT MAX(COUNT(EMPNO)) FROM EMP
GROUP BY DEPTNO)
------------------------------------------------------------------------------------------------------------------------------------------------------------------



                         SET OPERATORS                        -------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------
1>  DISPLAY THOSE WHO ARE EMPLOYEES  AS WELL AS   MANAGERS?
SQL>SELECT ENAME,JOB
FROM EMP
INTERSECT 
SELECT ENAME,JOB
FROM EMP WHERE JOB='MANAGER'
------------------------------------------------------------------------------------------------------------------------------------------------------------------
2>DISPLAY THOSE WHO ARE NOT MANAGER?
SQL>SELECT ENAME 
FROM EMP
MINUS
SELECT ENAME FROM EMP
WHERE JOB NOT IN'MANAGER' 

------------------------------------------------------------------------------------------------------------------------------------------------------------------



3>DISPLAY THOSE DEPT WHICH DONOT HAVE EMPLOYEES?
SQL>SELECT DEPTNO FROM DEPT
MINUS 
SELECT D.DEPTNO
FROM EMP A,DEPT D
WHERE A.DEPTNO=D.DEPTNO
------------------------------------------------------------------------------------------------------------------------------------------------------------------


4>3>DISPLAY THOSE DEPT WHICH  HAVE EMPLOYEES?
SQL>SELECT DEPTNO FROM DEPT
INTERSECT 
SELECT D.DEPTNO
FROM EMP A,DEPT D
WHERE A.DEPTNO=D.DEPTNO
------------------------------------------------------------------------------------------------------------------------------------------------------------------

5>FIND NO. OF ALL RECORDS FROM ALL THE TABLE?
SQL>SELECT 'EMP'EMP,COUNT(*)RECORD
FROM EMP
UNION
SELECT 'DEPT'DEPT,COUNT(*)RECORD
FROM DEPT
UNION
SELECT 'SALGRADE'SALGRADE,COUNT(*)RECORD
FROM SALGRADE
------------------------------------------------------------------------------------------------------------------------------------------------------------------

                          FUNCTION-BASED QUERIES------------------------------------------------------------------------------------------------------------------------------------------------------------------
1>DISPLAY THOSE EMPLOYEES WHO JOINED IN THE YEAR     82 AND 83
SQL>SELECT ENAME,HIREDATE,JOB
         FROM EMP
         WHERE (SUBSTR(HIREDATE,8,2)=82 OR          SUBSTR(HIREDATE,8,2)=83)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
2>DISPLAY THOSE EMPLOYEES WHO JOINED IN FIRST HALF OF ANY MONTH?
SQL>SELECT ENAME,HIREDATE,JOB
FROM EMP
WHERE SUBSTR(HIREDATE,1,2) BETWEEN 1 AND 15
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THOSE EMPLOYEES WHOSE NAME AND THIER MANAGER NAME START WITH SAME CHARACTER?
SQL>SELECT B.ENAME,A.ENAME
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
AND ASCII(B.ENAME)=ASCII(A.ENAME)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
4>DISPLAY THOSE EMPLOYEES WHOSE NAME AND JOB    COLOUMNS HAVING SAME NUMBER OF CHARACTERS?
SQL>SELECT ENAME,JOB FROM EMP
         WHERE LENGTH(ENAME)=LENGTH(JOB)
------------------------------------------------------------------------------------------------------------------------------------------------------------------
          
                              #USING DATE AND AGGREGATE FUNCTIONS------------------------------------------------------------------------------------------------------------------------------------------------------------------
1>DISPLAY THOSE EMPLOYEES WHO JOINED THE COMPANY 
   20 OR MORE BEFORE?
SQL>SELECT EMPNO,ENAME,JOB,HIREDATE
        FROM EMP
    WHERE MONTHS_BETWEEN(SYSDATE,HIREDATE)/12>=20
------------------------------------------------------------------------------------------------------------------------------------------------------------------

2>DISPLAY THE LAST DAY OF FEB 2001?
SQL>SELECT LAST_DAY('01-FEB-01')
FROM DUAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THE DATE ON FIRST MONDAY OF JAN 2001:
SQL>SELECT NEXT_DAY('31-DEC-00','MON')
FROM DUAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------

4>DISPLAY THE CURRENT TIME?
SQL>SELECT SYSDATE,TO_CHAR(SYSDATE,'HH:MI:SS') AS TIME
FROM DUAL
                                                                                                                                                                                           
------------------------------------------------------------------------------------------------------------------------------------------------------------------
5>DISPLAY HTE CURRENT YEAR?
SQL>SELECT SYSDATE,TO_CHAR(SYSDATE,'FMYYYY')AS YEAR 
FROM DUAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------

7>DISPLAY THE NET SALARY PAID TO EACH EMPLOYEE?
SQL>SELECT ENAME,SAL+NVL(COMM,0) 
FROM EMP
------------------------------------------------------------------------------------------------------------------------------------------------------------------
8>SHOW 10% INCENTIVES FOR EACH EMPLOYEE ONSALARY OR COMM WHICH EVER IS GREATER?
SQL>SELECT ENAME,SAL,COMM,GREATEST(SAL,NVL(COMM,0))*.01
FROM EMP
GROUP BY ENAME,SAL,COMM
------------------------------------------------------------------------------------------------------------------------------------------------------------------
9>SHOW THE CURRENT USER NAME?
SQL>SELECT USER FROM DUAL
------------------------------------------------------------------------------------------------------------------------------------------------------------------
1
0>DISPLAY THE 3rd HIGHEST PAID EMPLOYEE?
SQL>SELECT ROWNUM,ENAME,SAL
FROM(SELECT DISTINCT SAL,ENAME FROM EMP
                ORDER BY SAL DESC)
GROUP BY ROWNUM,ENAME,SAL
HAVING ROWNUM=3
------------------------------------------------------------------------------------------------------------------------------------------------------------------
11>DISPLAY THE MANAGER UNDER WHICH 5 PERSON ARE WORKING WHO GETTING SALARY>=5000?
SQL>SELECT B.ENAME,COUNT(A.ENAME),B.SAL
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
AND B.SAL>=5000
GROUP BY B.ENAME,B.SAL
HAVING COUNT(*)<=5
------------------------------------------------------------------------------------------------------------------------------------------------------------------
12>DISPLAY THOSE EMPLOYEE WHO HAVE JOINED THE COMPANY IN THE MONTH OF JAN?
SQL>SELECT ENAME,HIREDATE
FROM EMP
WHERE SUBSTR(HIREDATE,4,3)='JAN'
------------------------------------------------------------------------------------------------------------------------------------------------------------------
13>DISPLAY THE MANAGERS HAVING MORE THAN 3      EMPLOYEES UNDER THEM?
SQL>SELECT B.ENAME,COUNT(A.ENAME)
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
GROUP BY B.ENAME
HAVING COUNT(A.ENAME)>=3
------------------------------------------------------------------------------------------------------------------------------------------------------------------
14>DISPLAY DEPARTMENT LOCATION WITHOT ANY SPACE?
SQL>SELECT REPLACE(LOC,' ','')
FROM DEPT
------------------------------------------------------------------------------------------------------------------------------------------------------------------
15>DISPLAY THOSE EMPLOYEES WHO ARE WORKING UNDER THOSE MANAGER WHO ARE IN SALES DEPARTMENT?
SQL>SELECT A.ENAME,B.ENAME,D.DNAME
FROM EMP A,EMP B,DEPT D
WHERE A.MGR=B.EMPNO
AND B.DEPTNO=D.DEPTNO
AND D.DNAME='SALES'
------------------------------------------------------------------------------------------------------------------------------------------------------------------

                   #SUB QURIES                    =-=-=-=-=-=-=-
------------------------------------------------------------------------------------------------------------------------------------------------------------------
1>DISPLAY THOSE EMPLOYEES WHOSE DEPT IS SALES?
SQL>SELECT A.ENAME,D.DNAME
FROM EMP A,DEPT D
WHERE A.DEPTNO=D.DEPTNO
AND D.DNAME='SALES'
------------------------------------------------------------------------------------------------------------------------------------------------------------------
2>DISPLAY THOSE EMPLOYEE WHOSE GRADE IS 3?
SQL>SELECT A.ENAME,G.GRADE
FROM EMP A,SALGRADE G
WHERE A.SAL BETWEEN G.LOSAL AND G.HISAL
AND G.GRADE=3
------------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THOSE EMPLOYEES WHOSE DEPARTMENT IS SALES OR ACCOUNTING?
SQL>SELECT A.ENAME,D.DNAME
FROM EMP A,DEPT D
WHERE A.DEPTNO=D.DEPTNO
AND (D.DNAME='SALES' OR D.DNAME='ACCOUNTING')
------------------------------------------------------------------------------------------------------------------------------------------------------------------
4>DISPLAY THOSE EMPLOYEES WHO ARE IN BOSTON DEPT
SQL>SELECT  A.ENAME,D.LOC
FROM EMP A,DEPT D
WHERE A.DEPTNO=D.DEPTNO
AND D.LOC='BOSTON'
------------------------------------------------------------------------------------------------------------------------------------------------------------------
5>DISPLAY THOSE EMPLOYEES WHOSE NAME START WITH      'J' AND HIS DEPT ENDS WITH 'S'?
SQL>SELECT A.ENAME,D.DNAME
        FROM EMP A, DEPT D
            WHERE A.DEPTNO=D.DEPTNO
         AND (ENAME LIKE 'J%'    AND
           D.DNAME LIKE '%S')
------------------------------------------------------------------------------------------------------------------------------------------------------------------
6>DISPLAY THOSE EMPLOYEES WHO ARE WORKING WNDER KING?
SQL>SELECT A.ENAME,B.ENAME
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
AND B.ENAME='KING'
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
7>DISPLAY THOSE EMPLOYEES WHO ARE WORKING INDER 
     JONES AND CLARK?
SQL>SELECT A.ENAME,B.ENAME
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
AND (B.ENAME='JONES' OR B.ENAME='CLARK')
------------------------------------------------------------------------------------------------------------------------------------------------------------------
8>DISPLAY THOSE EMPLOYEES WHOSE MANAGER JOINED IN THE YEAR ie 81
SQL>SELECT A.ENAME,B.ENAME,B.HIREDATE
FROM EMP A,EMP B
WHERE A.MGR=B.EMPNO
AND  SUBSTR(B.HIREDATE,8,2)=81
/

------------------------------------------------------------------------------------------------------------------------------------------------------------------

Hierarchical queries


-----------------------------------------------------------------------------------------------------------------------------------------------------------------
1>DISPLAY ALL EMPLOYEES IN TREE WALK STYLE?
SQL>SELECT LPAD(' ',LEVEL*3,' ')||ENAME
FROM EMP
START WITH MGR IS NULL
CONNECT BY PRIOR EMPNO=MGR
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
2>DISPLAY THE EMPLOYEE IN HIEARCHY STARTING FROM        JONES?
SQL>SELECT LPAD(' ',LEVEL*3,' ')||ENAME
FROM EMP
START WITH ENAME='JONES'
CONNECT BY PRIOR EMPNO=MGR
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
3>DISPLAY THE TOTAL NO. OF EMPLOYEES WORKING IN COMPLETE HIERARCHY  UNDER THE  JONES?
SQL>

------------------------------------------------------------------------------------------------------------------------------------------------------------------
4>DISPLAY LAST LEVEL EMPLOYEE?
SQL>SELECT LEVEL,ENAME
FROM EMP
WHERE LEVEL=(SELECT MAX(LEVEL) FROM EMP
START WITH MGR IS NULL
CONNECT BY PRIOR EMPNO=MGR)
START WITH MGR IS NULL
CONNECT BY PRIOR EMPNO=MGR
------------------------------------------------------------------------------------------------------------------------------------------------------------------
5>DISPLAY THOSE EMPLOYEES WHOSE LEVEL HIEARACHY IS      ODD?
SQL>SELECT LEVEL,ENAME
FROM EMP
WHERE MOD(LEVEL,2)=1
START WITH MGR IS NULL
CONNECT BY PRIOR EMPNO=MGR
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
6>DISPLAY THE 2nd LEVEL EMPLOYEE
SQL>SELECT LEVEL,ENAME,JOB,SAL
FROM EMP
WHERE LEVEL=2
START WITH MGR IS NULL
CONNECT BY PRIOR EMPNO=MGR
-----------------------------------------------------------------------------------------------------------------------------------------------------------------

7>DISPLAY TOTAL SALARY PAID UNDER BLAKE?
SQL>SELECT B.ENAME,SUM(A.SAL)
FROM EMP A, EMP B
WHERE A.MGR=B.EMPNO
GROUP BY B.ENAME
HAVING B.ENAME=(SELECT B.ENAME
                            FROM EMP B
                           WHERE ENAME='BLAKE')
------------------------------------------------------------------------------------------------------------------------------------------------------------------
8>DISPLAY HOW MANY NO OF EMPLOYEES ARE PRESENT AT
LEVEL NO OF 3?
SQL>SELECT LEVEL,  COUNT(*)
FROM EMP
WHERE LEVEL=3
GROUP BY LEVEL
START WITH MGR IS NULL
CONNECT BY PRIOR EMPNO=MGR
--------------------------------------------------------------------------------