We found some interesting behavior when working in a package the other day. There are some things at the top of the package that have been generating warnings, but we've been ignoring the warnings because it seemed trivial. What I noticed is that after compiling the package seemingly successfully, I couldn't execute it. It wasn't really compiled. This is probably a bug in SQLDeveloper, but why generate warnings on what I would expect to be a trivial type conversion?
CREATE TABLE T
( TS_PK TIMESTAMP (6),
DATA1 NUMBER
);
Created in SQLPlus, we know that the package did not compile.
SQL> create or replace PACKAGE TEST_WARNING AS
2
3 PROCEDURE do_stuff;
4
5 END TEST_WARNING;
6 /
Package created.
SQL> create or replace PACKAGE BODY TEST_WARNING AS
2
3 PROCEDURE do_stuff AS
4 BEGIN
5 insert into t (ts_pk,data1) values (systimestamp, 1);
6 insert into t (ts_pk,data1) values (systimestamp, 2);
7 insert into t (ts_pk,data1) values (systimestamp, 3);
8 insert into t (ts_pk,data1) values (systimestamp, 4);
9 insert into t (ts_pk,data1) values (systimestamp, 5);
10 insert into t (ts_pk,data1) values (systimestamp, 6);
11 insert into t (ts_pk,data1) values (systimestamp, 7);
12 insert into t (ts_pk,data1) values (systimestamp, 8);
13 insert into t (ts_pk,data1) values (systimestamp, 9);
14 insert into t (ts_pk,data1) values (systimestamp, 10);
15 insert into t (ts_pk,data1) values (systimestamp, 10);
16 insert into t (ts_pk,data1) values (systimestamp, 12);
17 insert into t (ts_pk,data1) values (systimestamp, 13);
18 insert into t (ts_pk,data1) values (systimestamp, 14);
19 insert into t (ts_pk,data1) values (systimestamp, 15);
20 insert into t (ts_pk,data1) values (systimestamp, 16);
21 insert into t (ts_pk,data1) values (systimestamp, 17);
22 insert into t (ts_pk,data1) values (systimestamp, 18);
23 insert into t (ts_pk,data1) values (systimestamp, 19);
24 insert into t (ts_pk,data1) values (systimestamp, 20);
25
26 blah; -- this should cause the compile to fail
27
28
29 END do_stuff;
30
31 END TEST_WARNING;
32 /
Warning: Package Body created with compilation errors.
But through SQLDevleoper:
TEST_WARNING Compiled
TEST_WARNING Body Compiled (with warnings)
Project: D:\Data\sqldeveloper\sqldeveloper\system\oracle.sqldeveloper.1.2.0.2998\DefaultWorkspace\Project1.jpr
PACKAGE BODY OHD.TEST_WARNING@ohd
Warning(6,43): PLW-07202: bind type would result in conversion away from column type
Warning(7,43): PLW-07202: bind type would result in conversion away from column type
Warning(8,43): PLW-07202: bind type would result in conversion away from column type
Warning(9,43): PLW-07202: bind type would result in conversion away from column type
Warning(10,43): PLW-07202: bind type would result in conversion away from column type
Warning(11,43): PLW-07202: bind type would result in conversion away from column type
Warning(12,43): PLW-07202: bind type would result in conversion away from column type
Warning(13,43): PLW-07202: bind type would result in conversion away from column type
Warning(14,43): PLW-07202: bind type would result in conversion away from column type
Warning(15,43): PLW-07202: bind type would result in conversion away from column type
Warning(16,43): PLW-07202: bind type would result in conversion away from column type
Warning(17,43): PLW-07202: bind type would result in conversion away from column type
Warning(18,43): PLW-07202: bind type would result in conversion away from column type
Warning(19,43): PLW-07202: bind type would result in conversion away from column type
Warning(20,43): PLW-07202: bind type would result in conversion away from column type
Warning(21,43): PLW-07202: bind type would result in conversion away from column type
Warning(22,43): PLW-07202: bind type would result in conversion away from column type
Warning(23,43): PLW-07202: bind type would result in conversion away from column type
Warning(24,43): PLW-07202: bind type would result in conversion away from column type
Warning(25,43): PLW-07202: bind type would result in conversion away from column type
Warning(1,1): Only first 20 issues are reported <-- this causing my problem
What is the best way to put the current time into a plain timestamp column so that we don't get these warnings? I know there are multiple ways to suppress them, but I'd rather fix it so that they aren't warnings anymore.After running this, SQLDeveloper displays the error as expected, but I shouldn't need to do it in the first place.
exec dbms_warning.add_warning_setting_cat('ALL', 'DISABLE', 'SESSION')
plsql stops after 20 messages (warning or otherwise).
They are looking at upping that limit in the next release..
so, sqldeveloper - which has warnings on by default (and sqlplus does not) does this.
You can turn off the warnings by:
Preferences->Database->PL/SQL Compiler Options
turn off the informational/warning messages and it'll behave just like sqlplus in that regards.
man, a timestamp as a primary key :( what a bad choice... (converted from sqlserver I'd guess. very 'popular' from sybase days gone by...)
i would expect that even if that compiled, it would FAIL sometimes (assuming ts_pk is timestamp - primary key) Oracle is fast, you'll have duplicates some time.
ops$tkyte%ORA10GR2> create table t ( ts_pk timestamp(6) );
Table created.
ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> alter session set plsql_warnings='enable:all';
Session altered.
ops$tkyte%ORA10GR2> create or replace procedure p
2 as
3 begin
4 insert into t values ( systimestamp );
5 end;
6 /
SP2-0804: Procedure created with compilation warnings
ops$tkyte%ORA10GR2> show errors
Errors for PROCEDURE P:
LINE/COL ERROR
-------- -----------------------------------------------------------------
4/25 PLW-07202: bind type would result in conversion away from column
type
ops$tkyte%ORA10GR2> create or replace procedure p
2 as
3 l_ts t.ts_pk%type;
4 begin
5 l_ts := systimestamp;
6 insert into t values ( l_ts );
7 end;
8 /
Procedure created.