Select * from v$Parameter where name like 'undo%'; -- the value needs to be
AUTO -- and undo retention value is in seconds, thats the time allowed to undo
2. temporal validity
exec DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME('ALL');
exec DBMS_FLASHBACK_ARCHIVE.ENABLE_AT_VALID_TIME('CURRENT');
First execution takes normal time, Sus sequent execution will not take time.
4. Column Update Mystery - Update one column and automatically update another
column
Use Virtual Column -
column_name varchar2(20) GENERATED ALWAYS AS ( CAST(get_char(col1) as
varchar2(20) ) )
-----------------------------------------------------------------------------------
-----
https://www.youtube.com/watch?v=SxEQbz8tOwU
1. Use the benefits of RESULT CACHE -- /*+ result_cache */
9. Use correlation ids when performing joins, even on columns where they are not
required.
10. Analyze joins one by one and check that their use makes sense in each
circumstance
15. When creating multi column index, choose an optimal order of the columns
18. Follow SQL and PL/SQl standards. Have a document and code reviews
-----------------------------------------------------------------------------------
-----
Oracle PL/SQL Best Practices Part 1
https://www.youtube.com/watch?v=IvsVGaTuHhY
2. Instead of
CURSOR r1 is
SELECT ....
FOR UPDATE;
BEGIN
FOR v_rec IN r1 LOOP
IF ...
UPDATE ...
END IF;
END LOOP;
COMMIT;
END;
Use this...
CURSOR r1 is
SELECT ....
FOR UPDATE OF e.sal; <---------------
BEGIN
FOR v_rec IN r1 LOOP
IF ...
UPDATE emp SET sal ...
END IF;
END LOOP;
COMMIT;
END;
3. Instead of
v_name VARCHAR2(200);
USe this...
v_name emp.name%TYPE; <---------------
v_rec emp%ROWTYPE; <---------------
4. Instead of
SELECT SYSDATE INTO v_date FROm dual;
USe this...
v_date := SYSDATE; <---------------
Consider using SELECt ...BULK COLLECT and FORALL type statements to reduce
context switches.
5. Instead of
While looping collections
i := i +1;
USe this...
i := v_num.next(i); <---------------
6. Instead of
BEGIN
INSERT INTO dept VALUES(88,'hr',44500);
COMMIT;
EXCEPTION
WHEN others THEN
dbms_output.put_line(SQLCODE);
END;
Use this...
DECLARE
v_2291_error EXCEPTION; <---------------
PRGMA EXCEPTION_INIT(v_2291_error,-2291); <---------------
BEGIN
INSERT INTO dept VALUES(88,'hr',44500);
COMMIT;
EXCEPTION
WHEN v_2291_error THEN
dbms_output.put_line(SQLCODE);
END;
7. Instead of
DECLARE
TYPE v_nums IS TABLE OF emp.sal%TYPE
INDEX BY binary_integer;
v_new_sals v_nums;
BEGIN
UPDATE emp SET sal = sal * 1.1;
SELECT sal BULK COLLECt INTO v_new_sals FROM emp;
END;
Use this...
DECLARE
TYPE v_nums IS TABLE OF emp.sal%TYPE
INDEX BY binary_integer;
v_new_sals v_nums;
BEGIN
UPDATE emp SET sal = sal * 1.1
RETURNING sal BULK COLLECT INTO v_new_sals; <---------------
END;
-----------------------------------------------------------------------------------
-----
https://www.youtube.com/watch?v=PeXMOX1kxSU
1. Top-n Queries
Row limiting clause
FETCH FIRST/NEXT and OFFSET cluses
Retrive frist n records from a result set
Retrive the first n records after skipping over a set of records
ANSI standard
SELECt * FROM
(SELECT * FROM daily
ORDER BY att) WHERE rownum <= 5;
5. OFFSET, FETCH NEXT - When you need next 3 records afte 5 rows
...
)
arep;
Ex 2: Find patterns where the same credit card number was used physically in 2
different locations on the same day.
9. Invisible Columns:
Statements that do not directly reference the invisible column will not see
that column
Columns can be made invisible when using CREATE TABLE, CREATE VIEW, ALTER
VIEW, ALTER TABLE
Benefits: The ability to introduce a change while minimizing any negative
side effects of that change
Cascading TRUNCATE
TRUNCATE TABLE tname CASCADE;
Identity Columns
CREATE TABLE tname
(trans_id NUMBER GENERATED AS identity PRIMARY KEY,
trans_date DATE);
DBMS_UTILITY
UTL_CALL_STACK program
DBMS_SCHEDULER
2 new job types
SQL_SCRIPT
BACKUP_SCRIPT
Granting a role to a PLSQL program