DBMS Practice
DBMS Practice
Connected.
SQL> declare
2 a number:=5;
3 b number:=6;
4 c number:=2;
5 begin
8 dbms_output.put_line('a is greatest');
9 else
11 dbms_output.put_line('b is greatest');
12 else
13 dbms_output.put_line('c is greatest');
14 end if;
16 /
SQL>
SQL> declare
2 a number:=10;
3 b number:=12;
4 c number:=5;
5 begin
7 dbms_output.put_line('a is greatest');
8 else
10 dbms_output.put_line('b is greatest');
11 else
12 dbms_output.put_line('c is greatest');
13 end if;
15 /
b is greatest
SQL> create table em(eno number(5), ename varchar2(10), loc varchar(10), salary
number(10,2));
Table created.
SQL> DECLARE
2 num NUMBER := 5;
3 factorial NUMBER := 1;
4 i NUMBER := 1;
5 multiplier NUMBER;
6 e_invalid_input EXCEPTION;
7 BEGIN
9 RAISE e_invalid_input;
10 END IF;
12 factorial := factorial * i;
13 i := i + 1;
14 END LOOP;
19 END LOOP;
24 END LOOP;
25 END LOOP;
26 DECLARE
27 x NUMBER := 10;
28 y NUMBER := 0;
29 z NUMBER;
30 BEGIN
31 z := x / y;
33 EXCEPTION
36 END;
37 EXCEPTION
43 END;
44 /
Multiplication Table of 5:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Outer: 1, Inner: 1
Outer: 1, Inner: 2
Outer: 1, Inner: 3
Outer: 2, Inner: 1
Outer: 2, Inner: 2
Outer: 2, Inner: 3
Outer: 3, Inner: 1
Outer: 3, Inner: 2
Outer: 3, Inner: 3
2 n in number,
3 a in number,
4 c out number)IS
5 BEGIN
6 IF n < a then
7 c := n;
8 ELSE
9 c := a;
10 END IF;
11 END;
12 DECLARE
13 x NUMBER := 12;
14 y NUMBER := 8;
15 z NUMBER;
16 BEGIN
17 find_min(x,y,z);
19 END;
20 /
2 n IN NUMBER,
3 a IN NUMBER,
4 c OUT NUMBER
5 ) IS
6 BEGIN
7 IF n < a THEN
8 c := n;
9 ELSE
10 c := a;
11 END IF;
12 END;
13 /
Procedure created.
SQL> DECLARE
2 x NUMBER := 12;
3 y NUMBER := 8;
4 z NUMBER;
5 BEGIN
6 find_min(x, y, z);
8 END;
9 /
ERROR at line 1:
2 a IN NUMBER,
3 b IN NUMBER
4 ) RETURN NUMBER
5 IS
6 min_val NUMBER;
7 BEGIN
8 IF a < b THEN
9 min_val := a;
10 ELSE
11 min_val := b;
12 END IF;
13 RETURN min_val;
14 END;
15 /
Function created.
MIN_RESULT
----------
SQL> create table customers(id number(3), name varchar2(10), age number(3), address
varchar2(10), salary number(10,2));
create table customers(id number(3), name varchar2(10), age number(3), address varchar2(10),
salary number(10,2))
ERROR at line 1:
ORA-00955: name is already used by an existing object
SQL> create table cust(id number(3), name varchar2(10), age number(3), address varchar2(10),
salary number(10,2));
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> DECLARE
3 c_address customers.address%type;
4 CURSOR c_customers is
6 BEGIN
7 OPEN c_customers;
8 LOOP
11 CLOSE c_customers;
12 END;
13 /
1sanjaykrnl
SQL> DECLARE
2 c_id customers.id%TYPE;
3 c_name customers.name%TYPE;
4 c_address customers.address%TYPE;
6 CURSOR c_customers IS
9 BEGIN
10 OPEN c_customers;
11 LOOP
14 DBMS_OUTPUT.PUT_LINE('ID: ' || c_id || ', Name: ' || c_name || ', Address: ' ||
c_address);
15 END LOOP;
16 CLOSE c_customers;
17 END;
18 /
SQL>
SQL> DECLARE
2 c_id customers.id%TYPE;
3 c_name customers.name%TYPE;
4 c_address customers.address%TYPE;
6 CURSOR c_customers IS
9 BEGIN
10 OPEN c_customers;
11 LOOP
14 DBMS_OUTPUT.PUT_LINE('ID: ' || c_id || ', Name: ' || c_name || ', Address: ' ||
c_address);
15 END LOOP;
16 CLOSE c_customers;
17 END;
18 /
SQL>