DATA MANIPULATING THROUGH PL/SQL:
a) The data in the database is manipulated using the DML Commands.
b) The DML Commands INSERT, UPDATE and DELETE can be used in PL/SQL without any restrictions.
c) The Row Locks and Table Locks in the database are released using the COMMIT and ROLLBACK.
INSERTING DATA:
a) The SQL INSERT Statement is used as it exists, in the PL/SQL Block.
b) We can use SQL functions, like USER and SYSDATE as per requirements.
c) The PRIMARY KEY values can be generated using the database sequences.
d) Derive values within the PL/SQL Block as per necessity.
e) Add Column default values if any.
f) Any Identifiers in INSERT Clause must be an Database Column Name only, avoiding ambiguity.
Example:
SQL> BEGIN
INSERT INTO Emp(Empno, EName,Job,Deptno,MGR,Sal)
VALUES (Empsequence.NEXTVAL,'SATISH','MANAGER',10,7654,5000);
END;
UPDATING DATA:
a) The Data Updation is an similar to the UPDATE statement used in SQL.
b) A small amount of Ambiguity can arise in the SET clause of the UPDATE statement, as the identifier on the right side of the assignment operates can be a PL/SQL variable, or another database column.
c) In the SET clause, the identifier on the left is always a database column.
d) It is always better to implement a WHERE clause to that the required rows only are UPDATED.
e) If any rows are not updated, then no errors is returned.
f) A point to note this state is
* PL/SQL Variable Assignement use:=.
* SQL Column Assignement uses=.
Example:
Sql > DECLARE
V_EmpNo%TYPE:=&EmpNo;
V_Asterisk Emp.States%TYPE:=NULL;
CURSOR EmpCursor IS
SELECT EmpNo, Nvl(ROUND(Sal/100),0) Sal FROM EmpNo=V_EmpNo FOR UPDATE;
BEGIN
FOR EmpRecord IN EmpCursor
LOOP
FOR MyIndex IN 1...EmpRecord.Sal
LOOP
V_Asterisk:=V_Asterisk||'*';
END LOOP;
UPDATE Emp Set States= V_Asterisk
WHERE CURRENT OF EmpCursor;
V_Asterisk:=NULL;
END LOOP;
COMMIT;
END;
[8:20 PM
|
0
comments
]



0 comments
Post a Comment
Do comment to make this blog better