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));

PL/SQL note

An outer join does not require each record in the two joined tables to have a matching record. The joined table retains each record
—even if no other matching record exists. Outer joins subdivide further into left outer joins, right outer joins, and full outer joins,
depending on which table's rows are retained (left, right, or both).
A left outer join returns all the values from an inner join plus all values in the left table that do not match to the right table.
This allows us to find an employee's department, but still shows the employee(s) even when they have not been assigned to a department
SELECT *
FROM employee, department
WHERE employee.DepartmentID = department.DepartmentID(+)

Merge Row:
SELECT DepartmentID,
  listagg(LastName, ', ') WITHIN GROUP (ORDER BY LastName) AS LastNames
FROM employee
GROUP BY DepartmentID;

Explain plan is the SQL command that you may use to get Oracle to tell you what the query plan for a given SQL query would be if you
executed it right now in your current environment. The way to read this plan is to turning it into a graph of sorts-an evaluation tree.
From left to right, down to top. Using SQL_TRACE, you can capture the actual plan used at runtime.
AUTOTRACE gives you a look at how much work it actually took to perform your query, providing some important statistics regarding its
actual execution.
TKPROF is real and more powerful.

Currently, there are three transaction isolation levels supported by the Oracle database.  There is a fourth transition isolation level, read uncommitted, that is not supported by Oracle.
 These transaction isolation levels are:
Read Committed
Serializable
Read Only
The read committed transaction isolation level is the Oracle default. With this setting, each query can see only data committed before before the query (not the transaction) began.
Any transaction that executes a given query more than once can experience non-repeatable reads or phantoms.
Unlike the read committed level transactions, serializable isolation level transactions will not experience non-repeatable reads or phantoms.
All queries in an Oracle serializable transaction see the database as of a single point in time
With the Read Only transaction isolation level, only data that was committed at the start of the transaction can be accessed by a query.  No modification to the data is allowed.

Friday, August 23, 2013

Use Nologging tom improve the loading performance

Nologging is designed to handle bulk inserts of data which is reproducable.
Nologging has no effect on update, delete and insert statements.
Nologging can be applied on table or table space

(For Oracle 11g, use APPEND_VALUES instead of APPEND hint to bypass the redo log)

Nologging is active when performing one of the following commands:

direct load (SQL*Loader)
direct load INSERT (using APPEND hint)
CREATE TABLE … AS SELECT
CREATE INDEX
ALTER TABLE MOVE
ALTER TABLE … MOVE PARTITION
ALTER TABLE … SPLIT PARTITION
ALTER TABLE MERGE PARTITION
ALTER TABLE MODIFY PARTITION ADD SUBPARTITON
ALTER TABLE MODIFY PARTITION COALESCE SUBPARTITON
ALTER INDEX … SPLIT PARTITION
ALTER INDEX … REBUILD
ALTER INDEX … REBUILD PARTITION

The test on OIS shows that nologging has no meaning on the runtime:
--nolog1,23-AUG-13 02.27.45.000000000 PM to 23-AUG-13 02.53.10.000000000 PM
--nolog2,23-AUG-13 02.57.04.000000000 PM to 23-AUG-13 03.22.14.000000000 PM
--log,   23-AUG-13 03.31.00.000000000 PM to 23-AUG-13 03.51.56.000000000 PM

create table to hold all weekday for further computation

create table to hold all weekday for further computation
--create table weekday (valuation_date date)
--alter table weekday add primary key (valuation_date);
set serveroutput on
declare
lv_start_date date := trim(to_date('20080201','yyyymmdd'));
lv_date date;
lv_week pls_integer;
begin
  select trim(current_date) into lv_date from dual;
  while lv_start_date <= lv_date loop
    lv_week := to_number(to_char (lv_start_date, 'D')) - 1;
    if lv_week>=1 and lv_week<=5 then
      dbms_output.put_line(lv_start_date);
      insert into weekday values(lv_start_date);
    end if;
    select trim(lv_start_date+1) into lv_start_date from dual;
  end loop;
  commit;
end;
/

JavaFX table is much powerful than Java Swing JTable

JavaFX table is much powerful than Java Swing JTable, for example, to support nested column in the table,
JTable needs to implement by the developer itself (or use the third party more powerful table).
http://www.esus.com/docs/GetQuestionPage.jsp?uid=1272

In JavaFX table, it's very natural:
TableColumn firstEmailCol = new TableColumn("Primary");
TableColumn secondEmailCol = new TableColumn("Secondary");
emailCol.getColumns().addAll(firstEmailCol, secondEmailCol);

http://docs.oracle.com/javafx/2/ui_controls/table-view.htm

Wednesday, August 21, 2013

LinkedHashMap and TreeMap

LinkedHashMap
This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries.
This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).
It's used to compare/merge the currency pair list for FX
While TreeMap
A Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a
Comparator provided at map creation time, depending on which constructor is used.

Tuesday, August 20, 2013

Deploy Java Swing GUI application through JNLP (Java Web Start)

Deploy Java Swing GUI application through JNLP (Java Web Start)
1. Export runnable jar from Eclipse
The image source file may not in the jar. Put them into the jar if they are missing
2. Create keystore and sign the jar
keytool -genkey -keystore midasKeys -alias pengp2
jarsigner -keystore midasKeys midas.jar pengp2
3. Copy the signed jar to Tomcat folder.
4. Check "Keep temporary files on my computer" if there's Found unsigned entry in resource error.