Tausif and stanzin practical
Tausif and stanzin practical
LABORATORY FILE
For the course of
Introduction:
This helps us to access and manage the information easily. This also helps to
verify the stock currently available with them and to update the stock when
necessary. This also reduces the time to search the product from the available
stock.The role of an inventory system is to track your products and supplies.
Inventory management is the process of controlling of the ordering, storage
and use of components that a company uses in the production of the products
it sells.
Objectives:
DESC bill;
c. Drop Table
a. Insert
UPDATE purchase
SET quantity = 7
WHERE biilno = 8;
select * from purchase where biilno=8;
c. Delete
d. Truncate
SELECT COUNT(*)
from purcahse
where item_name= 'sulphate';
SELECT SUM(quantity)from
purchase;
SELECT MAX(quantity) AS
LargestStock FROM purchase;
SELECT AVG(quantity)
FROM purchase;
d. Group by + having
e. Order by
Select item_name,
quantity from
purchase ORDER
BY quantity;
f. Views
PROJECT REPORT
For the course of
PROJECT REPORT
For the course of
a. Nested Queries
SELECT *
FROM purchase
WHERE item_id IN (
SELECT item_id FROM
bill WHERE biilno IN (
SELECT FROM
inventory
WHERE STATUS = 'ACTIVE'
)
);
b. Inner Join
d. Right Join
e. Outer Join
a. Variables
b. Packages
c. Procedures
COMMIT;
This procedure takes two parameters - the ISBN of the book to update
and the quantity by which to update the stock count. It first retrieves the
current stock count for the book, and then checks if the updated stock
count would be negative. If it would be, it raises an error. Otherwise, it
updates the stock count and commits the transaction.
d. Functions
DECLARE
FUNCTION get_stock_count(p_isbn IN Books.ISBN%TYPE)
RETURN Books.Stock_Count%TYPE
IS
v_stock_count Books.Stock_Count% TYPE;
BEGIN
SELECT Stock_Count INTO v_stock_count FROM Books WHERE ISBN =
p_isbn;
RETURN v_stock_count;
END;
v_stock_count Books.Stock_Count%TYPE;
BEGIN
v_stock_count := get_stock_count('1234567890');
DBMS_OUTPUT.PUT_LINE('Stock count for ISBN 1234567890: ' ||
v_stock_count);
END;
Program – 7
DECLARE
v_num1 NUMBER := 10;
v_num2 NUMBER := 0;
v_result NUMBER;
BEGIN
-- Perform division
v_result := v_num1 / v_num2;
DBMS_OUTPUT.PUT_LINE('Result: ' || v_result);
EXCEPTION
-- Handle division by zero exception
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Error: Division by zero.');
-- Handle other exceptions
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
END;
Program – 9
CREATE TRIGGER
update_stock_count AFTER INSERT
ON Book_Warehouse FOR EACH ROW
BEGIN
UPDATE Books
SET Stock_Count = Stock_Count + NEW.Quantity
WHERE ISBN = NEW.ISBN;
END;
CREATE TRIGGER
update_shopping_cart AFTER INSERT
ON Cart_Items
FOR EACH ROW
BEGIN
UPDATE Shopping_Cart
SET Status = 'In
Progress',
Total_Price = (SELECT SUM(Price * NEW.Quantity) FROM
Books WHERE ISBN = NEW.ISBN)
WHERE Cart_ID =
NEW.Cart_ID; END;
Program – 10
Code –
START TRANSACTION;
SAVEPOINT before_insert;
INSERT INTO bill (biilno, item_name, item_id)
VALUES ('9', 'sulphate', 80');COMMIT;
-- If an error occurs before the COMMIT statement, you can use the
ROLLBACK statement to undo the changes:
START TRANSACTION;
INSERT INTO bill (biilno, item_name, item_id)
VALUES ('9', 'sulphate', 80');COMMIT;
ROLLBACK;
-- If you want to undo only part of the transaction, you can use the
SAVEPOINT and ROLLBACK TO statements:
START TRANSACTION;
INSERT INTO bill (biilno, item_name, item_id)
VALUES ('9', 'sulphate', 80');COMMIT;
SAVEPOINT before_update;
UPDATE bill SET item_id = 99 WHERE item_name ='sulphate';
ROLLBACK TO before_update;
-- This will undo the UPDATE statement, but keep the INSERT
statement:
COMMIT;