Opening Hours :7AM to 9PM
DECLARE customer_rec customers%rowtype; BEGIN SELECT * into customer_rec FROM customers WHERE id = 5; dbms_output.put_line('Customer ID: ' || customer_rec.id); dbms_output.put_line('Customer Name: ' || customer_rec.name); dbms_output.put_line('Customer Address: ' || customer_rec.address); dbms_output.put_line('Customer Salary: ' || customer_rec.salary); END; /Output:
declare c_rec calc%rowtype; res1 int:=0; c_sn int:=1; begin select * into c_rec from calc where sn=c_sn; case when c_sn=1 then res1:=c_rec.fno+c_rec.sno; dbms_output.put_line(res1); update calc set res=res1 where sn=c_sn; when c_sn=2 then res1:=c_rec.fno-c_rec.sno; dbms_output.put_line(res1); update calc set res=res1 where sn=c_sn; when c_sn=3 then res1:=c_rec.fno*c_rec.sno; dbms_output.put_line(res1); update calc set res=res1 where sn=c_sn; when c_sn=4 then res1:=c_rec.fno/c_rec.sno; dbms_output.put_line(res1); update calc set res=res1 where sn=c_sn; else dbms_output.put_line('invalid'); end case; end; /
DECLARE CURSOR customer_cur is SELECT id, name, address FROM customers; customer_rec customer_cur%rowtype; BEGIN OPEN customer_cur; LOOP FETCH customer_cur into custom er_rec; EXIT WHEN customer_cur%notfound; DBMS_OUTPUT.put_line(customer_rec.id || ' ' || customer_rec.name); END LOOP; END; /Output:
DECLARE CURSOR c_customers is SELECT * FROM customers; c_rec c_customers%rowtype; BEGIN OPEN c_customers; LOOP FETCH c_customers into c_rec; EXIT WHEN c_customers%notfound; if(c_rec.salary<2000) then update customers set salary=c_rec.salary+100 where id=c_rec.id; elsif (c_rec.salary<=5000) then update customers set salary=c_rec.salary+300 where id=c_rec.id; elsif (c_rec.salary<=19000) then update customers set salary=c_rec.salary+500 where id=c_rec.id; end if; END LOOP; CLOSE c_customers; END; /
TYPE type_name IS RECORD ( field_name1 datatype1 [NOT NULL] [:= DEFAULT EXPRESSION], field_name2 datatype2 [NOT NULL] [:= DEFAULT EXPRESSION], ... field_nameN datatypeN [NOT NULL] [:= DEFAULT EXPRESSION); record-name type_name;
DECLARE TYPE books IS RECORD (title varchar(50), author varchar(50), subject varchar(100), book_id number); book1 books; book2 books;
DECLARE type books is record (title varchar(50), author varchar(50), subject varchar(100), book_id number); book1 books; book2 books; BEGIN -- Book 1 specification book1.title := 'C Programming'; book1.author := 'Nuha Ali '; book1.subject := 'C Programming Tutorial'; book1.book_id := 6495407; -- Book 2 specification book2.title := 'Telecom Billing'; book2.author := 'Zara Ali'; book2.subject := 'Telecom Billing Tutorial'; book2.book_id := 6495700; -- Print book 1 record dbms_output.put_line('Book 1 title : '|| book1.title); dbms_output.put_line('Book 1 author : '|| book1.author); dbms_output.put_line('Book 1 subject : '|| book1.subject); dbms_output.put_line('Book 1 book_id : ' || book1.book_id); -- Print book 2 record dbms_output.put_line('Book 2 title : '|| book2.title); dbms_output.put_line('Book 2 author : '|| book2.author); dbms_output.put_line('Book 2 subject : '|| book2.subject); dbms_output.put_line('Book 2 book_id : '|| book2.book_id); END; /Output:
DECLARE type books is record (title varchar(50), author varchar(50), subject varchar(100), book_id number); book1 books; book2 books; PROCEDURE printbook (book books) IS BEGIN dbms_output.put_line ('Book title : ' || book.title); dbms_output.put_line('Book author : ' || book.author); dbms_output.put_line( 'Book subject : ' || book.subject); dbms_output.put_line( 'Book book_id : ' || book.book_id); END; BEGIN -- Book 1 specification book1.title := 'C Programming'; book1.author := 'Nuha Ali '; book1.subject := 'C Programming Tutorial'; book1.book_id := 6495407; -- Book 2 specification book2.title := 'Telecom Billing'; book2.author := 'Zara Ali'; book2.subject := 'Telecom Billing Tutorial'; book2.book_id := 6495700; -- Use procedure to print book info printbook(book1); printbook(book2); END; /Output: