Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6720043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:09:53+00:00 2026-05-26T09:09:53+00:00

I am new in PL/SQL. I have a problem with loop in this language.

  • 0

I am new in PL/SQL. I have a problem with loop in this language. I’ d like to make loop like this:

FOR nr IN 1..102 
LOOP
  DBMS_OUTPUT.PUT_LINE(nr);
  IF rec.column_||nr IS NULL
    THEN
    DBMS_OUTPUT.PUT_LINE('test');
  END IF;
END LOOP;

I have created a cursor. As you can see I’ d like to check all column with names column from column_1 to column_102. Unfortunately || operator does not work for this situation.
Do you know some solution to my problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:09:54+00:00Added an answer on May 26, 2026 at 9:09 am

    You can do this with dynamic PL/SQL. Use an EXECUTE IMMEDIATE statement to execute a string argument as PL/SQL, which you can make up with || as it was intended in the question.

    Example:

    BEGIN 
        FOR nr IN 1..102 
        LOOP
            DBMS_OUTPUT.PUT_LINE(nr);
            EXECUTE IMMEDIATE 
                'BEGIN ' || 
                'IF rec.column.' || nr ||' is null THEN ' ||
                    'DBMS_OUTPUT.PUT_LINE(''test''); ' ||
                'END IF; ' || 
                'END; ';
        END LOOP;
    END;
    

    Or you could also assign rec.column.' || nr ||' is null to a variable and make the PUT_LINE outside the EXECUTE IMMEDIATE part:

    UPDATE: It seems it is not possible to bind BOOLEAN variables, so I’ve modified the example to use a NUMBER.

    UPDATE 2: There is a possible efficiency improvement, altough maybe not suitable in this case. Use a constant VARCHAR for the dynamic SQL, and pass in nr with a binded variable. This is even more efficient than using native SQL if in a large loop. I don’t think 'rec.column.:arg is null would execute as 'rec.column.1 is null, though.

     DECLARE
        isnull NUMBER;
     BEGIN 
        FOR nr IN 1..102 
        LOOP
            DBMS_OUTPUT.PUT_LINE(nr);
            EXECUTE IMMEDIATE 
                'BEGIN ' || 
                    'IF rec.column.' || nr ||' IS NULL THEN ' || 
                        ':x:=1; ' || 
                    'ELSE ' ||
                        ':x:=0; ' ||
                    'END IF; ' ||
                'END; ' 
                USING OUT isnull;
            IF isnull = 1 THEN 
                DBMS_OUTPUT.PUT_LINE('test');
            END IF;
        END LOOP;
    END;
    

    UPDATE 3:
    Seeing that:

    • It is not possible to access rec inside the dynamic SQL statement because it is undefined (out of scope),

    • It seems not possible to pass a non-sql type as an argument to the dynamic statement (record, cursor)

    A possible workaround is to bind some id columns (SQL Type) to the dynamic statement, and use a select clause to find out if the current column is null:

    DECLARE
            isnull NUMBER;
            rec_id NUMBER; -- Identifier of the fetched record
         BEGIN 
            rec_id := rec.id;
            FOR nr IN 1..102 
            LOOP
                DBMS_OUTPUT.PUT_LINE(nr);
                EXECUTE IMMEDIATE 
                    'SELECT 1 FROM my_table WHERE id = :idarg ' ||
                       ' AND column_' || nr || ' IS NULL'
                  INTO isnull USING rec_id;
                IF isnull = 1 THEN 
                    DBMS_OUTPUT.PUT_LINE('test');
                END IF;
            END LOOP;
        END;
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to python and have hit a problem with an SQL query I'm
Hi I'm very new to sql but have been passed a job in which
I'm a bit new to SQL and have trouble constructing a select statement. I
I have SQL server 2000 dev edition. But it isn't compatible with my new
I am totally new to SQL . I have a simple select query similar
I am new to SQL Server, and I have been tasked with setting permissions
I'm pretty new to SQL. I have a database with records based on road/milepoints.
I'm brand new to SQL Server 2008, and have some newbie questions about the
I am pretty much new to using SQL Server 2000. I have been using
I have the following transaction: SQL inserts a 1 new record into a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.