0% found this document useful (0 votes)
58 views10 pages

Database System: Task 1

The document contains 20 tasks involving SQL queries on database tables. The tasks include queries to display dates, extract parts of strings, perform calculations on dates and numbers, format outputs, and modify table values. Sample queries select, filter, concatenate, convert, calculate, and transform date, string, and number values from tables. The tasks cover a range of basic to more advanced SQL functions and operations.

Uploaded by

Abdulrab Chatha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views10 pages

Database System: Task 1

The document contains 20 tasks involving SQL queries on database tables. The tasks include queries to display dates, extract parts of strings, perform calculations on dates and numbers, format outputs, and modify table values. Sample queries select, filter, concatenate, convert, calculate, and transform date, string, and number values from tables. The tasks cover a range of basic to more advanced SQL functions and operations.

Uploaded by

Abdulrab Chatha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

DATABASE SYSTEM

TASK 1

Display the date of your coming lab which will be on next Thursday. Don’t use any date in
query.

Query:

SELECT NEXT_DAY (SYSDATE, 'THURSDAY') AS "NEXT LAB DATE" FROM DUAL

TASK 2

Find position of ‘a’ in the names of all employees and print it with names.
Output will be like (SMITH0 ,WARD2).
QUERY:
SELECT ENAME ,CONCAT(ENAME, INSTR(ENAME, 'A')) AS "POSITION OF A" FROM EMP

TASK 3

Print names and position 3 to position 5 of the names of all employees.


QUERY:
SELECT ENAME, SUBSTR(ENAME, 3, 5) FROM EMP;
SCRENNSHOT:

TASK 4

Print a column name as “employees with my roll no” (print your own roll no.), in second column
print the length of this string.
Sample output
(SMITH’s roll no is BITF9a123)
QUERY:
SELECT ENAME ||'''s roll no is BITF19A036' AS "EMPLOYEES WITH ROLL NO",
LENGTH(ENAME ||'''s roll no is BITF19A036') FROM EMP;

TASK 5

Display salary, commission and total salary (salary + commission) in the format of *****20000.
QUERY:
SELECT SAL, COMM, LPAD(SAL+ NVL(COMM,0), 10, '*') AS "TOTAL SALARY" FROM EMP;

TASK 6
Print no. of weeks of all employees when he joined the company from today
QUERY:
SELECT ENAME, HIREDATE, SYSDATE AS "TODAY DATE",
TRUNC((SYSDATE - HIREDATE)/7) AS "WEEKS EMPLOYED" FROM EMP;
SCREEN SHOT:

TASK 7

Add 30 days in hire date of each employee and display both dates
QUERY:
SELECT HIREDATE, (HIREDATE + 30) FROM EMP;

TASK 8

Display salary, salary/4 and mod of salary by salary/4.


QUERY:
SELECT SAL, SAL/4, MOD(SAL,SAL/4) AS "MOD OF SAL" FROM EMP;

TASK 9

Display salaries of employees divided by 4 and round them to 1 decimal place.


QUERY:
SELECT SAL, SAL/4,
ROUND(SAL/4,1) AS "ROUND OF SAL/4 BY 1" FROM EMP;
TASK 10

Use a number function to get first date of current year and month.
QUERY:
SELECT TRUNC(SYSDATE, 'MONTH') AS "FIRST DATE" FROM DUAL;
SCRENNSHOT:

TASK 11

Write any 7 digit number in the following format.


2,222,222
9,345,123
QUERY:
SELECT TO_CHAR(1234567, '9,999,999') AS "7- DIGIT NUMBER" FROM DUAL;
TASK 12

In the string BITF19AXXX, change XXX with your roll number as BITF19A001.

QUERY:

SELECT REPLACE('BITF19AXXX','XXX','036') AS "ROLL NO" FROM DUAL;

TASK 13
Display data of all the employees where last three characters of job is man.

Use “man” in your search not “MAN”.

QUERY:

SELECT * FROM EMP

WHERE SUBSTR(JOB, -3) = UPPER('man');

TASK 14

Use a number function to change 345678.4567 to 345700


QUERY:
SELECT ROUND(345678.4567, -2) AS "ROUND OFF" FROM DUAL
TASK 15

Use a number function to change 345678.4567 to 340000


QUERY:
SELECT TRUNC(345678.4567, -4) AS "ROUND OFF" FROM DUAL;

TASK 16

Display hiredate and hiredate – X. (X = digit in your roll no (e.g BITF19A050 X=50)). And display
both dates as full names of day,month and year.
QUERY:
SELECT TO_CHAR(HIREDATE, 'DAY, DD MONTH, YYYY') AS "HIRE DATE",
TO_CHAR(HIREDATE - (SUBSTR ('BITF19A036', -3)), 'DAY, DD MONTH, YYYY') AS "NEW DATE"
FROM EMP;

TASK 17

Print names and “modified names” (put B instead of L in each name) in lower case.

QUERY:

SELECT ENAME, LOWER(REPLACE(ENAME,'L', 'B')) AS "MODIFIED NAME" FROM EMP;

TASK 18

Display name and hire date of every employee in the format of “ Wednesday, 17 December , 1980” and label
that column as Joining Date and also display current date in same format in 3 rd column.

QUERY:

SELECT ENAME,

TO_CHAR(HIREDATE, 'DAY, DD MONTH , YYYY') AS "JOINING DATE",

TO_CHAR(SYSDATE, 'DAY, DD MONTH , YYYY') AS "CURRENT DATE"

FROM EMP;

TASK 19

Print ename with your name of all employees

Your name in a column starting ending with X no of ‘#’. (use padding) (X = digit in your roll no (e.g X=20))

Sample Output

X=5

SMITH arslan#####
ALLEN arslan#####

WARD arslan#####

QUERY:

SELECT ENAME,

RPAD(ali, 8 + SUBSTR('6', -3), '#') AS "MY NAME"

FROM EMP;

TASK 20

Add 3600 minutes in hire date of each employee and display both dates

QUERY:

SELECT HIREDATE,
HIREDATE + 2.5 AS "NEW DATE"
FROM EMP;

Good Luck 😊

You might also like