0

Creating a virtual column whose value is computed using other 3 columns -

CREATE TABLE emp (
  id          NUMBER,
  comm1       number,
  comm2       number,
  comm3       number,
  comm4        number GENERATED ALWAYS AS
                
((comm1 - bitand(comm1, comm2) + comm2) - bitand((comm1 - bitand(comm1, comm2) + comm2),comm3)+comm3)  VIRTUAL,
              
  CONSTRAINT employees_pk PRIMARY KEY (id)
); 

if i insert-

INSERT INTO emp (id,comm1, comm2,comm3)
VALUES (3, 1,1,1);

Column comm4 get value of 1, i want 0 how can i invert it.

Harasha
  • 1
  • 1

1 Answers1

1

We can invert 0 to 1 and 1 to 0 if we use a module operator, but I think you have to work in your logical expression, I can't understand because I don´t know the context

there is a one solution for you:

CREATE TABLE emp (
  id          NUMBER,
  comm1       number,
  comm2       number,
  comm3       number,
  comm4        number GENERATED ALWAYS AS  ( mod ( 1 , ((comm1 - bitand(comm1, comm2) + comm2) - bitand((comm1 - bitand(comm1, comm2) + comm2),comm3)+comm3) ) ) VIRTUAL,
  CONSTRAINT employees_pk PRIMARY KEY (id)
)
Jose Jimenez
  • 41
  • 1
  • 4