1 DECLARE 2V_productid Productinfo.productid%TYPE;3V_productnameVARCHAR2( -); 4V_productprice Number(8,2); 5V_quantity Number(Ten); 6V_desperation CONSTANT V_productname%TYPE:='Test'; 7 8V_spitgr Simple_integer:= 99.9; 9V_longLONG:='Long Type Test';TenV_date DATS:=sysdate; One BEGIN A SELECTproductid,productname,productprice,quantity - intov_productid,v_productname,v_productprice,v_quantity - fromProductInfo the WHEREPro= '0240040001'; - -Dbms_output. Put_Line ('V_productid =' ||V_productid); -Dbms_output. Put_Line ('V_productname =' ||V_productname + || 'length ='||LENGTH (V_productname)); -Dbms_output. Put_Line ('V_productprice =' ||v_productprice); +Dbms_output. Put_Line ('v_quantity =' ||v_quantity); ADbms_output. Put_Line ('v_desperation =' ||v_desperation); atDbms_output. Put_Line ('V_spitgr =' ||v_spitgr); -Dbms_output. Put_Line ('V_long =' ||V_long); -Dbms_output. Put_Line ('v_date =' ||v_date); - END;
"Code parsing"
The declaration part of the statement block is in the right-justified way
Line 2nd declares a variable using the%type method, which indicates that the type of the variable V_productid is the same as the ProductID field data type in table ProductInfo
Line 3rd indicates that the data type is a VARCHAR2 type of length 20
4th ~ 5 rows are different ways of using number type
Line 6th uses%type to reference the data type of v_productname and declares a constant
The initial value of line 8th is 99.9, but since the data type can only represent integers, the value of the variable v_spitgr should be 100
11th ~ 26 Lines belong to the Executive Body part
Rows 12th to 15 indicate that data is queried from the product table and stored in a variable
The 17th ~ 25 row represents the output to the screen, which verifies that the variable stores the data
ORACLE variable definition