Tuesday, August 27, 2013

Oracle 11g new features

select /*+ result_cache */ state_code,count(*) ...
In PL/SQL:
return sales_tax_rate.tax_rate%type  
result_cache
relies_on (sales_tax_rate, customers)
is
l_ret   sales_tax_rate.tax_rate%type;
begin
Notice the clause "relies on" in the function code. It tells the function that the cache depends on those two tables: customers and tax_rate.
If the data in those tables change, the cache needs to be refreshed. The refresh happens automatically without your intervention. If the data
does not change, the cache continues to provide the cached values as quickly as possible. (In Oracle Database 11g Release 2, the function
knows the tables it gets the data from and automatically checks for the data change in them; the RELIES_ON clause is not necessary. The syntax
still allows the table name but it is redundant.)
The cache is for a database instance; not for a session. This ability to make caching in one session available in all others is very
different from using package variables that hold the value in memory, which are visible in a session only.
Furthermore, the package variables have no idea about the underlying table being changed. You have to manually refresh them when the data
changes; otherwise the apps will get stale data. Both SQL Result Cache and PL/SQL Function Cache automatically refresh the cache when the
underlying table data changes; no user intervention is required.

Dynamic SQL:

DBMS_SQL.PARSE(v_cursor, v_plsql, DBMS_SQL.NATIVE);
DBMS_SQL.BIND_VARIABLE(v_cursor, 'jobs', v_jobs);
DBMS_SQL.BIND_VARIABLE(v_cursor, 'empnos', v_empnos);
v_execute := DBMS_SQL.EXECUTE(v_cursor);

pivot and unpivot
SELECT deptno
FROM   emp
PIVOT (SUM(sal)
FOR    deptno IN (10,20,30,40));

No comments:

Post a Comment