आप उपयोग कर सकते हैं COALESCE( salary_history, salary_list() ) MULTISET UNION ALL salary_list( :your_new_value )
पुरानी सूची में नया मान जोड़ने के लिए (या यदि यह मौजूद नहीं है तो एक नई सूची बनाएं)।
Oracle 11g R2 स्कीमा सेटअप :
CREATE OR REPLACE TYPE salary_list AS TABLE OF NUMBER;
/
CREATE TABLE employees(
id NUMBER,
salary_history salary_list
) NESTED TABLE salary_history STORE AS salary_history_tab
/
INSERT INTO employees VALUES ( 1, NULL )
/
क्वेरी 1 :
UPDATE employees
SET salary_history = COALESCE( salary_history, salary_list() )
MULTISET UNION ALL salary_list( 500 )
WHERE id = 1
SELECT * FROM employees
परिणाम :
| ID | SALARY_HISTORY |
|----|----------------|
| 1 | 500 |
प्रश्न 2 :
UPDATE employees
SET salary_history = COALESCE( salary_history, salary_list() )
MULTISET UNION ALL salary_list( 700 )
WHERE id = 1
SELECT * FROM employees
परिणाम :
| ID | SALARY_HISTORY |
|----|----------------|
| 1 | 500,700 |
क्वेरी 3 :
UPDATE employees
SET salary_history = COALESCE( salary_history, salary_list() )
MULTISET UNION ALL salary_list( 500 )
WHERE id = 1
SELECT * FROM employees
परिणाम :
| ID | SALARY_HISTORY |
|----|----------------|
| 1 | 500,700,500 |