0% found this document useful (0 votes)
6 views

Lab Task 4

Uploaded by

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

Lab Task 4

Uploaded by

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

NATIONAL UNIVERSITY OF MODERN LANGUAGES

Faisalabad Campus

Saqlain Mahmood - FC 182


BSCS-5th – Lab Task-4

Database Systems
(Ms. Ayesha Ayub)

Topic:
“Using single-row character functions to customize output, use of
NVL function”
Lab Task 4

Q1:
Solve the Task
Answer:
Functions like UPPER() and LOWER() allow for converting strings to uppercase or lowercase,
respectively, making it easier to standardize data formats. The TRIM() function is crucial for
removing unwanted spaces from the beginning and end of strings, ensuring clean data
entries. Meanwhile, SUBSTR() and INSTR() enable users to extract specific substrings and
find the position of substrings within strings, providing greater control over string handling.
The CONCAT() function is used to join multiple strings into a single output, facilitating the
creation of full names or combined data fields. Additionally, RPAD() can be employed to
right-pad strings to a specified length, enhancing visual alignment in outputs.
Code of the above mentions Function:
create database ram;
use ram;
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100),
salary DECIMAL(10, 2),
hire_date DATE
);

INSERT INTO employees (employee_id, first_name, last_name, email, salary, hire_date)


VALUES (1, 'Raheem', 'Mahmood', '[email protected]', 5500.75, '2022-01-15');
INSERT INTO employees (employee_id, first_name, last_name, email, salary, hire_date)
VALUES (2, 'Faheem', 'Mahmood', NULL, 6300.00, '2021-05-25');
INSERT INTO employees (employee_id, first_name, last_name, email, salary, hire_date)
VALUES (3, 'Nadeem', 'Mahmood', '[email protected]', 4800.55, '2023-02-10');
INSERT INTO employees (employee_id, first_name, last_name, email, salary, hire_date)
VALUES (4, NULL, 'Kaleem', NULL, 7000.20, '2020-07-05');

SELECT
employee_id,
CONCAT(UPPER(IFNULL(first_name, 'Unknown')), ' ', UPPER(IFNULL(last_name,
'Unknown'))) AS full_name
FROM
employees;
SELECT employee_id,first_name,salary,MOD(salary, 1000) AS salary_modulo FROM
employees;
SELECT employee_id,first_name,salary,TRUNCATE(salary, 0) AS truncated_salary FROM
employees;
SELECT employee_id,first_name,salary,ROUND(salary, 1) AS rounded_salary FROM
employees;
SELECT employee_id,first_name,email,INSTR(email, '@') AS at_position FROM employees;
SELECT employee_id,first_name,email,RPAD(IFNULL(email, 'No Email Available'), 30, '*') AS
padded_email FROM employees;
SELECT employee_id,TRIM(IFNULL(first_name, 'Unknown')) AS
trimmed_first_name,TRIM(IFNULL(last_name, 'Unknown')) AS trimmed_last_name FROM
employees;
SELECT
employee_id,
LOWER(email) AS lowercase_email
FROM
employees;

Screenshot of the output:

You might also like