Monday, July 5, 2010

pl sql prgrms

SQL> cl scr

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 LOOP
15 fetch ec into i
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(null);
20 close ec;
21 end loop;
22 close dc;
23* end;
24 /
loop
*
ERROR at line 10:
ORA-06550: line 10, column 3:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
. ( % ; for
The symbol "; was inserted before "LOOP" to continue.
ORA-06550: line 16, column 7:
PLS-00103: Encountered the symbol "EXIT" when expecting one of the following:
. ( , % ; limit


SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(null);
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
loop
*
ERROR at line 10:
ORA-06550: line 10, column 3:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
. ( % ; for
The symbol "; was inserted before "LOOP" to continue.
ORA-06550: line 16, column 7:
PLS-00103: Encountered the symbol "EXIT" when expecting one of the following:
. ( , % ; limit


SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno)
14 loop
15 fetch ec into i
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(null);
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
loop
*
ERROR at line 10:
ORA-06550: line 10, column 3:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
. ( % ; for
The symbol "; was inserted before "LOOP" to continue.
ORA-06550: line 14, column 6:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
. ( % ;
The symbol "; was inserted before "LOOP" to continue.
ORA-06550: line 16, column 7:
PLS-00103: Encountered the symbol "EXIT" when expecting one of the following:
. ( , % ; limit


SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno)
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(null);
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
loop
*
ERROR at line 10:
ORA-06550: line 10, column 3:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
. ( % ; for
The symbol "; was inserted before "LOOP" to continue.
ORA-06550: line 14, column 6:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
. ( % ;
The symbol "; was inserted before "LOOP" to continue.
ORA-06550: line 19, column 6:
PLS-00103: Encountered the symbol "DBMS_OUTPUT"
ORA-06550: line 19, column 32:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
. ( , * % & - + / at mod remainder rem
as
from into || multiset bulk


SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(null);
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /

PL/SQL procedure successfully completed.

SQL> set serveroutput on
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(' ');
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(' '||' ');
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(NULL);
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 close ec;
20 dbms_output.put_line(NULL);
21 end loop;
22 close dc;
23* end;
24 /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(' ' ');
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
ERROR:
ORA-01756: quoted string not properly terminated


SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(' '' ');
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
'
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
'
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30
'


PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(' ');
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line(' '||null);
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(i.ename||' '||i.sal||' '||i.deptno);
18 end loop;
19 dbms_output.put_line('*********************');
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
*********************
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
*********************
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30
*********************
*********************

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor dc is
3 select deptno from dept;
4 cursor ec(pdno number) is
5 select ename,sal,deptno from emp where deptno=pdno;
6 vdno dept.deptno%type;
7 i ec%rowtype;
8 begin
9 open dc;
10 loop
11 fetch dc into vdno;
12 exit when dc%notfound;
13 open ec(vdno);
14 loop
15 fetch ec into i;
16 exit when ec%notfound;
17 dbms_output.put_line(rpad(i.ename,8)||' '||rpad(i.sal,6)||' '||i.deptno);
18 end loop;
19 dbms_output.put_line('*********************');
20 close ec;
21 end loop;
22 close dc;
23* end;
SQL> /
CLARK 2450 10
KING 5000 10
MILLER 1300 10
*********************
SMITH 800 20
JONES 2975 20
SCOTT 3000 20
ADAMS 1100 20
FORD 3000 20
*********************
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
BLAKE 2850 30
TURNER 1500 30
JAMES 950 30
*********************
*********************

PL/SQL procedure successfully completed.

SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor c(dno number) is
3 select ename,sal,job,deptno from emp where deptno=dno;
4 i c%rowtype;
5 begin
6 open c(&dno);
7 loop
8 fetch c into i;
9 exit when c%notfound;
10 if job='CLERK' then
11 sal:=sal+nvl(comm,2)*2;
12 elsif job='SALESMAN' then
13 sal:=sal+nvl(comm,2)*3;
14 else
15 sal:=sal+nvl(comm,2)*4;
16 end loop;
17 dbms_output.put_line(rpad(i.ename,8)||' '||rpad(i.sal,6)||' '||rpad(i.job,6)||' '||i.deptno);
18 close c;
19* end;
20 /
Enter value for dno: 30
old 6: open c(&dno);
new 6: open c(30);
end loop;
*
ERROR at line 16:
ORA-06550: line 16, column 7:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
if
ORA-06550: line 19, column 4:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the
following:
end not pragma final instantiable order overriding static
member constructor map


SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor c(dno number) is
3 select ename,sal,job,deptno from emp where deptno=dno;
4 i c%rowtype;
5 begin
6 open c(&dno);
7 loop
8 fetch c into i;
9 exit when c%notfound;
10 if job='CLERK' then
11 sal:=sal+nvl(comm,2)*2;
12 elsif job='SALESMAN' then
13 sal:=sal+nvl(comm,2)*3;
14 else
15 sal:=sal+nvl(comm,2)*4;
16 end if;
17 dbms_output.put_line(rpad(i.ename,8)||' '||rpad(i.sal,6)||' '||rpad(i.job,6)||' '||i.deptno);
18 end loop;
19 close c;
20* end;
21 /
Enter value for dno: 30
old 6: open c(&dno);
new 6: open c(30);
if job='CLERK' then
*
ERROR at line 10:
ORA-06550: line 10, column 8:
PLS-00201: identifier 'JOB' must be declared
ORA-06550: line 10, column 5:
PL/SQL: Statement ignored


SQL> ed
Wrote file afiedt.buf

1 declare
2 cursor c(dno number) is
3 select ename,sal,job,deptno from emp where deptno=dno;
4 i c%rowtype;
5 begin
6 open c(&dno);
7 loop
8 fetch c into i;
9 exit when c%notfound;
10 if job='CLERK' then
11 sal:=sal+nvl(comm,2)*2;
12 elsif job='SALESMAN' then
13 sal:=sal+nvl(comm,2)*3;
14 else
15 sal:=sal+nvl(comm,2)*4;
16 end if;
17 dbms_output.put_line(rpad(i.ename,8)||' '||rpad(i.sal,6)||' '||rpad(i.job,6)||' '||i.deptno);
18 end loop;
19 close c;
20* end;
SQL> exit




No comments:

Post a Comment