A decimal number is a number that can have a period (or the character used as the decimal separator as set in the Control Panel) between the digits. An example would be 12.625 or 44.80. Like an integer, a decimal number can start with a + or just a digit, which would make it a positive number. A decimal number can also start with a - symbol, which would make it a negative number. If the number represents a fraction, a period between the digits specifies what portion of 1 was cut.
A floating-point number is a fractional number. To declare a variable for decimal values that do not require too much precision, use the FLOAT or REAL data type. Here is an example: SQL> DECLARE Measure FLOAT := 36.12; 2 BEGIN 3 DBMS_OUTPUT.PUT_LINE('Measure: ' || Measure); 4 END; 5 / To declare a variable for decimal values, use the NUMBER data type. A precision is the number of digits used to display a numeric value. For example, the number 42005 has a precision of 5, while 226 has a precision value of 3. If the data type is specified as an integer (the INT and its variants) or a floating-point number (FLOAT and REAL), the precision is fixed by the database and you can just accept the value set by the interpreter. The scale of a number if the number of digits on the right side of the period (or the character set as the separator for decimal numbers for your language, as specified in Control Panel). The scale is used only for numbers that have a decimal part. To control the level of precision applied on a NUMBER variable, follow the NUMBER data type by parentheses. In the parentheses, use two values separated by a comma. The left value represents the precision. The right value represents the scale. The value must be an integer between 0 and 18. Here is an example: SQL> DECLARE Measure NUMBER(8, 3) := 284636.48; 2 BEGIN 3 DBMS_OUTPUT.PUT_LINE('Measure: ' || Measure); 4 END; 5 /
A DATE data type is used for a variable whose values would consist of date and/or time values. The entries must be valid date or time values. The date value of a DATE variable can be comprised between January 1st, 4712 BC and December 31, 9999. To initialize a DATE variable, include its value between single-quote. For a date, use the following format: DD-MMM-Y or DD-MMM-YY or DD-MMM-YYYY The first number represents the day. If the number is between 1 and 9, you can omit or include a leading 0. The second section will contain the 3-letter name of the month in any case of your choice (remember that SQL is not case-sensitive). The right section contains the value of the year:
Probably to be on the safe side, you should always express the year with 4 digits. Here is an example: SQL> DECLARE DateOfBirth DATE := '06-Feb-1996'; 2 BEGIN 3 DBMS_OUTPUT.PUT_LINE('Date of Birth: ' || DateOfBirth); 4 END; 5 / Date of Birth: 06-FEB-96 PL/SQL procedure successfully completed.
A Boolean value is a piece of information stated as being true or false. To declare a Boolean variable, use the BOOLEAN type. Here is an example: DECLARE IsOrganDonor BOOLEAN; As stated previously, you can initialize the variable when declaring. Here is an example: DECLARE IsOrganDonor BOOLEAN := TRUE; To initialize the variable after declaring it, in the BEGIN...END section, access the variable and assign the desired value. Here is an example: DECLARE IsOrganDonor BOOLEAN; BEGIN IsOrganDonor := TRUE; END; / |
|
|||||||||||||||||||||
|