1

I am using the CREATE TABLE AS SELECT statement in Oracle 11g to get data from SQL Server 2012 via a database link.

Oracle creates all these tables with non-nullable columns and that causes me problems later when I try to update them.

How can I prevent this behaviour in Oracle and make resulting columns nullable?

Evan Carroll
65.7k50 gold badges259 silver badges511 bronze badges
asked Dec 30, 2015 at 11:20

1 Answer 1

2

Either create the table manually beforehand, or specify the column names an NULLability in the CTAS statement:

create table blah2 
( 
 ctascolumn1 not null,
 ctascolumn2 null
) 
as 
select col1, col2 from blah;
answered Dec 30, 2015 at 11:48
6
  • Do they end up nullable because they come from a database link or is it always the case with CTAS regardless of the source? Commented Dec 30, 2015 at 13:31
  • Always the case, as far as I know Commented Dec 30, 2015 at 13:32
  • @AndriyM: I think Oracle decides this based on the values. If a column of the query only contains non null values, the table's column is defined with NOT NULL. If at least one value in the query result is null the column is defined as NULL Commented Dec 30, 2015 at 13:48
  • @a_horse_with_no_name I doubt it. How would it know if there's a 4 Petabyte dataset? It won't scan the result set once to create, then again to insert Commented Dec 30, 2015 at 13:50
  • I'm pretty sure Oracle does scan the whole result because otherwise it won't be able to actually copy the data. But although I'm pretty sure I have seen this happening, I can't reproduce this on Oracle 12c Commented Dec 30, 2015 at 13:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.