OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V3.2.4Enterprise Edition

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V3.2.4
    iconOceanBase Database
    SQL - V 3.2.4Enterprise Edition
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Assign values

    Last Updated:2023-10-24 09:23:03  Updated
    Share
    What is on this page
    Use value assignment statements to assign values to variables
    Use the SELECT INTO statement to assign values to variables
    Assign values to variables that are passed to subprograms as parameters
    Assign values to BOOLEAN variables

    folded

    Share

    After you declare variables, you can assign values to the variables by using different methods.

    Use one of the following methods to assign values:

    • Use the value assignment statement to specify values of expressions for variables.

    • Use the SELECT INTO or FETCH statement to assign values to variables.

    • Pass variables as OUT or IN OUT parameters to subprograms, and assign values to the variables in the subprograms.

    The data types of the variables must be compatible with those of the values. If a data type can be implicitly converted to another data type, the two data types are compatible.

    Use value assignment statements to assign values to variables

    After you declare variables, you can use value assignment statements to specify values of expressions for the variables.

    PL uses := to assign values by using the following syntax:

    variable  := expression ;
    

    variable specifies the PL variable, and expression specifies the PL expression.

    Example: Use a value assignment statement to assign a value to a variable.

    obclient> DECLARE
       pi     CONSTANT NUMBER := 3.14159;
       radius NUMBER NOT NULL := 1;
       area   NUMBER := (pi * radius**2);
    BEGIN
       DBMS_OUTPUT.PUT_LINE('The area of the circle is '||area);
    END;
    /
    Query OK, 0 rows affected
    
    The area of the circle is 3.14159
    

    In the example, the pi, radius, and area variables are declared, and initial values are specified for pi and radius. A value assignment statement is used to specify a value of an expression for the area variable.

    Use the SELECT INTO statement to assign values to variables

    You can use the SELECT INTO statement to directly assign values to variables. Value assignment will be implemented once each time the SELECT INTO statement is executed. The types of variables to which values are to be assigned must be in one-to-one mapping with the columns in SELECT.

    The SELECT INTO statement can be simplified as follows:

    SELECT select_item [, select_item ]...
    INTO variable_name [, variable_name ]...
    FROM table_name;
    

    Each select_item must have one corresponding variable_name whose type is compatible with that of select_item. SQL does not support the BOOLEAN type, so the value of variable_name cannot be of the BOOLEAN type.

    Example: Use the SELECT INTO statement to assign values to variables.

    obclient> CREATE TABLE employees(
       employee_id    NUMBER(4,0),  
       name           VARCHAR(10),  
       salary         NUMBER(7,2)
      );
    Query OK, 0 rows affected
    
    obclient> INSERT INTO employees (employee_id,name,salary)VALUES(105,'Sam Smith',15000);
    Query OK, 1 row affected
    
    obclient> DECLARE
        emp_id      employees.employee_id%TYPE :=105;
        emp_name    employees.name%TYPE;
        wages       employees.salary%TYPE;
     BEGIN
        SELECT name, NVL(salary,0) INTO emp_name, wages
        FROM employees WHERE employee_id = emp_id;
        DBMS_OUTPUT.PUT_LINE(emp_name||'----'||to_char(wages));
     END;
     /
    Query OK, 0 rows affected
    
    Sam Smith----15000
    

    Assign values to variables that are passed to subprograms as parameters

    If you pass a variable as an OUT or IN OUT parameter to a subprogram and the subprogram has assigned a value to the parameter, the value retains after the variable is executed in the subprogram.

    Example: Assign a value to a variable that is passed to a subprogram as a parameter.

    obclient> DECLARE
      wages   employees.salary%TYPE;
    
      PROCEDURE new_salary (
        emp_id        employees.employee_id%TYPE :=105,
        salary    IN OUT NUMBER,
        add_salary    NUMBER
      ) IS
      BEGIN
        salary := salary + add_salary;
      END;
    
    BEGIN
      SELECT salary INTO wages
      FROM employees
      WHERE employee_id = 105;
    
      DBMS_OUTPUT.PUT_LINE
       ('The original wages is ' || wages);
    
      new_salary (105, wages, 1000); -- Call the procedure
    
      DBMS_OUTPUT.PUT_LINE
       ('The new wages is ' || wages);
    END;
    /
     Query OK, 0 rows affected
    
    The original wages is 15000 -- Before the procedure is called
    The new wages is 16000 -- After the procedure is called
    

    Assign values to BOOLEAN variables

    BOOLEAN values support logic operations. BOOLEAN variables can be set only to TRUE, FALSE, or NULL.

    Example: Assign a value to a BOOLEAN variable.

    obclient> DECLARE
      done BOOLEAN;     -- By default, the initial value is NULL.
    BEGIN
        done := FALSE;  -- Specify the value of the literal.
        WHILE NOT done LOOP
            Null;
            done := TRUE;
        END LOOP;
    END;
    /
    

    Previous topic

    Scope and visibility of identifiers
    Last

    Next topic

    Expressions
    Next
    What is on this page
    Use value assignment statements to assign values to variables
    Use the SELECT INTO statement to assign values to variables
    Assign values to variables that are passed to subprograms as parameters
    Assign values to BOOLEAN variables