Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: PL/SQL strange error :((

Re: PL/SQL strange error :((

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Thu, 27 May 1999 16:03:41 GMT
Message-ID: <37546aea.17963229@newshost.us.oracle.com>


A copy of this was sent to "Laurent Boulard" <Laurent.Boulard_at_icl.com> (if that email address didn't require changing) On Thu, 27 May 1999 15:40:39 +0100, you wrote:

>For two days now, I don't understand why when I try this little piece of
>code, I get a error.
>I checked memory space and syntax, looked in each part of thePL/SQL User's
>guide and reference.
>This code is for a Oracle Server 8.0.5.
>
>------------ cut here -------------------------------
>-- ====================================================================
>--
>-- TPCC random functions
>--
>-- ====================================================================
>
>create or replace package tpccrand is
>

[snip]
/
>show errors;
>

the error I get with that is:

SQL> create or replace package tpccrand is   2 --

  3          type Tperm is varray (3000) of integer;
  4          randperm3000 Tperm;
  5  --
  6     type Tlastname is varying array (10) of varchar2(10);
  7          lastname Tlastname :=
  8        T_lastname( 'BAR',   'OUGHT', 'ABLE', 'PRI',
  9                    'PRES',  'ESE',   'ANTI', 'CALLY',
 10                    'ATION', 'EING'
 11                  );
 12  --
 13          procedure initperm;
 14          procedure randstr (str out varchar2, x in integer, y in integer);
 15          procedure randdatastr (str out varchar2, x in integer, y in
 16  integer);
 17          procedure randnum (str out varchar2, len in integer);
 18          procedure randlastname (str out varchar2, id in integer);
 19          function NURand (A in integer, x in integer, y in integer,
 20                          cnum in integer) return integer;
 21 end tpccrand;
 22 /

Warning: Package created with compilation errors.

SQL> show errors;
Errors for PACKAGE TPCCRAND:

LINE/COL ERROR

-------- -----------------------------------------------------------------
7/18     PL/SQL: Declaration ignored
8/7      PLS-00201: identifier 'T_LASTNAME' must be declared

That looks like a typo -- you have T_lastname not tLastName. Once you fix that however, you'll get:

  1 create or replace package tpccrand is   2 --

  3          type Tperm is varray (3000) of integer;
  4          randperm3000 Tperm;
  5  --
  6     type TlastName is varying array (10) of varchar2(10);
  7          lastname TlastName :=
  8        TlastName( 'BAR',   'OUGHT', 'ABLE', 'PRI',
  9                    'PRES',  'ESE',   'ANTI', 'CALLY',
 10                    'ATION', 'EING'
 11                  );
 12  --
 13          procedure initperm;
 14          procedure randstr (str out varchar2, x in integer, y in integer);
 15          procedure randdatastr (str out varchar2, x in integer, y in
integer);
 16          procedure randnum (str out varchar2, len in integer);
 17          procedure randlastname (str out varchar2, id in integer);
 18          function NURand (A in integer, x in integer, y in integer,
 19                          cnum in integer) return integer;
 20* end tpccrand;
SQL> show errors;
Errors for PACKAGE TPCCRAND:

LINE/COL ERROR

-------- -----------------------------------------------------------------
7/18     PLS-00492: variable or constant initialization may not refer to
         functions declared in the same package

7/18     PL/SQL: Declaration ignored


meaning you cannot initialize lastname in the spec. We must do that in the body. So, we will record the spec as:

  1 create or replace package tpccrand is   2 --

  3          type Tperm is varray (3000) of integer;
  4          randperm3000 Tperm;
  5  --
  6     type TlastName is varying array (10) of varchar2(10);
  7          lastname TlastName;
  8     /*
  9          lastname TlastName :=
 10        TlastName( 'BAR',   'OUGHT', 'ABLE', 'PRI',
 11                    'PRES',  'ESE',   'ANTI', 'CALLY',
 12                    'ATION', 'EING'
 13                  );
 14     */
 15  --
 16          procedure initperm;
 17          procedure randstr (str in out varchar2, x in integer, y in
integer);
 18          procedure randdatastr (str in out varchar2, x in integer, y in
integer);
 19          procedure randnum (str in out varchar2, len in integer);
 20          procedure randlastname (str in out varchar2, id in out integer);
 21          function NURand (A in integer, x in integer, y in integer,
 22                          cnum in integer) return integer;
 23* end tpccrand;
SQL> show errors;

I remove the initialization. ALSO i change str and id to be IN OUT (since you do READ and WRITE to them in the body below)

We put in the body code like:

SQL> create or replace package body tpccrand is

  2          procedure initperm is
  3                  pos binary_integer;
  4                  temp integer;
  5                  i binary_integer;
  6          begin
  7                  for i in 0..2999 loop
  8                          randperm3000(i) := i+1;
  9                  end loop;
 10  
 10                  for i in reverse 3000..1 loop
 11                          pos := mod(random.val(0,3000),i);
 12                          temp := randperm3000(i-1);
 13                          randperm3000(i-1) := randperm3000(pos);
 14                          randperm3000(pos) := temp;
 15                  end loop;
 16          end initperm;
 17  
 17          procedure randstr (str in out varchar2, x in integer, y in integer)
is
 18                  i binary_integer;
 19                  j binary_integer;
 20                  len binary_integer;
 21          begin
 22                  len := random.val(x,y+1);
 23                  str := '';
 24                  for i in 0..len-1 loop
 25                          j := random.val(0,62);
 26                          if j < 26 then
 27                                  str := str || chr(j + 97);
 28                          elsif j < 52 then
 29                                  str := str || chr(j + 65 - 26);
 30                          else
 31                                  str := str || chr(j + 48 - 52);
 32                          end if;
 33                  end loop;
 34          end randstr;
 35  
 35          procedure randdatastr (str in out varchar2, x in integer, y in
integer)
 36 is
 37                  i binary_integer;
 38                  j binary_integer;
 39                  len binary_integer;
 40                  pos binary_integer;
 41          begin
 42                  len := random.val(x,y+1);
 43                  str := '';
 44                  for i in 0..len-1 loop
 45                          j := random.val(0,62);
 46                          if j < 26 then
 47                                  str := str || chr(j + 97);
 48                          elsif j < 52 then
 49                                  str := str || chr(j + 65 - 26);
 50                          else
 51                                  str := str || chr(j + 48 - 52);
 52                          end if;
 53                  end loop;
 54                  if ( random.val(0,10) = 0 ) then
 55                          pos := random.val(1,len-8);
 56                          str := substr(str,1,pos-1) || 'ORIGINAL' ||
substr(str,pos+8);
 57                  end if;
 58          end randdatastr;
 59  
 59          procedure randnum(str in out varchar2,len in integer) is
 60                  i binary_integer;
 61          begin
 62                  str := '';
 63                  for i in 1..len loop
 64                          str := str || chr(48 + random.val(0,10));
 65                  end loop;
 66          end randnum;
 67  
 67          procedure randlastname (str in out varchar2,id in out integer) is
 68          begin
 69                  id := mod(id,1000);
 70                  str := lastname(id/10);
 71                  str := str || lastname( mod(id/10,10) );
 72                  str := str || lastname( mod(id,10) );
 73          end randlastname;
 74  
 74          function NURand (A in integer, x in integer, y in integer,
 75                          cnum in integer) return integer is
 76                  ta binary_integer;
 77                  tb binary_integer;
 78          begin
 79                  ta := random.val(0,A+1);
 80                  tb := random.val(x,y+1);
 81          end NURand;

 82
 82 begin
 83       lastName :=
 84        TlastName( 'BAR',   'OUGHT', 'ABLE', 'PRI',
 85                    'PRES',  'ESE',   'ANTI', 'CALLY',
 86                    'ATION', 'EING'
 87                  );

 88 end tpccrand;
 89 /

Package body created.

See, we put at the bottom some elaboration code to initialize lastname (instead in the spec). Also -- I removed the duplicate randlastname and nurand functions you had as well.

So, this now *compiles* but I don't know if it *works* :)

[snip]

>------------ cut here -------------------------------
>
>And the errors are : (sqlplus SYS/password)
>
>--------------------------------------------------------
>SQL> @tpccrand.pls
>
>Warning: Package created with compilation errors.
>
> type Tperm is varray (3000) of integer;
> *
>ERROR at line 3:
>ORA-00942: table or view does not exist
>
>
>No errors.
>
>Warning: Package Body created with compilation errors.
>
> pos binary_integer;
> *
>ERROR at line 3:
>ORA-00942: table or view does not exist
>
>
>No errors.
>--------------------------------------------------------
>
>Thanks a lot to people will be able to help me !
>
>

See http://www.oracle.com/ideveloper/ for my column 'Digging-in to Oracle8i'...  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Service Industries
Reston, VA USA

--
Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Thu May 27 1999 - 11:03:41 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US