Oracle uses%type-type variables to output results

Source: Internet
Author: User

Use the%type keyword to declare a data type that is the same as the specified column name, which is usually followed by the specified column name.

2 Benefits of using%type:

1. Users do not have to look at the data types of individual columns in the table to ensure that the defined variables can store the retrieved data.

2. If the data type of a column in a table changes, as long as the field name does not change, the user does not have to consider changing the data type of the variable.
Here is a simple example:

Declarev_ename Emp.ename%Type--declaring a variable with the same type as the ename columnV_job Emp.job%Type--declaring variables with the same type as the job columnbegin   SelectEname,job intoV_ename,v_job fromEMPwhereEmpno=7369;--retrieving data and saving it in a variableDbms_output.put_line (v_ename||''s position is'||V_job);--Output ResultsEnd;

The output results are as follows:

Smith's job is clerk.

In the process of use should pay attention to:

Since the variables in the INTO clause can only store a single value, it is required that the clause returned by select can only be a row of data, which is qualified by the WHERE clause, and if multiple rows of data are returned, the code runs with an error.

Oracle uses%type-type variables to output results

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.