Pages

Monday, October 3, 2011

Display no of days of different day of current month



SELECT SUM(DECODE(TO_CHAR(mon_date,'D'),1,1)) total_sun
, SUM(DECODE(TO_CHAR(mon_date,'D'),2,1)) total_mon
, SUM(DECODE(TO_CHAR(mon_date,'D'),3,1)) total_tue
, SUM(DECODE(TO_CHAR(mon_date,'D'),4,1)) total_wed
, SUM(DECODE(TO_CHAR(mon_date,'D'),5,1)) total_thus
, SUM(DECODE(TO_CHAR(mon_date,'D'),6,1)) total_fri
, SUM(DECODE(TO_CHAR(mon_date,'D'),7,1)) total_sat
FROM (
SELECT curr_mon + LEVEL - 1 mon_date,
    ( TRUNC (curr_mon + LEVEL - 1, 'D')
       - TRUNC (TRUNC (curr_mon + LEVEL - 1, 'Y'), 'D')
    ) / 7 + 1 week_no
FROM (SELECT TO_DATE (TO_CHAR(SYSDATE,'YYYYMM'), 'YYYYMM') curr_mon
    FROM DUAL)
CONNECT BY curr_mon + LEVEL - 1 <= LAST_DAY (curr_mon));

Friday, September 23, 2011

Display all the dates of current month by SQL


SELECT mon_date, week_no, TO_CHAR(mon_date,'D') day, TO_NUMBER(TO_CHAR(mon_date,'DD')) dd
FROM (
SELECT curr_mon + LEVEL - 1 mon_date,
    ( TRUNC (curr_mon + LEVEL - 1, 'D')
       - TRUNC (TRUNC (curr_mon + LEVEL - 1, 'Y'), 'D')
    ) / 7 + 1 week_no
FROM (SELECT TO_DATE (TO_CHAR(SYSDATE,'YYYYMM'), 'YYYYMM') curr_mon
    FROM DUAL)
CONNECT BY curr_mon + LEVEL - 1 <= LAST_DAY (curr_mon));

Connecting Oracle Forms 6i and Oracle Reports 6i with Oracle 10g XE


To connect from Oracle Forms 6i / Reports 6i to Oracle 10g XE, need to set the database character set as UTF8.

Steps to follow:
1. Connect to the database as SYSDBA
SQL>CONN SYSTEM/MANAGER AS SYSDBA

2. Shutdown the database if running:
SQL>SHUTDOWN IMMEDIATE

3. Start the database in restrict mode:
SQL>STARTUP RESTRICT

4. Change the databse charcter set to UTF8 as follows:
SQL>ALTER DATABASE CHARACTER SET INTERNAL_USE UTF8;

5. Shutdown the database:
SQL>SHUTDOWN IMMEDIATE

6. At last, start the database in normal mode:
SQL>STARTUP

After successfull of these steps, you can connect to the Oracle XE database through Forms 6i or Oracle Reports 6i.
Note: Install Oracle Forms and Reports in different Oracle Home

Thursday, September 22, 2011

Dispaly List of Month By SQL

SELECT     TO_CHAR (start_date + LEVEL - 1, 'MM') month_code,
           TO_CHAR (start_date + LEVEL - 1, 'MON') mon_name
      FROM (SELECT TO_DATE (TO_CHAR (SYSDATE, 'YYYY') || '0101',
                            'YYYYMMDD'
                           ) start_date,
                   TO_DATE (TO_CHAR (SYSDATE, 'YYYY') || '1231',
                            'YYYYMMDD'
                           ) end_date
              FROM DUAL)
CONNECT BY start_date + LEVEL - 1 <= end_date
  GROUP BY TO_CHAR (start_date + LEVEL - 1, 'MM'),
           TO_CHAR (start_date + LEVEL - 1, 'MON');

/*
OUTPUT:
MONTH_CODE|MONTH_NAME
01|JAN
02|FEB
03|MAR
04|APR
05|MAY
06|JUN
07|JUL
08|AUG
09|SEP
10|OCT
11|NOV
12|DEC

*/

Write a pl/sql block to display names of employees with sal in descending order without using order by

DECLARE
   TYPE rec IS RECORD
   (
      ename   emp.ename%TYPE,
      sal     emp.sal%TYPE
   );

   v_rec        rec;
   v_rec2       rec;
   v_rec_temp   rec;

   TYPE assoc IS TABLE OF rec
                    INDEX BY PLS_INTEGER;

   v_assoc      assoc;

   CURSOR c
   IS
      SELECT ename, sal FROM emp;

   --elem   emp.ename%TYPE;
   v_sal        NUMBER;
   v_ename      VARCHAR2 (100);
   i            NUMBER := 1;
BEGIN
   DBMS_OUTPUT.put_line ('Origional List');

   FOR d IN c
   LOOP
      v_rec.ename := d.ename;
      v_rec.sal := d.sal;
      v_assoc (i) := v_rec;
      DBMS_OUTPUT.put_line (i || ': ' || v_rec.ename || ' ' || v_rec.sal);
      i := i + 1;
   END LOOP;

   DBMS_OUTPUT.put_line ('Descending Order List');

   FOR e IN 1 .. v_assoc.COUNT
   LOOP
      v_rec := v_assoc (e);

      --DBMS_OUTPUT.put_line (e || '==>>' || v_rec.ename || ' -----'|| v_rec.sal );

      FOR e2 IN e + 1 .. v_assoc.COUNT
      LOOP
         v_rec2 := v_assoc (e2);

         --DBMS_OUTPUT.put_line (e || '====>>>>' || v_rec2.sal || '>' || v_sal);

         IF v_rec2.sal > v_rec.sal
            OR (v_rec2.sal = v_rec.sal AND v_rec2.ename < v_rec.ename)
         THEN
            v_rec_temp.ename := v_rec.ename;
            v_rec_temp.sal := v_rec.sal;
            v_assoc (e) := v_rec2;
            v_assoc (e2) := v_rec_temp;
            v_rec := v_assoc (e);
         END IF;
      END LOOP;
   END LOOP;

   FOR e IN 1 .. v_assoc.COUNT
   LOOP
      v_rec := v_assoc (e);
      v_ename := v_rec.ename;
      v_sal := v_rec.sal;
      DBMS_OUTPUT.put_line (e || ' : ' || v_ename || ' ' || v_sal);
   END LOOP;
END;

/*
Output:
Origional List
1: SMITH 800
2: ALLEN 1600
3: WARD 1250
4: JONES 2975
5: MARTIN 1250
6: BLAKE 2850
7: CLARK 2450
8: SCOTT 3000
9: KING 5000
10: TURNER 1500
11: ADAMS 1100
12: JAMES 950
13: FORD 3000
14: MILLER 1300
Descending Order List
1 : KING 5000
2 : FORD 3000
3 : SCOTT 3000
4 : JONES 2975
5 : BLAKE 2850
6 : CLARK 2450
7 : ALLEN 1600
8 : TURNER 1500
9 : MILLER 1300
10 : MARTIN 1250
11 : WARD 1250
12 : ADAMS 1100
13 : JAMES 950
14 : SMITH 800
*/

Friday, July 29, 2011

Oracle E-Business Suite

Oracle E-Business Suite consists of a collection of enterprise resource planning (ERP), customer relationship management (CRM), and supply-chain management (SCM) computer applications. It contains several products:
  • Oracle CRM
  • Oracle Financials
  • Oracle HRMS
  • Oracle Mobile Supply Chain Applications
  • Oracle Order Management
  • Oracle Procurement
  • Oracle Project Portfolio Management
  • Oracle Quotes
  • Oracle Transportation Management
  • Oracle Warehouse Management Systems
  • Oracle Inventory
  • Oracle Enterprise Asset Management

Thursday, July 28, 2011

SQL Developer


The SQL Developer is an IDE for working in Oracle Database and gives the developer a quick overview of the entire database. It is developed by Oracle Corporation in Java and it is free for use.

SQL Developer can connect to any Oracle Database version 9.2.0.1 and later and runs on Windows, Linux, and Mac OSX. Default connectivity to the database is through the JDBC Thin driver (no Oracle Home required); the JDBC Type 2 driver (OCI client side driver) is also supported.

Toad

Toad -> Tool for Oracle Application Development
A product of Quest Software
Overview of Toad
-------------------
Toad provides the following features and benefits:
1. SQL Development
2. Data Management Reporting
3. PL/SQL Development
4. Application Development
5. Database Administration
6. Optimization and Tuning

Short-cuts:
-----------
F1 -> Help
F2 -> Toggle output Window
Shift+F2 -> Toggle Data Grid Window
F4 -> Describe Oracle objects like Table, view, Procedures, Functions, etc
F5 -> Executes the selection or entire screen as a script.
F7 -> Clear all text
Ctrl + L -> Convert text to Lower Case
Ctrl + U -> Convert text to Upper Case
Ctrl + Z -> Undo
Ctrl + Enter -> Execute the current query
Shift+F9 -> This will run only the SQL that your cursor is on. You do not need to highlight the line or the entire SQL statement; simply place your cursor anywhere inside the SQL statement and click SHIFT-F9.
Ctrl + F -> Find the String