Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Using INSERT, UPDATE, DELETE, and SELECT Statements With Varrays

DROP TABLE depts CASCADE CONSTRAINTS PURGE
/

DROP TYPE dnames_var
/

-- By using a varray, we put an upper limit on the number of elements
-- and ensure they always come back in the same order
CREATE TYPE dnames_var IS VARRAY(7) OF VARCHAR2(30);
/

CREATE TABLE depts (
region VARCHAR2(25),
dept_names DNAMES_VAR);

BEGIN
INSERT INTO depts
VALUES ('Europe',
Dnames_var('Shipping','Sales','Finance'));
INSERT INTO depts
VALUES ('Americas',
Dnames_var('Sales','Finance','Shipping'));
INSERT INTO depts
VALUES ('Asia',
Dnames_var('Finance','Payroll','Shipping','Sales'));
COMMIT;
END;
/

DECLARE
new_dnames DNAMES_VAR := Dnames_var('Benefits','Advertising','Contracting','Executive',
'Marketing');
some_dnames DNAMES_VAR;
BEGIN
UPDATE depts
SET dept_names = new_dnames
WHERE region = 'Europe';
COMMIT;
SELECT dept_names
INTO some_dnames
FROM depts
WHERE region = 'Europe';
FOR i IN some_dnames.FIRST.. some_dnames.LAST LOOP
dbms_output.Put_line('dept_names = '
||Some_dnames(i));
END LOOP;
END;
/



OUTPUT: Click Here
Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-