I. constants and variables
Before getting started, let's make a classic example as follows:
Declare mydate varchar2 (16): = 'hellow world'; begin dbms_output.put_line (mydate); end;
Declare is declaration part
In this section, I declare the varchar2 type variable named mydata. The content is hellow world and the length is 16.
Begin .... The end part is the execution part.
Here I called the existing Oracle process dbms_output.put_line, which started to print.
After the execution, the variables I just defined are printed.
Note that PL/SQL is case-insensitive like T-SQL
I use PL/SQL developer to execute the aboveProgram(If necessary, introduce Oracle Installation, basic operations, and related tools)
The following two figures are shown:
You can declare Constants by using the constant keyword, such:
Mydate constant varchar2 (16): = 'hellow world ';
Ii. Data Types (incomplete)
1: Number (P, S) declares a number
P indicates the precision. That is, there are several digits in the number. The value of P is 1 ~ 38
S indicates the scale, that is, the decimal point of this number is in the nth digit (from right to left), and s value is-84 ~ 127
Both parameters are optional,
The scale can be a negative number, for example:
Mydate number (6,-2): = 123456;
The output of this variable is: 123500. As you can see, he is rounded up.
Note:
Mydate number (6, 2): = 1234.123456;
As shown above, the number of assignments obviously exceeds the precision, but can be successfully executed. The obtained variable is
1234.12, precision is 6. It also plays a role in rounding
Do not try to do this:
Mydate number (6, 2): = 123456.123456;
Because the system does not meet the precision requirements.
2: Char (n) is used to define a string of fixed length.
N indicates the length. N cannot exceed 2000. It is an optional parameter.
If you define N, but the stored string length is smaller than N,Then the system will fill you with spaces
3: varchar2 (n) is used to define a variable-length string.
N is required, indicating the maximum length of the string. The value range is 1 ~ 32767
You defined a varchar2 data with a smaller length than N,The system will not fill you with spaces!
4: Boolean defines logical variables
Optional values: True, false, and null.
5: Date defines the date data
Contains only the date, 4712 BC to 9999 AD, generally does not exceed the limit
7 bytes
6: Timestamp (s) or date data
Storage year, month, day, hour, minute, second, morning, afternoon
S indicates the number of decimal places in seconds, ranging from 0 ~ Value Range: 9
7: Lob storage file
Blog: Mainly used to store image files
Clob: Mainly used to store text files
Bfile: Mainly used for audio and video files
No more than 4 GB for all files