1

I am creating a table of inetegers called 'integer_properties' from 1 to 1000 the table columns are:

integer,isPrime,isOdd,isEven,digitCount;

I want to insert records using a for loop i tried following but the error says: 'missing SELECT keyword'

BEGIN
   for k in 1..1000
   loop
      insert into integer_properties(integer,
                                     isPrime,
                                     isEven,
                                     isOdd,
                                     digitCount)
         values(k,null,null,null,null);
   end loop;
END;

It is tedious to enter 1000 numbers with DDL command without using PL/SQL block. I am trying to enter the loop variable values in the integer column. Is it possible to do that?

1 Answer 1

5

You can do it in a single query.

insert into integer_properties
select level, null, null, null, null
from dual
connect by level <= 1000;

commit;

LEVEL is a pseudocolumn used in hierarchical queries.

Your code seems fine, but using INTEGER as column name might be is causing problem. If you enclose it in double quotes, it will work fine. So, better to avoid using keywords while naming columns.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.