You are on page 1of 58

Aakar Gupta(19BCE0379)

CYCLE SHEET – 2

DDL statements (ALTER, CONSTRAINT etc):


Q1. Modify Hospital_Bill by adding an attribute consulting_physician and add foreign
key constraint for that attribute. Use constraint name for foreign key constraint.
CODE:
ALTER TABLE hospital_bill
ADD consulting_physician varchar2(5);
ALTER TABLE hospital_bill
ADD CONSTRAINT FK_ConsultPhysician
FOREIGN KEY (consulting_physician) REFERENCES Doctor(Doc_ID);
Aakar Gupta(19BCE0379)

Q2. In Patient table, replace address with three attributes namely street, city and
pincode.
CODE:
ALTER TABLE patient
Aakar Gupta(19BCE0379)

DROP COLUMN address;


ALTER TABLE patient
ADD (street VARCHAR2(50),
city VARCHAR2(50),
pincode NUMBER(6));
Aakar Gupta(19BCE0379)

Q3. Add an attribute Test_Time which can accept only two values “Before food” and
“After food” with proper constraint name.
CODE:
ALTER table lab_tests
ADD Test_Time VARCHAR2(20);
ALTER table lab_tests
ADD CONSTRAINT CheckTest
CHECK (Test_Time in ('Before food','After food'));
Aakar Gupta(19BCE0379)
Aakar Gupta(19BCE0379)

Q4. Remove the constraint only from test_time attribute.


CODE:
ALTER TABLE lab_tests
DROP CONSTRAINT CheckTest;
Aakar Gupta(19BCE0379)

Q5. Drop address attribute from staff table and add attributes door_no, street, city, and
pincode.
CODE:
ALTER TABLE staff
DROP COLUMN address;
ALTER TABLE Staff
ADD (door_no NUMBER(5),
Aakar Gupta(19BCE0379)

street VARCHAR2(50),
city VARCHAR2(50),
pincode NUMBER(6));
Aakar Gupta(19BCE0379)

Q6. Create a table Medicines with schema medicines=(med_name, brand, dosage,


manu_date, exp_date). Ensure that manu_date should not be later than exp_date.
Create an appropriate constraint to ensure this.
CODE:
CREATE TABLE Medicines(med_name VARCHAR2(100) PRIMARY KEY,
brand VARCHAR2(50) NOT NULL,
dosage varchar2(50) NOT NULL,
manu_date date NOT NULL,
exp_date date NOT NULL,
CHECK(manu_date<=exp_date));
Aakar Gupta(19BCE0379)
Aakar Gupta(19BCE0379)

INSERTING INTO MEDICINES TABLE


insert into Medicines values('Paracetamol', 'Ranbaxy', '2times/day', date '2020-07-01',
date '2021-07-01');
insert into Medicines values('Calpol', 'Lyrica', '1 time(s)/day', date '2019-02-19', date
'2022-03-19');
insert into Medicines values('Metformin', 'Cipla', '2 time(s)/day', date '2020-05-20', date
'2023-06-14');
insert into Medicines values('Acetaminophen', 'Ranbaxy', '3 time(s)/day', date '2020-04-
23', date '2022-02-21');
insert into Medicines values('Cefpodoxime', 'Ranbaxy', '1 time(s)/day', date '2020-01-
13', date '2024-03-11');
insert into Medicines values('Amoxicillin', 'Apollo', '3 time(s)/day', date '2019-02-21',
date '2021-03-21');
insert into Medicines values('Digene', 'Abbott', '2 time(s)/day', date '2020-04-25', date
'2021-06-27');
Aakar Gupta(19BCE0379)

Q7. Remove the attributes dosage and brand from Prescribed_Medicines and alter the
medicine_name attribute as a foreign key referencing the new table Medicines.
CODE:
ALTER TABLE prescribed_medicines
DROP (dosage,brand);
Aakar Gupta(19BCE0379)

ALTER TABLE prescribed_medicines


DISABLE CONSTRAINT PK_medicine_name;

ALTER TABLE prescribed_medicines


ADD CONSTRAINT FK_medicine_name
FOREIGN KEY(medicine_name) REFERENCES Medicines(med_name);
Aakar Gupta(19BCE0379)
Aakar Gupta(19BCE0379)

Q8. Create a view for doctors who are specialized in ‘Cardiology’ from Doctor table with
attributes doc_id, doc_name and gender.
CODE:
CREATE VIEW doctors AS
SELECT doc_id,doc_name,gender
FROM doctor
WHERE specialist = 'Cardiology';
Aakar Gupta(19BCE0379)

SELECT * FROM doctors;

Q9. Add an attribute No_of_staff in Department table and create a constraint with
constraint name to make sure the number is > 0.
CODE:
ALTER TABLE department
ADD No_of_staff NUMBER(5)
CONSTRAINT CHK_No_of_staff
CHECK (No_of_staff > 0);
Aakar Gupta(19BCE0379)

Q10. Add an attribute with In_Patient_prescription to store the Room_Type which can
store the values “AC” and “Non-AC”.
CODE:
ALTER TABLE in_patient_prescription
ADD Room_Type VARCHAR2(10)
CONSTRAINT CHK_Room_Type
Aakar Gupta(19BCE0379)

CHECK (Room_Type in('AC','Non-AC'));


Aakar Gupta(19BCE0379)

SQL QUERIES WITH JOIN OPERATION:

Q1. Find the HOD of doctor ‘RAGHVAN’.


CODE USING CARTESIAN PRODUCT:
Aakar Gupta(19BCE0379)

SELECT doc_name,hod FROM department,doctor


WHERE department.dept_no = doctor.dept_no
AND doc_name = 'RAGHVAN';

CODE USING INNER JOIN:


SELECT doctor.doc_name, department.hod
FROM doctor
INNER JOIN department ON doctor.DEPT_NO = department.DEPT_NO
WHERE doctor.doc_name = 'RAGHVAN';
Aakar Gupta(19BCE0379)

Q2. Find the list of all patients who were admitted in bed number ‘B101’.
CODE USING CARTESIAN PRODUCT:
SELECT pat_name,bed_no FROM patient,in_Patient
WHERE patient.pat_id = in_patient.pat_id
AND bed_no = 'B101';

CODE USING INNER JOIN:


SELECT patient.pat_name,in_patient.bed_no
Aakar Gupta(19BCE0379)

FROM patient
INNER JOIN in_patient ON patient.pat_id = in_patient.pat_id
WHERE in_patient.bed_no = 'B101';

Q3. Display all the prescribed medicines of patient with Pat_ID ‘P101’.
CODE USING CARTESIAN PRODUCT:
SELECT medicine_name FROM
prescribed_Medicines,prescription,in_patient_prescription
WHERE prescription.pres_id = prescribed_medicines.pres_id
AND prescription.pres_id = in_patient_prescription.pres_id
AND in_patient_prescription.pat_id = 'P101';
Aakar Gupta(19BCE0379)

CODE USING INNER JOIN:


SELECT prescribed_medicines.medicine_name
FROM prescribed_medicines
INNER JOIN prescription ON prescription.pres_id = prescribed_medicines.pres_id
INNER JOIN in_patient_prescription ON prescription.pres_id = in_patient_prescription.pres_id
WHERE in_patient_prescription.pat_id = 'P101';

Q4. Display the test results of patient ‘Mani’.


Aakar Gupta(19BCE0379)

CODE USING CARTESIAN PRODUCT:


SELECT pat_name,result FROM test_results,lab_tests,patient
WHERE lab_tests.test_id = test_results.test_id
AND patient.pat_id = lab_tests.pat_id
AND pat_name = 'Mani';

CODE USING INNER JOIN:


SELECT patient.pat_name, test_results.result
FROM test_results
INNER JOIN lab_tests ON lab_tests.test_id = test_results.test_id
INNER JOIN patient ON patient.pat_id = lab_tests.pat_id
WHERE patient.pat_name = 'Mani';
Aakar Gupta(19BCE0379)

Q5. Display all bills of bill amount more than 10000 rupees and paid by the patient
‘Steve’.
CODE USING CARTESIAN PRODUCT:
SELECT pat_name,bill_amount
FROM hospital_bill,patient
WHERE patient.pat_id = hospital_bill.pat_id
AND patient.pat_name = 'Steve'
AND hospital_bill.bill_amount > 10000;

CODE USING INNER JOIN:


SELECT patient.pat_name,hospital_bill.bill_amount
Aakar Gupta(19BCE0379)

FROM hospital_bill
INNER JOIN patient ON patient.pat_id = hospital_bill.pat_id
WHERE patient.pat_name = 'Steve'
AND hospital_bill.bill_amount > 10000;

Q6. Find the category and address of the nurse who attended the patient with pat_no
‘P220’.

Since we’ve already dropped address attribute of staff entity and added door_no,
street, city, pincode instead in Ques – 4 of previous exercise, therefore address can’t
be referred to now.

CODE USING CARTESIAN PRODUCT:


SELECT staff_name,catgory,door_no,street,city,pincode
FROM staff,appointment
WHERE appointment.nurse_id = staff.staff_id
Aakar Gupta(19BCE0379)

AND appointment.pat_id = 'P220';

CODE USING INNER JOIN:


SELECT staff.staff_name,staff.catgory,staff.door_no,staff.street,staff.city,staff.pincode
FROM staff
INNER JOIN appointment ON appointment.nurse_id = staff.staff_id
WHERE appointment.pat_id = 'P220';

RESULT OF THIS QUESTION BEFORE DROPPING ADDRESS ATTRIBUTE


CODE USING CARTESIAN PRODUCT:
SELECT staff_name,catgory,address
FROM staff,appointment
WHERE appointment.nurse_id = staff.staff_id
Aakar Gupta(19BCE0379)

AND appointment.pat_id = 'P220';

CODE USING INNER JOIN:


SELECT staff.staff_name,staff.catgory,staff.address
FROM staff
INNER JOIN appointment ON appointment.nurse_id = staff.staff_id
WHERE appointment.pat_id = 'P220';

Q7. Find the list of doctors who worked in the department which is started on or after
’10-May-2018’.
CODE USING CARTESIAN PRODUCT:
SELECT doc_name
Aakar Gupta(19BCE0379)

FROM doctor,department
WHERE doctor.doc_id = department.hod
AND department.est_date >= date '2018-05-10';

CODE USING INNER JOIN:


SELECT doctor.doc_name
FROM doctor
INNER JOIN department ON doctor.doc_id = department.hod
WHERE department.est_date >= date '2018-05-10';

Q8. Get the name of technicians who tests blood level.


CODE USING CARTESIAN PRODUCT:
SELECT staff_name,description
Aakar Gupta(19BCE0379)

FROM staff,test_types
WHERE test_types.technician = staff.staff_id
AND test_types.description = 'Blood test';

CODE USING INNER JOIN:


SELECT staff.staff_name, test_types.description
FROM staff
INNER JOIN test_types ON test_types.technician = staff.staff_id
WHERE test_types.description = 'Blood test';

Q9. Display the details of all patients who were hospitalized between ’10-Mar2020’ and
’10-Jul-2020’.
Aakar Gupta(19BCE0379)

Since we’ve already dropped address attribute of patient entity and replaced it with
street, city, pincode instead in Ques – 2 of previous exercise, therefore address can’t
be referred to now.

CODE USING CARTESIAN PRODUCT:


SELECT DISTINCT * FROM patient,in_patient
WHERE in_patient.pat_id = patient.pat_id
AND start_time >= date '2020-03-10' AND end_time <= date '2020-07-10';

CODE USING INNER JOIN:


SELECT DISTINCT * FROM patient
INNER JOIN in_patient ON in_patient.pat_id = patient.pat_id
WHERE start_time >= date '2020-03-10' AND end_time <= date '2020-07-10';
Aakar Gupta(19BCE0379)

RESULT OF THIS QUESTION BEFORE DROPPING ADDRESS ATTRIBUTE

CODE USING CARTESIAN PRODUCT:


SELECT DISTINCT * FROM patient,in_patient
WHERE in_patient.pat_id = patient.pat_id
AND start_time >= date '2020-03-10' AND end_time <= date '2020-07-10';

CODE USING INNER JOIN:


SELECT DISTINCT * FROM patient
Aakar Gupta(19BCE0379)

INNER JOIN in_patient ON in_patient.pat_id = patient.pat_id


WHERE start_time >= date '2020-03-10' AND end_time <= date '2020-07-10';

Q10. Display the in-patient prescription of the patient whose name is ‘Gayle’.

Since we’ve already dropped address attribute of patient entity and replaced it with
street, city, pincode instead in Ques – 2 of previous exercise, therefore address can’t
be referred to now.
Also we’ve added the Room_type attribute in In_Patient_prescription table in Ques –
10 of previous exercise.
Also we’ve dropped attributes dosage and brand from Prescribed_Medicines in Ques –
7 of previous exercise.

CODE USING CARTESIAN PRODUCT:


SELECT * FROM in_patient_prescription,patient,prescribed_medicines
WHERE patient.pat_id = in_patient_prescription.pat_id
AND in_patient_prescription.pres_id = prescribed_medicines.pres_id
Aakar Gupta(19BCE0379)

AND patient.pat_name = 'Gayle';

CODE USING INNER JOIN:


SELECT * FROM in_patient_prescription
INNER JOIN patient ON patient.pat_id = in_patient_prescription.pat_id
INNER JOIN prescribed_medicines ON in_patient_prescription.pres_id =
prescribed_medicines.pres_id
WHERE patient.pat_name = 'Gayle';
Aakar Gupta(19BCE0379)

RESULT OF THIS QUESTION BEFORE ANY MODIFICATION IN PREVIOUS EXERCISE

CODE USING CARTESIAN PRODUCT:

SELECT * FROM in_patient_prescription,patient,prescribed_medicines


WHERE patient.pat_id = in_patient_prescription.pat_id
AND in_patient_prescription.pres_id = prescribed_medicines.pres_id
AND patient.pat_name = 'Gayle';
Aakar Gupta(19BCE0379)

CODE USING INNER JOIN:


SELECT * FROM in_patient_prescription
INNER JOIN patient ON patient.pat_id = in_patient_prescription.pat_id
INNER JOIN prescribed_medicines ON in_patient_prescription.pres_id =
prescribed_medicines.pres_id
WHERE patient.pat_name = 'Gayle';

SQL QUERIES WITH AGGREGATE AND CHAR FUNCTIONS


Aakar Gupta(19BCE0379)

Q1. Find the number of doctors who are working in the department ‘D101’.

CODE:

SELECT COUNT(*)
AS "NO OF DOCTORS WORKING IN DEPARTMENT D101"
FROM DOCTOR WHERE DEPT_NO = 'D101';

Q2. Count the number of male patients who are treated by the doctor with doctor id
‘D0001’.

CODE:
Aakar Gupta(19BCE0379)

SELECT COUNT(patient.pat_id) AS "NO OF MALE PATIENT TREATED BY D0001"


FROM patient
INNER JOIN appointment ON appointment.pat_id = patient.pat_id
WHERE patient.gender = 'M'
AND appointment.doc_id = 'D0001';

Q3. Find the total bill paid by the patient ‘Karthik’.


CODE:
SELECT SUM(hospital_bill.bill_amount) AS "TOTAL BILL PAID BY KARTHIK"
FROM hospital_bill
INNER JOIN patient ON patient.pat_id = hospital_bill.pat_id
WHERE patient.pat_name = 'Karthik';
Aakar Gupta(19BCE0379)

Q4. Find the name and address of the patient who paid the highest bill of all patients.

Since we’ve already dropped address attribute of patient entity and replaced it with
street, city, pincode instead in Ques – 2 of previous exercise, therefore address can’t
be referred to now.
Instead of Address we will take street and city as the references.

CODE:
SELECT patient.pat_name, patient.street,patient.city, hospital_bill.bill_amount
FROM patient
INNER JOIN hospital_bill ON patient.pat_id = hospital_bill.pat_id
WHERE hospital_bill.bill_amount = (SELECT MAX(bill_amount) FROM hospital_bill);
Aakar Gupta(19BCE0379)

RESULT OF THIS QUESTION BEFORE DROPPING ADDRESS ATTRIBUTE


CODE:
SELECT patient.pat_name, patient.street,patient.city, hospital_bill.bill_amount
FROM patient
INNER JOIN hospital_bill ON patient.pat_id = hospital_bill.pat_id
WHERE hospital_bill.bill_amount = (SELECT MAX(bill_amount) FROM hospital_bill);

Q5. Get the specialization of doctors whose name start with the letter ‘M’.
CODE USING SUBSTR:
SELECT doctor.doc_name, doctor.specialist
FROM doctor
Aakar Gupta(19BCE0379)

WHERE SUBSTR(doc_name,1,1) IN ('M', 'm');

CODE USING LIKE:


SELECT doctor.doc_name, doctor.specialist
FROM doctor
WHERE doc_name like 'M%'
OR doc_name like 'm%';

Q6. Find the all the patients details whose name is exactly 5 characters long.
Since we’ve already dropped address attribute of patient entity and replaced it with
street, city, pincode instead in Ques – 2 of previous exercise, therefore address can’t
be referred to now.
CODE:
SELECT * FROM patient
WHERE LENGTH(patient.pat_name) = 5;
Aakar Gupta(19BCE0379)

RESULT OF THIS QUESTION BEFORE DROPPING ADDRESS ATTRIBUTE


CODE:
SELECT * FROM patient
WHERE LENGTH(patient.pat_name) = 5;

Q7. Display the department names in ascending order.


CODE:
SELECT dept_name
FROM department
ORDER BY dept_name ASC;
Aakar Gupta(19BCE0379)

NOW SELECT DISTINCT department names in ascending order.


CODE:
SELECT DISTINCT dept_name
FROM department
ORDER BY dept_name ASC;

Q8. Get the gender wise count of patients.


CODE:
SELECT COUNT(patient.pat_id) AS "Number of Male Patients"
FROM patient
WHERE patient.gender = 'M';

SELECT COUNT(patient.pat_id) AS "Number of Female Patients"


Aakar Gupta(19BCE0379)

FROM patient
WHERE patient.gender = 'F';

SELECT COUNT(patient.pat_id) AS "Number of Transgender Patients"


FROM patient
WHERE patient.gender = 'T';

Q9. Get the count of doctors for each specialization.


CODE:
SELECT specialist, COUNT(*) AS "Number Of Doctors"
FROM doctor
GROUP BY specialist;
Aakar Gupta(19BCE0379)

Q10. Get the total number tests conducted in any particular date.
CODE:
SELECT COUNT(test_id) AS "Number of Tests performed on 09-FEB-20"
FROM lab_tests
WHERE lab_tests.dte = date '2020-02-09'

SQL QUERIES - NESTED SUBQUERIES

Q1. All of the queries in “SQL queries with JOIN operation” section can be tried with
subqueries concept.
a) Find the HOD of doctor ‘RAGHVAN’.

CODE:
SELECT hod FROM department WHERE dept_no = (SELECT dept_no FROM doctor
WHERE doc_name = 'RAGHVAN');
Aakar Gupta(19BCE0379)

b) Find the list of all patients who were admitted in bed number ‘B101’.

CODE:
SELECT pat_name FROM patient where pat_id in (SELECT pat_id FROM in_patient
WHERE bed_no = 'B101');

c) Display all the prescribed medicines of patient with Pat_ID ‘P101’.

CODE:
SELECT medicine_name FROM prescribed_medicines WHERE pres_id in (SELECT
pres_id FROM in_patient_prescription WHERE pat_id = 'P101');

d) Display the test results of patient ‘Mani’.


Aakar Gupta(19BCE0379)

CODE:
SELECT result FROM test_results WHERE test_id = (SELECT test_id FROM
lab_tests,patient WHERE lab_tests.pat_id = patient.pat_id
AND pat_name ='Mani');

e) Display all bills of bill amount more than 10000 rupees and paid by the patient
‘Steve’.

CODE:
SELECT bill_amount FROM hospital_bill WHERE pat_id = (SELECT pat_id FROM
patient WHERE pat_name = 'Steve') AND bill_amount > 10000;

f) Find the category and address of the nurse who attended the patient with pat_no
‘P220’.

Since we’ve already dropped address attribute of staff entity and added door_no,
street, city, pincode instead in Ques – 4 of previous exercise, therefore address
can’t be referred to now.
Aakar Gupta(19BCE0379)

SELECT staff_name,catgory,door_no,street,city,pincode FROM staff WHERE staff_id


IN (SELECT nurse_id FROM appointment WHERE pat_id = 'P220');

RESULT OF THIS QUESTION BEFORE DROPPING ADDRESS ATTRIBUTE

SELECT staff_name,catgory,address FROM staff WHERE staff_id IN (SELECT nurse_id


FROM appointment WHERE pat_id = 'P220');

g) Find the list of doctors who worked in the department which is started on or after
’10-May-2018’.

CODE:
SELECT doc_name FROM doctor WHERE dept_no IN (SELECT dept_no
FROM department WHERE est_date >= date '2018-05-10');
Aakar Gupta(19BCE0379)

h) Get the name of technicians who tests blood test.

CODE:
SELECT staff_name FROM staff WHERE staff_id IN (SELECT technician FROM
test_types WHERE description = 'Blood test');

i) Display the details of all patients who were hospitalized between ’10-Mar2020’ and
’10-Jul-2020’.

Since we’ve already dropped address attribute of patient entity and replaced it
with street, city, pincode instead in Ques – 2 of previous exercise, therefore
address can’t be referred to now.

CODE:
Aakar Gupta(19BCE0379)

SELECT * FROM patient WHERE pat_id IN (SELECT pat_id FROM in_patient WHERE
start_time >= date '2020-03-10' AND end_time <= date '2020-07-10');

j) Display the in-patient prescription of the patient whose name is ‘Gayle’.

Since we’ve already dropped address attribute of patient entity and replaced it with
street, city, pincode instead in Ques – 2 of previous exercise, therefore address can’t be
referred to now.
Also we’ve added the Room_type attribute in In_Patient_prescription table in Ques –
10 of previous exercise.
Also we’ve dropped attributes dosage and brand from Prescribed_Medicines in Ques –
7 of previous exercise.

CODE:

SELECT * FROM in_patient_prescription WHERE pat_id = (SELECT pat_id FROM


patient WHERE pat_name = 'Gayle');
Aakar Gupta(19BCE0379)

Q2. Display the list of doctors who are working in the department with more number of
doctors using sub-query and IN operator.

CODE:
SELECT doc_name FROM doctor WHERE dept_no IN(SELECT dept_no FROM
(SELECT COUNT(doc_id) MyCount, dept_no
FROM doctor
GROUP BY dept_no) WHERE MyCount IN (SELECT MAX(MyCount) FROM (SELECT
COUNT(doc_id) MyCount, Dept_No
FROM doctor
GROUP BY dept_no)));
Aakar Gupta(19BCE0379)

As in my database all the list of doctors working in the all the department are printed
because in my database only one doctor was there in each department.

Q3. Find the name and id of all patients who are older than all the doctors in the entire
‘cardiology’ department. Use subqueries and ALL operator.
CODE:
SELECT patient.pat_id, patient.pat_name
FROM patient
WHERE patient.dob < ALL (SELECT dob FROM doctor
WHERE doctor.specialist = 'Cardiology');

We didn’t have any data that could fulfil this query hence no data found, otherwise this
query works fine.
Aakar Gupta(19BCE0379)

Q4. Find the prescription ids of all prescription that included a medicine from the brand
‘Ranbaxy’ using nested subqueries.
CODE:
SELECT pres_id FROM prescription WHERE pres_id IN (SELECT pres_id FROM
prescribed_medicines WHERE brand = 'Ranbaxy');

Q5. Find the list of patients who paid their bill through either ‘credit card’ or ‘debit card’
using subquery.
CODE:
SELECT pat_name FROM patient WHERE pat_id IN (SELECT pat_id FROM
hospital_bill WHERE payment_type = 'Credit card' or payment_type = 'Debit card');
Aakar Gupta(19BCE0379)

SQL QUERIES USING OTHER FUNCTIONS


Practice queries using DATE, NUMERIC, and CHARACTER functions. Try to upload at least
two queries from each function category.

DATE FUNCTION QUERIES:

Q1. Find the last date of month from the established date for a department with
department number ‘D105’.

CODE:

SELECT last_day(est_date) FROM department WHERE dept_no = 'D105';


Aakar Gupta(19BCE0379)

Q2. Find the date after adding 4 months in the date with appointment id ‘A105’.

CODE:
SELECT add_months(dte,4) AS date_after_adding_4_months FROM
appointment WHERE app_id = 'A105';

NUMERIC FUNCTION QUERIES:

Q1. Find the Square Root of Bill Amount of patient having patient id as ‘P104’.
CODE:
SELECT bill_amount,sqrt(bill_amount) FROM Hospital_Bill WHERE pat_id = 'P104';
Aakar Gupta(19BCE0379)

Q2. Find the Tan Value of Bill Amount of patients.


CODE:
SELECT bill_amount,cos(bill_amount) FROM Hospital_Bill;

CHARACTER FUNCTION QUERIES:

Q1. Concatenate the string ‘Smith’ in the patient having name ‘Steve’.
CODE:
SELECT concat('Steve',' Smith') AS "Concatenated Patient Name" FROM patient WHERE
pat_name = 'Steve';
Aakar Gupta(19BCE0379)

Q2. Display all the patient names in Upper Letters.

CODE:
SELECT pat_name,upper(pat_name) AS "PATIENT NAMES IN UPPERCASE" FROM patient;
Aakar Gupta(19BCE0379)

Q3. Display all the doctor names in Lower Letters.


CODE:
SELECT doc_name,lower(doc_name) AS "DOCTOR NAMES IN LOWERCASE" FROM
doctor;

You might also like