Может ли INT-параметр иметь дробную часть? - Увы...

Elic
Дата: 01.12.2009 18:52:45
declare
  numberVar number := 2/3;
  numberVar2 number(20,10) := 4/3;
  procedure Test(Label varchar2, Value int)
  is
    LocalVar int := Value;
  begin
    dbms_output.put_line(Label || '         : ' || Value);
    dbms_output.put_line(Label || ' assigned: ' || LocalVar);
  end Test;
begin
  Test('|                 const', 1/3);
  Test('|            number var', numberVar);
  Test('|constrained number var', numberVar2);
end;
/
7.3.4, 9.2.0.8
|                 const         : .3333333333333333333333333333333333333333
|                 const assigned: 0
|            number var         : .6666666666666666666666666666666666666667
|            number var assigned: 1
|constrained number var         : 1.3333333333
|constrained number var assigned: 1
10.2.0.4, 10.2.0.3
alter session set plsql_optimize_level=0;

|                 const         : .3333333333333333333333333333333333333333
|                 const assigned: .3333333333333333333333333333333333333333
|            number var         : .6666666666666666666666666666666666666667
|            number var assigned: .6666666666666666666666666666666666666667
|constrained number var         : 1.3333333333
|constrained number var assigned: 1.3333333333
Подтипы одного и того же типа => передача фактического параметра по ссылке = преобразование округлением не выполняется. А теперь и присвоение оптимизировано.

Рушатся все мои устои ...
andrey_anonymous
Дата: 01.12.2009 19:16:12
Elic
Подтипы одного и того же типа => передача фактического параметра по ссылке = преобразование округлением не выполняется.

Мне кажется, что поведение параметра связано скорее с
declare
  procedure p(p number(38,0)) is
  begin
    null;
  end;
begin
  null;
end;
 
ORA-06550: line 3, column 23:
PLS-00103: Encountered the symbol "(" when expecting one of the following:

   := . ) , @ % default character
The symbol ":=" was substituted for "(" to continue.
чем с оптимизацией.
А вот то, что сломали присваивание - действительно печально :(
Timm
Дата: 01.12.2009 21:36:27
В 11.2.0.1 не починили.
Relic Hunter
Дата: 01.12.2009 22:04:29
Я всегда подспудно использовал PLS_INTEGER в PL/SQL. Проблема не проявляется.

Oracle® Database PL/SQL User's Guide and Reference 10g Release 2 (10.2)
Use PLS_INTEGER for Integer Arithmetic

When you need to declare a local integer variable, use the datatype PLS_INTEGER, which is the most efficient integer type. PLS_INTEGER values require less storage than INTEGER or NUMBER values, and PLS_INTEGER operations use hardware arithmetic. Note that the BINARY_INTEGER datatype is identical to PLS_INTEGER.

The datatype NUMBER and its subtypes are represented in a special internal format, designed for portability and arbitrary scale and precision, not performance. Even the subtype INTEGER is treated as a floating-point number with nothing after the decimal point. Operations on NUMBER or INTEGER variables require calls to library routines.

Avoid constrained subtypes such as INTEGER, NATURAL, NATURALN, POSITIVE, POSITIVEN, and SIGNTYPE in performance-critical code. Variables of these types require extra checking at run time, each time they are used in a calculation.
Elic
Дата: 02.12.2009 10:09:14
Relic Hunter
Я всегда подспудно использовал PLS_INTEGER в PL/SQL. Проблема не проявляется.
Hint:
Elic
Подтипы одного и того же типа
Да диапазон значений PLS_INTEGER-а "маловат".