Sql> Declare 2C_tax_rate Number(3,2):=0.03; 3V_namevarchar2( -); 4v_passwdvarchar2( -); 5V_sale Number(7,2); 6V_tax_sale Number(7,2); 7 begin 8 SelectName,passwd,salary intoV_name,v_passwd,v_sale fromMyTestwhereId=&INPT; 9V_tax_sale:=V_sale*c_tax_rate;TenDbms_output.put_line ('Name:'||V_name||'passwd:'||v_passwd||'Taxsale:'||V_tax_sale); One End; A /Name:123passwd123Taxsale:3PL/SqlprocedureSuccessfully completed
When declaring a variable, you can set the type of the field in the table to be dynamic.
Sql> Insert intoMyTestValues('4','125555','passwd',' -'); 1Row inserted SQL> Select * frommytest; ID NAME PASSWD SALARY----- -------------------- -------------------- --------------------------------------------------------------- -----------------1 123 123 -2Gaodingle!!!!123 -3Gagaga123 -4 125555passwd -SQL>SQL> Declare 2C_tax_rate Number(3,2):=0.03; 3V_namevarchar2(4); 4v_passwdvarchar2( -); 5V_sale Number(7,2); 6V_tax_sale Number(7,2); 7 begin 8 SelectName,passwd,salary intoV_name,v_passwd,v_sale fromMyTestwhereId=&INPT; 9V_tax_sale:=V_sale*c_tax_rate;TenDbms_output.put_line ('Name:'||V_name||'passwd:'||v_passwd||'Taxsale:'||V_tax_sale); One End; A / Declarec_tax_rate Number(3,2):=0.03; V_namevarchar2(4); V_PASSWDvarchar2( -); V_sale Number(7,2); V_tax_sale Number(7,2);beginSelectName,passwd,salary intoV_name,v_passwd,v_sale fromMyTestwhereId=4; V_tax_sale:=V_sale*C_tax_rate;dbms_output.put_line ('Name:'||V_name||'passwd:'||v_passwd||'Taxsale:'||V_tax_sale);End; ORA-06502: PL/SQL: Numeric or value error: String buffer too small ora-06512: On line9SQL>SQL> Declare 2C_tax_rate Number(3,2):=0.03; 3V_name Mytest.name%type; 4v_passwdvarchar2( -); 5V_sale Number(7,2); 6V_tax_sale Number(7,2); 7 begin 8 SelectName,passwd,salary intoV_name,v_passwd,v_sale fromMyTestwhereId=&INPT; 9V_tax_sale:=V_sale*c_tax_rate;TenDbms_output.put_line ('Name:'||V_name||'passwd:'||v_passwd||'Taxsale:'||V_tax_sale); One End; A /Name:125555PASSWD:PASSWD Taxsale:1.5PL/SqlprocedureSuccessfully completed
Sql> Declare 2 --defining a PL/SQL record type called Test_record_type can be understood as defining a class that includes the Name,passwd,salary 3Type Test_record_type isRecord (name Mytest.name%TYPE,PASSWD mytest.passwd%Type,salary_gaga mytest.salary%type); 4 --Define a variable This variable is a test_record_type type like the class new object 5Sp_record Test_record_type; 6 begin 7 SelectName,passwd,salary intoSp_record fromMyTestwhereId=&INPT; 8Dbms_output.put_line ('Name:'||Sp_record.name||'Salary:'||Sp_record.salary_gaga); 9 End; Ten /Name:123Salary -
Sql> Declare 2Type sp_test_table is Table ofMytest.name%TypeIndex byBinary_integer; 3test_table sp_test_table; 4 begin 5 SelectName intoTest_table (0) fromMyTestwhereId=&INPT; 6Dbms_output.put_line ('Name:'||Test_table (0)); 7 End; 8 /Name:gagaga PL/SqlprocedureSuccessfully completed
PL/SQL Programming-variables