Search
 
SCRIPT & CODE EXAMPLE
 

SQL

PL SQL Adding elements to VARRAY from a cursor

DECLARE
    TYPE r_customer_type IS RECORD(
        customer_name customers.name%TYPE,
        credit_limit customers.credit_limit%TYPE
    ); 

    TYPE t_customer_type IS VARRAY(5) 
        OF r_customer_type;
    
    t_customers t_customer_type := t_customer_type();

    CURSOR c_customer IS 
        SELECT NAME, credit_limit 
        FROM customers 
        ORDER BY credit_limit DESC 
        FETCH FIRST 5 ROWS ONLY;
BEGIN
    -- fetch data from a cursor
    FOR r_customer IN c_customer LOOP
        t_customers.EXTEND;
        t_customers(t_customers.LAST).customer_name := r_customer.name;
        t_customers(t_customers.LAST).credit_limit  := r_customer.credit_limit;
    END LOOP;

    -- show all customers
    FOR l_index IN t_customers .FIRST..t_customers.LAST 
    LOOP
        dbms_output.put_line(
            'The customer ' ||
            t_customers(l_index).customer_name ||
            ' has a credit of ' ||
            t_customers(l_index).credit_limit
        );
    END LOOP;

END;
/
Code language: SQL (Structured Query Language) (sql)
Comment

PREVIOUS NEXT
Code Example
Sql :: suhaib 
Sql :: r dbConnect(odbc::odbc() to ms sql server remote 
Sql :: setval postgres example table id 
Sql :: grepper sql workbench download 
Sql :: get who is hired in month in sql 
Sql :: mamp mysql config file 
Sql :: remove an object that is dependent on a column in sql 
Sql :: how to add column with custom sequence in postgresql 
Sql :: fill column postgresql 
Sql :: PostgresDownload 
Sql :: create synonym for dblink in oracle 
Sql :: expose db in virtualbox 
Sql :: alter server set options dbserver oracle fdw 
Sql :: sql how to get courses that i have made prerequisites 
Sql :: okta postgresql 
Sql :: alter tablespace undotbs1 add datafile 
Sql :: dynamic where clause in sql server stored procedure 
Sql :: oracle create chain rule 
Sql :: SQL Server log file truncate - Source :NAYCode.com 
Sql :: sql workbench 
Sql :: c# execute transact sql 
Sql :: mysql clone table with data and add attribute 
Sql :: SQL DATEADD(date_part, number, date) 
Sql :: set mysql socket file docker windows 
Sql :: read_sql mysql 
Sql :: sql restore database from bak file 
Sql :: compare strings lexicographically in sql 
Sql :: mysql-split-and-join-the-values 
Sql :: sql column as header 
Sql :: tsql remove duplicate rows 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =