0% found this document useful (0 votes)
32 views16 pages

Dbms Lab Manual Mtech Cse 2025

The document outlines a laboratory record for M.Tech CSE students, detailing a series of PL/SQL programming experiments. These experiments include writing programs for inserting rows, using cursors, handling exceptions, and demonstrating various PL/SQL features such as functions and packages. Each experiment is accompanied by a brief description and a corresponding page number.

Uploaded by

brigcse05
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)
32 views16 pages

Dbms Lab Manual Mtech Cse 2025

The document outlines a laboratory record for M.Tech CSE students, detailing a series of PL/SQL programming experiments. These experiments include writing programs for inserting rows, using cursors, handling exceptions, and demonstrating various PL/SQL features such as functions and packages. Each experiment is accompanied by a brief description and a corresponding page number.

Uploaded by

brigcse05
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/ 16

DATABASE PROGRAMMING WITH PL/SQL LAB

Laboratory Record
M.tech CSE 2025
DATA BASE PROGRAMMING LABORATORY RECORD
FOR

M.TECH(CSE) Ist YEAR, Ist SEMESTER

List of Experiments:
1. Write a Pl/SQL program using FOR loop to insert ten rows into a database table.
2. Given the table EMPLOYEE (EmpNo, Name, Salary, Designation, DeptID), write a cursor to select
the five highest paid employees from the table.
3. Illustrate how you can embed PL/SQL in a high-level host language such as C/Java And demonstrates
how a banking debit transaction might be done.
4. Given an integer i, write a PL/SQL procedure to insert the tuple (i, 'xxx') into a given relation. 5. Write
a PL/SQL program to demonstrate Exceptions.
6. Write a PL/SQL program to demonstrate Cursors.
7. Write a PL/SQL program to demonstrate Functions.
8. Write a PL/SQL program to demonstrate Packages.
9. Write PL/SQL queries to create Procedures.
10. Write PL/SQL queries to create Triggers.
DATABASE PROGRAMMING LABORATORY RECORD

LIST OF EXPERIMENTS

S.No. NAME OF THE EXPERIMENT PAGENO.

1 Write a PL/SQL program using FOR loop to insert 4

Ten rows into a database table.

2 Given the table Employee(EmpNo,Name,Salary, 5

Designation,DeptID),write a cursor to select the five

highest paid employees from the table.

3 Given an integeri,writeaPL/SQLprocedureto 7

insertthetuple(i,‘xxx’)intoagiven relation.

4 Write a PL/SQL program to demonstrate 8

Exceptions.

5 WriteaPL/SQLprogramtodemonstrateCursors. 9

6 WriteaPL/SQLprogramtodemonstrateFunctions. 10

7 WriteaPL/SQLprogramtodemonstratePackages. 11

8 WriteaPL/SQLqueries tocreateProcedures. 12

9 WriteaPL/SQLqueries tocreateTriggers. 13

3
1. Write a PL/SQL program using FOR loop to insert ten rows in to database table.

PROGRAM:

OUTPUT:
2. Given the table Employee ( EmpNo, Name, Salary, Designation, DeptID), write
a cursor to select the five highest paid employees from the table.

PROGRAM:
OUTPUT:
3) Illustrate how you can embed PL/SQL in a high-level host language such as C/Java
And
demonstrates how a banking debit transaction might be done.

you prompt the user for a bank account number, transaction type, and transaction amount,
then debit or credit the account. If the account does not exist, you raise an exception. When the
transaction is complete, you display its status.

#include <stdio.h>
#include <sqlca.h>

char username[20];
char password[20];
char status[80];
char temp[32];
int acct_num;
double trans_amt;
void sql_error();

main()
{
char trans_type;

strcpy(password, "TIGER");
strcpy(username, "SCOTT");

EXEC SQL WHENEVER SQLERROR DO sql_error();


EXEC SQL CONNECT :username IDENTIFIED BY :password;
printf("Connected to Oracle\n");

for (;;)
{
printf("Account Number (0 to end)? ");
gets(temp);
acct_num = atoi(temp);

if(acct_num == 0)
{
EXEC SQL COMMIT WORK RELEASE;
printf("Exiting program\n");
break;
}

printf("Transaction Type - D)ebit or C)redit? ");


gets(temp);
trans_type = temp[0];

printf("Transaction Amount? ");


gets(temp);
trans_amt = atof(temp);

/*----------------- begin PL/SQL block -------------------*/


EXEC SQL EXECUTE
DECLARE
old_bal NUMBER(9,2);
err_msg CHAR(70);
nonexistent EXCEPTION;

BEGIN
:trans_type := UPPER(:trans_type);
IF :trans_type = 'C' THEN -- credit the account
UPDATE accts SET bal = bal + :trans_amt
WHERE acctid = :acct_num;
IF SQL%ROWCOUNT = 0 THEN -- no rows affected
RAISE nonexistent;
ELSE
:status := 'Credit applied';
END IF;
ELSIF :trans_type = 'D' THEN -- debit the account
SELECT bal INTO old_bal FROM accts
WHERE acctid = :acct_num;
IF old_bal >= :trans_amt THEN -- enough funds
UPDATE accts SET bal = bal - :trans_amt
WHERE acctid = :acct_num;
:status := 'Debit applied';
ELSE
:status := 'Insufficient funds';
END IF;
ELSE
:status := 'Invalid type: ' || :trans_type;
END IF;
COMMIT;
EXCEPTION
WHEN NO_DATA_FOUND OR nonexistent THEN
:status := 'Nonexistent account';
WHEN OTHERS THEN
err_msg := SUBSTR(SQLERRM, 1, 70);
:status := 'Error: ' || err_msg;
END;
END-EXEC;
/*----------------- end PL/SQL block ----------------------- */

printf("\nStatus: %s\n", status);


}
exit(0);
}
void
sql_error()
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL ROLLBACK WORK RELEASE;
printf("Processing error\n");
exit(1);
}

Output:
Transaction Type - Debit or Credit?
>> SECLECT * FROM BANK;

a/c no debit

1111000124 10000

1111000124 5000

4.Given an integer i,write a PL/SQL procedure to insert the tuple (i,‘xxx’) in to a given relation.
PROGRAM:

OUTPUT:
5.Write a PL/SQL program to demonstrate Exceptions.

PROGRAM:

OUTPUT:
6.Write a PL/SQL program to demonstrate Cursors.

PROGRAM:

OUTPUT:
7.Write a PL/SQL program to demonstrate Functions.

PROGRAM:

OUTPUT:
8.Write a PL/SQL program to demonstrate Packages.

PROGRAM:

OUTPUT:
9.Write a PL/SQL queries to create Procedures.

PROGRAM:

OUTPUT:
10.Write a PL/SQL queries to create Triggers.

PROGRAM:

OUTPUT:

You might also like