Multi-field assignment for Oracle and SQL SERVER

Source: Internet
Author: User

  1. Create TableTablea (idInt, IpVarchar(15), appsVarchar(10 ))
  2. Insert IntoTableaSelect23,'2017. 0.0.1','Aaa'
  3. Go
  4. Declare@ Variable1Varchar(15), @ Variable2Varchar(10)
  5. Select@ Variable1 = ip, @ Variable2 = appsFromTableaWhereId = 23
  6. Select@ Variable1, @ Variable2
  7. /*
  8. -------------------------
  9. 127.0.0.1 aaa
  10. (One row is affected)
  11. */
  12. Go
  13. Drop TableTablea
The multi-character value assignment method of SQLSERVER is as shown above. You can directly SELECT

However, in Oracle PLSQL, select into can only assign values to a single variable, but cannot assign values to multiple variables at the same time.

For example, select count (*) into nb_count from t_khz where fzbh = V_fzbh;

Multi-variable value assignment generally adopts the cursor FETCH method:

  1. CursorC_rwIs
  2. Select*FromT_kh
  3. R_rw c_rw % rowtype;
  4. OpenC_rw;
  5. Loop
  6. FetchC_rwIntoR_rw;
  7. ExitWhenC_rw % notfound;
  8. Dbms_output.put_line (r_r1_khbh |''| R_r1_khxm |''| R_rw.yzbm );
  9.  EndLoop;
  10. CloseC_rw;
Another way is to use ROWTYPE.
  1. -- Local variables here
  2. IInteger;
  3. V_kh t_kh % rowtype;
  4. Gin
  5. -- Test statements here
  6. Select*IntoV_khFromT_khWhereRownum = 1;
  7. Dbms_output.put_line (v_kh.khbh |''| V_kh.khxm |''| V_kh.yzbm );
  8. D;

For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12

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.