Вы находитесь на странице: 1из 6

SQL> set serveroutput on

SQL> set linesize300;


SQL> declare
2
v_empno number(5) :=&empno;
3
v_sal number(4);
4
v_ename varchar2(20);
5
v_err_code number;
6
v_err_msg varchar2(200);
7 begin
8 select ename,sal,empno into v_ename,v_sal,v_empno
9 from emp
10 where empno=v_empno;
11 dbms_output.put_line(v_ename||' '||v_sal||' '||v_empno);
12 exception
13
when others then
14
v_err_code :=sqlcode;
15
v_err_msg :=substr(sqlerrm,1,200);
16
dbms_output.put_line('error code:'||v_err_code);
17
dbms_output.put_line('error msg :'||v_err_msg);
18 end;
19 /
Enter value for empno: 7369
old 2:
v_empno number(5) :=&empno;
new 2:
v_empno number(5) :=7369;
SMITH 800 7369

PL/SQL procedure successfully completed.


SQL> /
Enter value for empno: 111
old 2:
v_empno number(5) :=&empno;
new 2:
v_empno number(5) :=111;
error code:100

error msg :ORA-01403: no data found

PL/SQL procedure successfully completed.


SQL> /
Enter value for empno: -345
old 2:
v_empno number(5) :=&empno;
new 2:
v_empno number(5) :=-345;
error code:100

error msg :ORA-01403: no data found

PL/SQL procedure successfully completed.

SQL> spool off


SQL> /
Enter value for empno: 078945
old 2:
v_empno number(5) :=&empno;
new 2:
v_empno number(5) :=078945;
error code:100

error msg :ORA-01403: no data found

PL/SQL procedure successfully completed.


SQL> /
Enter value for
old 2:
new 2:
v_empno

empno: nrt
v_empno number(5) :=&empno;
v_empno number(5) :=nrt;
number(5) :=nrt;
*
ERROR at line 2:
ORA-06550: line 2, column 22:
PLS-00201: identifier 'NRT' must be declared
ORA-06550: line 2, column 10:
PL/SQL: Item ignored
ORA-06550: line 10, column 13:
PLS-00320: the declaration of the type of this expression is incomplete or malfo
rmed
ORA-06550: line 10, column 13:
PL/SQL: ORA-00904: "V_EMPNO": invalid identifier
ORA-06550: line 8, column 1:
PL/SQL: SQL Statement ignored
ORA-06550: line 11, column 49:
PLS-00320: the declaration of the type of this expression is incomplete or malfo
rmed
ORA-06550: line 11, column 1:
PL/SQL: Statement ignored
SQL> Declare
2
dbms_output.put_line('error code : '||sqlcode);
3
dbms_output.put_line('error mag1 :'||sqlerrm(sqlcode));
4
dbms_output.put_line('error msg2 : '||sqlerrm(100));
5
dbms_output.put_line('error msg3: '||sqlerrm(200));
6
dbms_output.put_line('error msg4: '||sqlerrm(-20000));
7 end;
8 /
dbms_output.put_line('error code : '||sqlcode);
*
ERROR at line 2:
ORA-06550: line 2, column 13:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national character
nchar
The symbol "<an identifier>" was substituted for "." to continue.

ORA-06550: line 3, column 13:


PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national charact
ORA-06550: line 4, column 13:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national charact
ORA-06550: line 5, column 13:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identif
SQL> ed
Wrote file afiedt.buf
1 Declare
2
dbms_output.put_line('error code : '||SQLCODE);
3
dbms_output.put_line('error mag1 :'||sqlerrm(sqlcode));
4
dbms_output.put_line('error msg2 : '||sqlerrm(100));
5
dbms_output.put_line('error msg3: '||sqlerrm(200));
6
dbms_output.put_line('error msg4: '||sqlerrm(-20000));
7* end;
SQL> /
dbms_output.put_line('error code : '||SQLCODE);
*
ERROR at line 2:
ORA-06550: line 2, column 13:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national character
nchar
The symbol "<an identifier>" was substituted for "." to continue.
ORA-06550: line 3, column 13:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national charact
ORA-06550: line 4, column 13:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table long double ref
char time timestamp interval date binary national charact
ORA-06550: line 5, column 13:
PLS-00103: Encountered the symbol "." when expecting one of the following:
constant exception <an identif
SQL> ed
Wrote file afiedt.buf
1 begin
2
dbms_output.put_line('error
3
dbms_output.put_line('error
4
dbms_output.put_line('error
5
dbms_output.put_line('error
6
dbms_output.put_line('error

code : '||SQLCODE);
mag1 :'||sqlerrm(sqlcode));
msg2 : '||sqlerrm(100));
msg3: '||sqlerrm(200));
msg4: '||sqlerrm(-20000));

7* end;
SQL> /
error code : 0

error mag1 :ORA-0000: normal, successful completion

error msg2 : ORA-01403: no data found

error msg3:

-200: non-ORACLE exception

error msg4: ORA-20000:

PL/SQL procedure successfully completed.


SQL> create table a(id number);
create table a(id number)
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
SQL> select * from a;
ID

SALARY

---------- ----------

123

4000

222

3000

SQL> drop table a;


Table dropped.
SQL> cl scr
SQL> create table a (id number);
Table created.

SQL> insert into a values (2);


1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> insert into a values(3);
1 row created.
SQL> /
1 row created.
SQL> ed
Wrote file afiedt.buf
1* insert into a values(5)
SQL> /
1 row created.
SQL> /
1 row created.
SQL> ed
Wrote file afiedt.buf
1* insert into a values(8)
SQL> /
1 row created.
SQL> select * from a;
ID

----------

8 rows selected.
SQL> delete from a where rowid not in(select max(rowid)
2 from emp);
8 rows deleted.
SQL> select * from a;
no rows selected
SQL> rollback;
Rollback complete.
SQL> select * from a;
no rows selected
SQL> spool off

Вам также может понравиться