PLSQL: %TYPE x %ROWTYPE

inicial › Forums › Database › PLSQL › PLSQL: %TYPE x %ROWTYPE

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2292612
    matheusdba
    Keymaster

    What is the difference between %TYPE and %ROWTYPE?

    #2292613
    matheusdba
    Keymaster

    Both %TYPE and %ROWTYPE are used to define variables in PL/SQL as it is defined within the database. If the datatype or precision of a column changes, the program automatically picks up the new definition from the database without having to make any code changes.

    The %TYPE and %ROWTYPE constructs provide data independence, reduces maintenance costs, and allows programs to adapt as the database changes to meet new business needs.

    %TYPE
    %TYPE is used to declare a field with the same type as that of a specified table’s column. Example:

    DECLARE
    v_EmpName emp.ename%TYPE;
    BEGIN
    SELECT ename INTO v_EmpName FROM emp WHERE ROWNUM = 1;
    DBMS_OUTPUT.PUT_LINE('Name = ' || v_EmpName);
    END;
    /

    %ROWTYPE
    %ROWTYPE is used to declare a record with the same types as found in the specified database table, view or cursor. Examples:

    DECLARE
    v_emp emp%ROWTYPE;
    BEGIN
    v_emp.empno := 10;
    v_emp.ename := 'XXXXXXX';
    END;
    /
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.