• Tidak ada hasil yang ditemukan

INITCAP(DEPT_NAME) FROM EMPLOYEE ORDER BY SALARY

N/A
N/A
Protected

Academic year: 2019

Membagikan "INITCAP(DEPT_NAME) FROM EMPLOYEE ORDER BY SALARY"

Copied!
6
0
0

Teks penuh

(1)

Herewith I am giving solutions to few questions ( you can write these

programs using different ways); similarly you can try for remaining

solutions by your own.

Note: - If you need any other solution, contact me personally.

1) I) Create the following Employee table & insert into it 5 Records EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, DEPT NAME) Write SQL Queries to a) Delete a record with some DOJ.

b) Update salary of employee who is earning less than 10,000 by 10%.

Ans :- UPDATE EMPLOYEE SET SALARY = SALARY * 1.10 WHERE SALARY<10000

c) Display Name (Capitals), Address (Capitalization) & Dept name (Capitalization) Employee records according to their salary (Less Salary first).

Ans :- SELECT UPPER(NAME), INITCAP(ADDRESS), INITCAP(DEPT_NAME) FROM EMPLOYEE ORDER BY SALARY

II) Write PL/SQL Program to find whether the given number is Palindrome number or not?

2) I) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, COMPANY NAME)

Write SQL Queries to a) Delete a record with some name. b) Update address of some employee by using SSN. c) Display Name (Capitals), Address (Capitalization) & Dept name (Capitalization) Employee records according to their Name (Alphabetical order).

Ans :- SELECT UPPER(NAME), INITCAP(ADDRESS), INITCAP(DEPT_NAME) FROM EMPLOYEE ORDER BY NAME

II) To find largest of three numbers using IF-ELSIF. DECLARE

A NUMBER := &A; B NUMBER := &B; C NUMBER := &C; BEGIN

IF (A > B AND A > C) THEN

DBMS_OUTPUT.PUT_LINE('BIGGEST IS ' || A); ELSIF (B > C) THEN

DBMS_OUTPUT.PUT_LINE('BIGGEST IS ' || B); ELSE

DBMS_OUTPUT.PUT_LINE('BIGGEST IS ' || C); END IF;

END; /

3) I) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, COMPANY NAME)

Write SQL Queries to a) Add column Mobile number & E-Mail ID. b) Remove column Salary. c) Display Employee records according to Names (Capitalize & Alphabetical order).

II) Write PL/SQL Program to display Fibonacci series. DECLARE

A NUMBER:=0; B NUMBER:=1; C NUMBER; I NUMBER:=1; BEGIN

(2)

C:=A+B;

DBMS_OUTPUT.PUT_LINE(C); A:=B;

B:=C; I:=I+1; END LOOP; END;

/

4) I) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, COMPANY NAME)

Write SQL Queries to a) Delete record with some name. b) Update Name of some female employee. c) Display Employee name along with experience (No of years) in the company.

Ans :- SELECT NAME, MONTHS_BETWEEN (SYSDATE, DOJ)/12 FROM EMPLOYEE II) Display an employee details by reading SSN from keyboard.

DECLARE

SSN VARCHAR2(10); NAME VARCHAR2(30); SALARY NUMBER(10,2); DOJ DATE;

BEGIN

SELECT SID, NAME, SALARY, DOJ INTO SID, NAME, SALARY, DOJ FROM FACULTY WHERE SID='&SID';

DBMS_OUTPUT.PUT_LINE(SID || ' '|| NAME || ' '|| SALARY ||' '|| DOJ ); END;

/

5) I) Create the following table & insert 5 records into table. STUDENT (SID, SNAME, DOB, MARKS) Write a query to

a) Find the names of students who have scored more than 20 marks using Exists clause. b) Find the names of students whose marks are better than some students called Pavan using ANY Clause.

II) Write PL/SQL program to check the given number is prime numbers or not. DECLARE

A NUMBER:=&A; B BOOLEAN:=FALSE; I NUMBER;

C NUMBER; BEGIN I:=A/2; C:=2;

WHILE(C<=I) LOOP IF(MOD(A,C)= 0) THEN B:=TRUE;

END IF; C:=C+1; END LOOP;

IF(B!=FALSE) THEN

DBMS_OUTPUT.PUT_LINE(A||' IS NOT A PRIME'); ELSE

DBMS_OUTPUT.PUT_LINE(A||' IS A PRIME'); END IF;

(3)

6) I) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, COMPANY NAME) Write SQL Queries to a) Find highest & lowest Salary of Employees.

Ans :- SELECT MAXIMUM(SALARY), MINIMUM(SALARY) FROM EMPLOYEE

b) Gross & Average Salary according to Company (Company Name & Gross Salary for the company) using Group By clause.

Ans :- SELECT COMPANY_NAME, SUM(SALARY), AVERAGE(SALARY) FROM EMPLOYEE GROUP BY COMPANY_NAME

II) Write a PL/SQL program to insert record into Employee table. Handle the Exceptions.

DECLARE

SSN NUMBER (5):=&SSN;

NAME VARCHAR2(30):='&NAME';

Similarly declare all variables.

BEGIN

INSERT INTO SAILORS VALUES(SSN, NAME, <REMAINING VALUES>);

END;

/

7) I) Create the following table & insert 5 records into table. STUDENT (SID, FNAME, LNAME, DOB, MARKS)

Write queries to display records with a) Concatenation of FNAME & LNAME. b) Left padding FNAME with ‘*’ and right padding LNAME with ‘#’.

Ans :- SELECT LPAD(FNAME,30,’*’), RPAD(LNAME,30,’#’) FROM STUDENT c) Remove characters from left if they are starting with P & from right if they are ending with A.

Ans :- SELECT LTRIM(RTRIM(FNAME,’A’),’P’) FROM STUDENT d) Display FNAME in Capitals and LNAME in lower case along with DOB & Marks.

Ans :- SELECT UPPER(FNAME), LOWER(LNAME), DOB, MARKS FROM STUDENT e) Display FNAME & LNAME with first letter capital.

Ans :- SELECT INITCAP(FNAME), INITCAP (LNAME) FROM STUDENT II) Write PL/SQL program to check whether the given string is palindrome or not

DECLARE

LEN NUMBER;

S1 VARCHAR2(20) := '&S1';

S2 VARCHAR2(20);

BEGIN

LEN := LENGTH(S1);

FOR I IN REVERSE 1..LEN LOOP

S2 := S2||SUBSTR(S1,I,1);

END LOOP;

IF S2= S1 THEN

DBMS_OUTPUT.PUT_LINE('GIVEN STRING '||S1||' IS A PALINDROME');

ELSE

DBMS_OUTPUT.PUT_LINE('GIVEN STRING '||S1||' IS NOT A PALINDROME');

END IF;

END;

/

OR

S1 VARCHAR2(20);

(4)

BEGIN

S1:='&S1';

SELECT REVERSE(S1) INTO S2 FROM DUAL;

IF S1=S2 THEN

DBMS_OUTPUT.PUT_LINE('GIVEN STRING IS PALINDROME');

ELSE

DBMS_OUTPUT.PUT_LINE('GIVEN STRING IS NOT PALINDROME');

END IF;

END;

/

8) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, DEPT NAME)

Write SQL Queries to a) Delete a record with some DEPT NAME. b) Update salary of employee who earns more than 15000 by 10%. c) Display Show Name (Capitals), Address (Capitalization) & Dept (Capitalization) of Employee records according to their salary (Lowest salary first).

II) Write PL/SQL Program to find whether the given number is Palindrome number or not?

DECLARE

N NUMBER(3);

I NUMBER(3);

SUM1 NUMBER(3);

K NUMBER(3);

BEGIN

SUM1:=0;

N:=&N;

K:=N;

WHILE (N>0) LOOP

I:=MOD(N,10);

SUM1:=(SUM1*10)+I;

N:=TRUNC(N/10);

END LOOP;

IF(K=SUM1) THEN

DBMS_OUTPUT.PUT_LINE('GIVEN NUMBER IS A PALINDROME NUMBER');

ELSE

DBMS_OUTPUT.PUT_LINE('GIVEN NUMBER IS NOT A PALINDROME NUMBER');

END IF;

END;

/

9) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, DEPT NAME)

Write SQL Queries to a) Delete a record with some SSN. b) Update salary of some employee who works for IT dept by 15%. c) Display Show Name (Capitals), Address (Capitalization) & Dept (Capitalization) of Employee records according to their salary (Highest salary first).

II) Define appropriate PL/SQL block to illustrate RAISE_APPLICATION_ERROR

DECLARE

(5)

IF(B=0)THEN

RAISE_APPLICATION_ERROR(-20001,'DIVISION BY ZERO');

ELSE

C:=A/B;

DBMS_OUTPUT.PUT_LINE('RESULT IS :'||C);

END IF;

END;

/

10) I) Create the following table & insert 5 records into table. STUDENT (SID, FNAME, LNAME, DOB, MARKS) Execute the following using Conversion & Date functions. a) Show the age of student as on today.

Ans :- SELECT MONTHS_BETWEEN (SYSDATE, DOB)/12 FROM STUDENT b) Show date of birth after 20 Yrs from DOB.

Ans :- SELECT ADD_MONTHS (DOB, 240) FROM STUDENT c) Show today’s date in the format like Monday 4 April 2011

II) Write a PL/SQL to find the roots of a quadratic equation. DECLARE

A INTEGER:=&A; B INTEGER:=&B; C INTEGER:=&C; R1 NUMBER(5,2); R2 NUMBER(5,2); X NUMBER(5,2); BEGIN

IF(B*B>=4*A*C) THEN

R1:=(-B+SQRT(B*B-4*A*C))/2*A; R2:=(-B-SQRT(B*B-4*A*C))/2*A;

DBMS_OUTPUT.PUT_LINE('ROOTS ARE REAL'||R1||' '||R2); ELSE

X:=(SQRT(-(B*B-4*A*C)))/2*A; R1:=-B/2*A;

DBMS_OUTPUT.PUT_LINE('ROOTS ARE IMAGINARY'||R1||'+i'||X||' '||R1||'-i'||X); END IF;

END; /

11) I) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, COMPANY NAME)

Write SQL Queries to a) Add column Mobile number & E-Mail ID. b) Remove column Salary. c) Add some constraint (like salary should not less that 10,000 & more than 50,000).

II) Write PL/SQL Program to find whether the given number is Palindrome number or not?

12) I) Create the following Student & Marks tables & insert into it 5 Records STUDENT(SID, NAME, DEPT, CLASS)

MARKS(SID, MID, QUIZ)

Show the Foreign Key constraint. Write SQL queries to delete a record, update a record in student & marks table. Write SQL queries to display student details along with marks they scored. (Show Name in UPPERCASE & DEPT by Capitalized).

Ans :- CREATE TABLE STUDENT (SID VARCHAR2(10), NAME VARCHAR2(30), DEPT VARCHAR2(20), CLASS VARCHAR2(10), PRIMARY KEY(SID))

(6)

SELECT S.SID, UPPER(NAME), INITCAP(DEPT), CLASS, MID, QUIZ FROM STUDENT S, MARKS M WHERE S.SID=M.SID

II) Define appropriate PL/SQL block to illustrate RAISE_APPLICATION_ERROR

13) I) Create the following Student & Marks tables & insert into it 5 Records STUDENT(SID, NAME, DEPT, CLASS)

MARKS(SID, MID, QUIZ)

Show the Foreign Key constraint. Write SQL queries to delete a record, update a record in student & marks table. Write SQL queries to display student details along with marks they scored. (Show Name in UPPERCASE & DEPT by Capitalized).

II) Define appropriate PL/SQL block to illustrate RAISE_APPLICATION_ERROR

14) I) Create the following Employee table & insert into it 5 Records EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, DEPT NAME)

Write SQL Queries to a) Delete a record with some DOJ. b) Update salary of employee who is earning less than 10,000 by 10%. c) Display Name(Capitals), Address (Capitalization) & Dept name (Capitalization) Employee records according to their salary (Less Salary first).

II) Write PL/SQL Program to find whether the given number is Palindrome number or not?

15) I) Create the following Employee table & insert into it 5 Records

EMPLOYEE (NAME, SSN, ADDRESS, SALARY, DOJ, COMPANY NAME)

Write SQL Queries to a) Delete a record with some name. b) Update address of some employee by using SSN. c) Display Name (Capitals), Address (Capitalization) & Dept name (Capitalization) Employee records according to their Name (Alphabetical order).

II) To find largest of three numbers using IF-ELSIF.

Extra:- Write a Pl/Sql program to check the given number is Armstrong ‘or’ not.

DECLARE

N NUMBER(3);

S NUMBER(3):=0;

T NUMBER(3);

BEGIN

N:=&N;

T:=N;

WHILE T>0 LOOP

S:=S+POWER((T MOD 10),3);

T:=TRUNC(T/10);

END LOOP;

IF(S=N) THEN

DBMS_OUTPUT.PUT_LINE('THE GIVEN NUMBER ' || N || 'IS AN ARMSTRONG

NUMBER');

ELSE

DBMS_OUTPUT.PUT_LINE('THE GIVEN NUMBER ' || N || 'IS NOT AN ARMSTRONG

NUMBER');

Referensi

Dokumen terkait