Already have an account? Get multiple benefits of using own account!
Login in your account..!
Remember me
Don't have an account? Create your account in less than a minutes,
Forgot password? how can I recover my password now!
Enter right registered email to receive password!
Manipulating Individual ElementsFaraway you have manipulated an entire collection. Within the SQL, to manipulate the individual elements of the collection, and then use the operator TABLE. The operand of TABLE is a subquery which returns a single column value for you to manipulate. That the value is the nested table or the varray.In the illustration below, you add a row to the History Department nested table stored in the column courses:BEGININSERT INTOTABLE(SELECT courses FROM department WHERE name = ’History’)VALUES(3340, ’Modern China’, 4);END;In the next illustration, you revise the number of credits for two courses offered by the Psychology Department:DECLAREadjustment INTEGER DEFAULT 1;BEGINUPDATE TABLE(SELECT courses FROM departmentWHERE name = ’Psychology’)SET credits = credits + adjustmentWHERE course_no IN (2200, 3540);END;In the following illustration, you retrieve the number and the title of a specific course offered by the History Department:DECLAREmy_course_no NUMBER(4);my_title VARCHAR2(35);BEGINSELECT course_no, title INTO my_course_no, my_titleFROM TABLE(SELECT courses FROM departmentWHERE name = ’History’)WHERE course_no = 3105;...END;In the next illustration, you delete all 5-credit courses offered by the English Department:BEGINDELETE TABLE(SELECT courses FROM departmentWHERE name = ’English’)WHERE credits = 5;END;In the following illustration, you recover the title and cost of the Maintenance Department’s fourth project from the varray column projects:DECLAREmy_cost NUMBER(7,2);my_title VARCHAR2(35);BEGINSELECT cost, title INTO my_cost, my_titleFROM TABLE(SELECT projects FROM departmentWHERE dept_id = 50)WHERE project_no = 4;...END;Presently, you cannot reference the individual elements of a varray in an UPDATE, INSERT, or DELETE statement. And hence, you should use the PL/SQL procedural statements. In the illustration below, the stored procedure add_project inserts a new project into the department’s project list at a given position a shown:CREATE PROCEDURE add_project (dept_no IN NUMBER,new_project IN Project,position IN NUMBER) ASmy_projects ProjectList;BEGINSELECT projects INTO my_projects FROM departmentWHERE dept_no = dept_id FOR UPDATE OF projects;my_projects.EXTEND; -- make room for new project/* Move varray elements forward. */FOR i IN REVERSE position..my_projects.LAST - 1 LOOPmy_projects(i + 1) := my_projects(i);END LOOP;my_projects(position) := new_project; -- add new projectUPDATE department SET projects = my_projectsWHERE dept_no = dept_id;END add_project;The stored procedure updates below for a given project is:CREATE PROCEDURE update_project (dept_no IN NUMBER,proj_no IN NUMBER,new_title IN VARCHAR2 DEFAULT NULL,new_cost IN NUMBER DEFAULT NULL) ASmy_projects ProjectList;BEGINSELECT projects INTO my_projects FROM departmentWHERE dept_no = dept_id FOR UPDATE OF projects;/* Find project, update it, then exit loop immediately. */FOR i IN my_projects.FIRST..my_projects.LAST LOOPIF my_projects(i).project_no = proj_no THENIF new_title IS NOT NULL THENmy_projects(i).title := new_title;END IF;IF new_cost IS NOT NULL THENmy_projects(i).cost := new_cost;END IF;EXIT;END IF;END LOOP;UPDATE department SET projects = my_projectsWHERE dept_no = dept_id;END update_project;
Transaction Visibility As the figure shows, the changes made by an autonomous transaction become visible to another transaction whenever the autonomous transaction commits. Th
Keyword & Parameter Description: PRAGMA: These keywords signify that the statement is a pragma (i.e. compiler directive). The Pragmas are processed at the compile time, n
Data Types in SQL - Character CHARACTER or, synonymously, CHAR, for character strings. When this type is to be the declared type of something (e.g., a column), the permissible
Need for Dynamic SQL: You need dynamic SQL in the situations as follows: 1) You would like to execute a SQL data definition statement (like CREATE), a data control statemen
Semidifference via EXCEPT and JOIN - SQL SELECT * FROM (SELECT StudentId FROM IS_CALLED WHERE Name = 'Devinder' EXCEPT DISTINCT CORRESPONDING SELECT StudentId
Using the BULK COLLECT Clause The keywords BULK COLLECT specify the SQL engine to bulk-bind output collections before returning them to the PL/SQL engine. You can use these ke
Comparison Operators Usually, you use the comparison operators in the WHERE clause of a data manipulation statement to form the predicates, that compare one expression to anot
Joining in SQL Joining IS_CALLED and IS_ENROLLED_ON in SQL SELECT * FROM IS_CALLED NATURAL JOIN IS_ENROLLED_ON This is an example of an SQL table expression. I have been
Object Types An object type is a user-defined complex datatype which encapsulates the data structure along with the functions and procedures required to manipulate the data. Th
Write a query to find academics that are authors and that have only ever coauthored papers with authors from institutes in the same state as their own. List their academic number,
Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!
whatsapp: +1-415-670-9521
Phone: +1-415-670-9521
Email: [email protected]
All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd