oracle中的变量声明部分的一个简单问题
oracle中的变量声明部分declarenamechar(30);marknumber(2):='97';中number后面的2是什么意思?是数值的最大位数吗?...
oracle中的变量声明部分
declare
name char(30);
mark number(2):='97' ;
中number后面的2是什么意思?是数值的最大位数吗? 展开
declare
name char(30);
mark number(2):='97' ;
中number后面的2是什么意思?是数值的最大位数吗? 展开
3个回答
展开全部
这个的number(2)中的2指的是数字精度或者说是数字的最大长度。
如果只有数字长度而没有小数位数的话,接收的结果是一个最大为两位的整数。
declare
n1 number(2);
n2 number(2);
n3 number(2);
begin
n1 := 19.123;
n2 := 9.123;
-- n3 := 999.123; -- 这里将会报错
dbms_output.put_line(n1); -- 这里返回结果 19
dbms_output.put_line(n2); -- 这里返回结果 9
end;
NUMBER Datatype
The NUMBER datatype is used to store zero, positive and negative
fixed and floating point numbers with magnitudes between 1.0 x
10
digits of precision. If you specify an arithmetic expression whose
value has a magnitude greater than or equal to 1.0 x 10
returns an error. You can specify a fixed point number datatype
with this syntax:
NUMBER(p,s)
where:
p
is the precision, or the total number of digits. Oracle guarantees
the portability of numbers with precision ranging from 1 to 38.
s
is the scale, or the number of digits to the right of the decimal
point. The scale can range from -84 to 127.
You can also use one of these alternate forms:
NUMBER(p)
is a fixed point number with precision p and scale 0.
NUMBER
is a floating point number with precision 38. Note that a scale
value is not applicable for floating point numbers.
SCALE AND PRECISION
Specify the scale and precision of a number column for extra
integrity checking on input. Specifying scale and precision does
not force all values to a fixed length. If a value exceeds the
precision, Oracle returns an error. If a value exceeds the scale,
Oracle rounds it.
These examples show how Oracle stores data using different
precisions and scales.
Actual Data Specified as Stored as
----------- ------------ ---------
7456123.89 NUMBER 7456123.89
7456123.89 NUMBER (9) 7456124
7456123.89 NUMBER (9,2) 7456123.89
7456123.89 NUMBER (9,1) 7456123.9
7456123.8 NUMBER (6) exceeds precision
7456123.8 NUMBER (15,1) 7456123.8
7456123.89 NUMBER (7,-2) 7456100
7456123.89 NUMBER(7,2) exceeds precision
NEGATIVE SCALE
If the scale is negative, the actual data is rounded to the
specified number of places to the left of the decimal point. For
example, a specification of (10,-2) means to round to hundreds.
SCALE GREATER THAN PRECISION
You can specify a scale that is greater than precision, although it
is uncommon. In this case, the precision specifies the maximum
number of digits to the right of the decimal point. As with all
number datatypes, if the value exceeds the precision, Oracle returns
an error. If the value exceeds the scale, Oracle rounds the value.
For example, a column defined as NUMBER(4,5) requires a zero for the
first digit after the decimal point and rounds all values past the
fifth digit after the decimal point. The following examples show
the effects of a scale greater than precision:
Actual Data Specified as Stored as
----------- ------------ ---------
.01234 NUMBER(4,5) .01234
.00012 NUMBER(4,5) .00012
.000127 NUMBER(4,5) .00013
.0000012 NUMBER(2,7) .0000012
.00000123 NUMBER(2,7) .0000012
FLOATING POINT NUMBERS
Oracle also allows you to specify floating point numbers. A
floating point value either can have a decimal point anywhere from
the first to the last digit or can omit the decimal point
altogether. A scale value is not applicable to floating point
numbers because there is no restriction on the number of digits that
can appear after the decimal point.
You can specify floating point numbers with the appropriate forms of
the NUMBER datatype discussed in the section on page -. Oracle
also supports the ANSI datatype FLOAT. You can specify this
datatype using one of these syntactic forms:
FLOAT
specifies a floating point number with decimal precision 38, or a
binary precision of 126.
FLOAT(b)
specifies a floating point number with binary precision b.
The precision b can range from 1 to 126.
To convert from binary to decimal precision, multiply b by 0.30103.
To convert from decimal to binary precision, multiply the decimal
precision by 3.32193. The maximum of 126 digits of binary precision
is roughly equivalent to 38 digits of decimal precision.
如果只有数字长度而没有小数位数的话,接收的结果是一个最大为两位的整数。
declare
n1 number(2);
n2 number(2);
n3 number(2);
begin
n1 := 19.123;
n2 := 9.123;
-- n3 := 999.123; -- 这里将会报错
dbms_output.put_line(n1); -- 这里返回结果 19
dbms_output.put_line(n2); -- 这里返回结果 9
end;
NUMBER Datatype
The NUMBER datatype is used to store zero, positive and negative
fixed and floating point numbers with magnitudes between 1.0 x
10
digits of precision. If you specify an arithmetic expression whose
value has a magnitude greater than or equal to 1.0 x 10
returns an error. You can specify a fixed point number datatype
with this syntax:
NUMBER(p,s)
where:
p
is the precision, or the total number of digits. Oracle guarantees
the portability of numbers with precision ranging from 1 to 38.
s
is the scale, or the number of digits to the right of the decimal
point. The scale can range from -84 to 127.
You can also use one of these alternate forms:
NUMBER(p)
is a fixed point number with precision p and scale 0.
NUMBER
is a floating point number with precision 38. Note that a scale
value is not applicable for floating point numbers.
SCALE AND PRECISION
Specify the scale and precision of a number column for extra
integrity checking on input. Specifying scale and precision does
not force all values to a fixed length. If a value exceeds the
precision, Oracle returns an error. If a value exceeds the scale,
Oracle rounds it.
These examples show how Oracle stores data using different
precisions and scales.
Actual Data Specified as Stored as
----------- ------------ ---------
7456123.89 NUMBER 7456123.89
7456123.89 NUMBER (9) 7456124
7456123.89 NUMBER (9,2) 7456123.89
7456123.89 NUMBER (9,1) 7456123.9
7456123.8 NUMBER (6) exceeds precision
7456123.8 NUMBER (15,1) 7456123.8
7456123.89 NUMBER (7,-2) 7456100
7456123.89 NUMBER(7,2) exceeds precision
NEGATIVE SCALE
If the scale is negative, the actual data is rounded to the
specified number of places to the left of the decimal point. For
example, a specification of (10,-2) means to round to hundreds.
SCALE GREATER THAN PRECISION
You can specify a scale that is greater than precision, although it
is uncommon. In this case, the precision specifies the maximum
number of digits to the right of the decimal point. As with all
number datatypes, if the value exceeds the precision, Oracle returns
an error. If the value exceeds the scale, Oracle rounds the value.
For example, a column defined as NUMBER(4,5) requires a zero for the
first digit after the decimal point and rounds all values past the
fifth digit after the decimal point. The following examples show
the effects of a scale greater than precision:
Actual Data Specified as Stored as
----------- ------------ ---------
.01234 NUMBER(4,5) .01234
.00012 NUMBER(4,5) .00012
.000127 NUMBER(4,5) .00013
.0000012 NUMBER(2,7) .0000012
.00000123 NUMBER(2,7) .0000012
FLOATING POINT NUMBERS
Oracle also allows you to specify floating point numbers. A
floating point value either can have a decimal point anywhere from
the first to the last digit or can omit the decimal point
altogether. A scale value is not applicable to floating point
numbers because there is no restriction on the number of digits that
can appear after the decimal point.
You can specify floating point numbers with the appropriate forms of
the NUMBER datatype discussed in the section on page -. Oracle
also supports the ANSI datatype FLOAT. You can specify this
datatype using one of these syntactic forms:
FLOAT
specifies a floating point number with decimal precision 38, or a
binary precision of 126.
FLOAT(b)
specifies a floating point number with binary precision b.
The precision b can range from 1 to 126.
To convert from binary to decimal precision, multiply b by 0.30103.
To convert from decimal to binary precision, multiply the decimal
precision by 3.32193. The maximum of 126 digits of binary precision
is roughly equivalent to 38 digits of decimal precision.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询