Dbms Lab Manual Mtech Cse 2025
Dbms Lab Manual Mtech Cse 2025
Laboratory Record
M.tech CSE 2025
DATA BASE PROGRAMMING LABORATORY RECORD
FOR
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
3 Given an integeri,writeaPL/SQLprocedureto 7
insertthetuple(i,‘xxx’)intoagiven relation.
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");
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;
}
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 ----------------------- */
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: