PL/SQL Programming-variables

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.