Home » Oracle » 1z0-151 » Which statement is true about this code?
The Orders database table uses Order_id as its primary key. You have written the following code to use in the Orders block of a form:
SELECT orders_seq.NEXTVAL
INTO :orders.order_id
FROM SYS.dual;
Which statement is true about this code?
A. If you place this Code in a trigger that fires when the record is inserted into the database, you will likely have more gaps in Order IDs than if you use the sequence as a default value for the item.
B. If you place this code in a trigger, you should ensure that Order_id has its required property set to Yes.
C. If you place this code in a trigger, you should ensure that Order_id has its Database Item property set to No.
D. If the named sequence does not exist, it is automatically created the first time the code is called.
E. You should place this code a in a database trigger to minimize the gaps in Order IDs.
F. You should place this code in Pre-insert trigger to minimize the gaps in Order IDs.
G. You should place this code in a Post_insert trigger to minimize the gaps in Order IDs.
Correct Answer: F
Explanation/Reference:
Explanation:
Assigning Sequence Numbers to Records
You will recall that you can assign default values for items from an Oracle sequence, to automatically provide unique keys for records on their creation.
However, if the user does not complete a record, the assigned sequence number is “wasted.”
An alternative method is to assign unique keys to records from a Pre-Insert trigger, just before their insertion in the base table, by which time the user has completed the record and issued the Save.
Assigning unique keys in the posting phase can:
* Reduce gaps in the assigned numbers
* Reduce data traffic on record creation, especially if records are discarded before saving
Example
This Pre-Insert trigger on the ORDERS block assigns an Order ID from the sequence ORDERS_SEQ, which will be written to the ORDER_ID column when the row is subsequently inserted.
SELECT ORDERS_SEQ.nextval
INTO :ORDERS.order_id
FROM SYS.dual;
Download Printable PDF. VALID exam to help you PASS.
|
|