View the exhibit and examine the structure of the EMPLOYEE table.
EMPLOYEE_SEQ is an existing sequence.
Examine the following block of code:
Which statement is true about the above block of code?
A. It consists of two transactions
B. It consists of a single transaction,
C. The data is automatically committed after the block execution ends,
D. It gives an error on execution because sequences cannot be used in anonymous blocks.
Correct answer is B. All other answers can be eliminated using following code in HR sample schema.
CREATE SEQUENCE emp_seq
MINVALUE 500
MAXVALUE 1000
START WITH 500
INCREMENT BY 1
CACHE 20;
SQL> select count(*) from employees;
COUNT(*)
———-
107
begin
begin
insert into employees (employee_id,first_name,last_name,email,
hire_date, job_id, salary)
values (emp_seq.nextval,’Ruth’,’Cores’,’RCORES’,current_date,’AD_ASST’,4000);
end;
begin
insert into employees (employee_id,first_name,last_name,email,
hire_date, job_id, salary)
values (emp_seq.nextval,’Tom’,’Jones’,’TJONES’,current_date,’AC_MGR’,6000);
end;
end;
/
SQL> select count(*) from employees;
COUNT(*)
———-
109
SQL> rollback;
Rollback complete.
SQL> select count(*) from employees;
COUNT(*)
———-
107