Set as Homepage   Add to Favourites   Recommend   Contact



Menu

∙ Home
∙ Index (All Topics)
∙ About Me
∙ About This Blog
∙ Favourite Links
∙ RSS Feed

Categories

∙ ASP & PHP (1)
∙ HTML, XML and CSS (2)
∙ C / C++ (5)
∙ Java, JSP and Servlet (0)
∙ SQL-Oracle-PL/SQL (28)
∙ Operating Systems (1)
∙ OFF-Topic (8)

Popular Topics (Top 10)

∙ Decode Function in Oracle SQL (30774)

∙ Derin anlamlı sözler - Bunlar da Türkçe olanlar :) (21534)

∙ Turkcell Staj Günlüğü - 1: Introduction to Oracle (20254)

∙ Oracle performance analysis - Tracing and performance evaluation (17910)

∙ Differences between C and C++ (14146)

∙ Implicit vs. Explicit cursors - Performance analysis (9600)

∙ Turkcell Staj Günlüğü - 4: Transaction Management (8459)

∙ Turkcell Staj Günlüğü - 2: Data Blocks, Extends and Segments (7694)

∙ Turkcell Staj Günlüğü - 3: Tablespaces, Datafiles and Control Files (7616)

∙ Turkcell Staj Günlüğü - 9: "SQL, PL/SQL and Java" ve "Redo Internals" (7496)


Most Recent (Last 10)

∙ Matematik Asla Yalan Söylemez!

∙ Finding and Removing Loop on a Singly-Linked List

∙ Obfuscated C

∙ Is C a Vitamin? Yes, of course...

∙ Differences between C and C++

∙ Whence C? Why C? Whither C?

∙ Türkçe Karakterli Domain'lerin İç Yüzü

∙ Windows Source Codes

∙ Decode Function in Oracle SQL

∙ Hello World!


Recent Comments (Last 10)

∙ "tebrikler" By yasin on Turkcell Staj Günlüğü - 5: Startup, Shutdown

∙ "Gercekten Güzel Bir Çalışma" By Hüseyin Karabakla on Neden hazır blog'ları kullanmadım ki?

∙ "Konu paralelinde güzel bir özet ek okuma - " By TongucY on Oracle performance analysis - Tracing and performance evaluation

∙ "harika" By burak ozcan on Derin anlamlı sözler - Bunlar da Türkçe olanlar :)

∙ "Tebrikler" By Tarık Bayzın on Turkcell Staj Günlüğü - 1: Introduction to Oracle

∙ "Gayet Başarılı.." By Fahri ATES on Turkcell Staj Günlüğü - 1: Introduction to Oracle

∙ "Helal olsun" By ender onder on Turkcell Staj Günlüğü - 5: Startup, Shutdown

∙ "tebrikler.." By ender ondeer on Turkcell Staj Günlüğü - 4: Transaction Management

∙ "Adulation?" By fizikci on Matematik Asla Yalan Söylemez!

∙ "Rehberlik için çook teşekkürler" By Pınar Tanrıverdi on Kahin'e yolculuk nasıl başlamalı?


Archive (Last 12 Months)

∙ Feb, 2008 (4)
∙ Jan, 2008 (2)
∙ Dec, 2007 (1)
∙ Sep, 2007 (4)
∙ Aug, 2007 (9)
∙ Jul, 2007 (22)
∙ Jun, 2007 (3)
∙ Index (All Records)

Other Related Blogs

∙ Tom Kyte’s Blog
∙ Steven Feuerstein’s Blog
∙ Jonathan Lewis’s Blog
∙ H.Tonguç Yılmaz Oracle Blog
∙ Mennan Tekbir's Blog
∙ Hakkı Oktay’s Blog
∙ Osman Çam’s Blog

Stats

Total Topics
Total Topic Views
Total Comments
Unique Visitors
Total Visitors
: 45
: 279256
: 44

About this blog…
About this blog…
About Me
About Me
Favourite Links
Favourite Links
Neden hazır blog'ları kullanmadım ki?
Neden hazır blog'ları kullanmadım ki?
CSS is more powerful than you imagine
CSS is more powerful than you imagine
Turkcell Staj Günlüğü - 1: Introduction to Oracle
Turkcell Staj Günlüğü - 1: Introduction to Oracle
Turkcell Staj Günlüğü - 2: Data Blocks, Extends and Segments
Turkcell Staj Günlüğü - 2: Data Blocks, Extends and Segments
Kahin'e yolculuk nasıl başlamalı?
Kahin'e yolculuk nasıl başlamalı?
Turkcell Staj Günlüğü - 3: Tablespaces, Datafiles and Control Files
Turkcell Staj Günlüğü - 3: Tablespaces, Datafiles and Control Files
Turkcell Staj Günlüğü - 4: Transaction Management
Turkcell Staj Günlüğü - 4: Transaction Management
Image formats - Which to use when
Image formats - Which to use when
Turkcell Staj Günlüğü - 5: Startup, Shutdown
Turkcell Staj Günlüğü - 5: Startup, Shutdown
Turkcell Staj Günlüğü - 6: Oracle Architecture
Turkcell Staj Günlüğü - 6: Oracle Architecture
ASP - Locales and Codepages
ASP - Locales and Codepages
Oracle performance analysis - Tracing and performance evaluation
Oracle performance analysis - Tracing and performance evaluation
Oracle performance analysis - Autotrace workshop
Oracle performance analysis - Autotrace workshop
Oracle performance analysis - Runstats workshop
Oracle performance analysis - Runstats workshop
Oracle performance analysis - Tkprof workshop
Oracle performance analysis - Tkprof workshop
Some favourite quotes
Some favourite quotes
Derin anlamlı sözler - Bunlar da Türkçe olanlar :)
Derin anlamlı sözler - Bunlar da Türkçe olanlar :)
Turkcell Staj Günlüğü - 7: Concurrency and Consistency
Turkcell Staj Günlüğü - 7: Concurrency and Consistency
"Kurtuluş"un hikayesi
"Kurtuluş"un hikayesi
Turkcell Staj Günlüğü - 8: Statement Processing and CBO
Turkcell Staj Günlüğü - 8: Statement Processing and CBO
When a transaction begins?
When a transaction begins?
Implicit vs. Explicit cursors - Performance analysis
Implicit vs. Explicit cursors - Performance analysis
Turkcell Staj Günlüğü - 9: "SQL, PL/SQL and Java" ve "Redo Internals"
Turkcell Staj Günlüğü - 9: "SQL, PL/SQL and Java" ve "Redo Internals"
Affect of gathering table stats to decision of CBO
Affect of gathering table stats to decision of CBO
Bind is bad :) - An interesting case of bind variables fails
Bind is bad :) - An interesting case of bind variables fails
When the explanation doesn't sound quite right...
When the explanation doesn't sound quite right...
Turkcell Staj Günlüğü - 10: Import, Export ve SQL Loader
Turkcell Staj Günlüğü - 10: Import, Export ve SQL Loader
Turkcell Staj Günlüğü - 11: Autonomous Transactions ve Dynamic SQL
Turkcell Staj Günlüğü - 11: Autonomous Transactions ve Dynamic SQL
Difference between db block gets and consistent gets
Difference between db block gets and consistent gets
Object-Oriented Features of Oracle - Part 1: Native Datatypes vs. Object Datatypes
Object-Oriented Features of Oracle - Part 1: Native Datatypes vs. Object Datatypes
Object-Oriented Features of Oracle - Part 2: Object Types and Collection types
Object-Oriented Features of Oracle - Part 2: Object Types and Collection types
Object-Oriented Features of Oracle - Part 3: Object Tables, Object Views and REFs
Object-Oriented Features of Oracle - Part 3: Object Tables, Object Views and REFs
Examining show_space
Examining show_space
Turkcell Staj Günlüğü - 12: Partitioning
Turkcell Staj Günlüğü - 12: Partitioning
Hello World!
Hello World!
Decode Demo #1
Decode Demo #1
Decode Demo #2
Decode Demo #2
Decode Demo #3
Decode Demo #3
Decode Demo #4
Decode Demo #4
Decode Function in Oracle SQL
Decode Function in Oracle SQL
Windows Source Codes
Windows Source Codes
Türkçe Karakterli Domain'lerin İç Yüzü
Türkçe Karakterli Domain'lerin İç Yüzü
Whence C? Why C? Whither C?
Whence C? Why C? Whither C?
Differences between C and C++
Differences between C and C++
Is C a Vitamin? Yes, of course...
Is C a Vitamin? Yes, of course...
Obfuscated C
Obfuscated C
Finding and Removing Loop on a Singly-Linked List
Finding and Removing Loop on a Singly-Linked List
Matematik Asla Yalan Söylemez!
Matematik Asla Yalan Söylemez!
eXTReMe Tracker
Decode Demo #1
Category: SQL-Oracle-PL/SQL
Date: 16.09.2007 23:12:38


SQL*Plus: Release 10.2.0.1.0 - Production on Thu Sep 13 11:29:06 2007

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> CREATE TABLE airplanes (
  2  program_id     VARCHAR2(3),
  3  line_number    NUMBER(10),
  4  customer_id    VARCHAR2(4),
  5  order_date     DATE,
  6  delivered_date DATE)
  7  PCTFREE 0
  8  PCTUSED 99;

Table created.

SQL>
SQL> CREATE INDEX ix_program_id
  2  ON airplanes (program_id)
  3  PCTFREE 0;

Index created.

SQL>
SQL> DECLARE
  2   progid  VARCHAR2(3) := '000';
  3   lineno  NUMBER(10) := 0;
  4   custid  VARCHAR2(4) := 'AAL';
  5   orddate DATE;
  6   deldate DATE;
  7  BEGIN
  8    LOOP
  9      SELECT DECODE(progid,'000','737','737','747','747','757','757','767','767',
                       '777','777','999')
 10      INTO progid
 11      FROM dual;
 12
 13      IF progid = 999 THEN
 14        EXIT;
 15      END IF;
 16
 17      FOR x IN 1..50000
 18      LOOP
 19        lineno := lineno + 1;
 20
 21        SELECT DECODE(custid,'AAL','DAL','DAL','SAL','SAL','ILC','ILC','SWA','SWA',
                         'NWO','NWO','USAF','USAF','AAL')
 22        INTO custid
 23        FROM dual;
 24
 25        OrdDate := SYSDATE + lineno;
 26        DelDate := OrdDate + lineno + 100;
 27
 28        INSERT INTO airplanes
 29        (program_id, line_number, customer_id,
 30        order_date, delivered_date)
 31        VALUES
 32        (progid, lineno, custid, orddate, deldate);
 33      END LOOP;
 34      lineno := 0;
 35    END LOOP;
 36    COMMIT;
 37  END load_airplanes;
 38  /

PL/SQL procedure successfully completed.

SQL>
SQL> SELECT program_id,
  2    DECODE(customer_id, 'AAL', 'American Airlines') AIRLINE,
  3    delivered_date
  4  FROM airplanes
  5  WHERE ROWNUM < 11;

PRO AIRLINE           DELIVERED
--- ----------------- ---------
737                   24-DEC-07
737                   26-DEC-07
737                   28-DEC-07
737                   30-DEC-07
737                   01-JAN-08
737                   03-JAN-08
737 American Airlines 05-JAN-08
737                   07-JAN-08
737                   09-JAN-08
737                   11-JAN-08

10 rows selected.

SQL> SELECT program_id,
  2         DECODE(customer_id,
  3                'AAL', 'American Airlines',
  4                'ILC', 'Intl. Leasing Corp.',
  5                'NWO', 'Northwest Orient',
  6                'SAL', 'Southwest Airlines',
  7                'SWA', 'Sweptwing Airlines',
  8                'USAF', 'U.S. Air Force') AIRLINE,
  9         delivered_date
 10  FROM airplanes
 11  WHERE ROWNUM < 11;

PRO AIRLINE             DELIVERED
--- ------------------- ---------
737                     24-DEC-07
737 Southwest Airlines  26-DEC-07
737 Intl. Leasing Corp. 28-DEC-07
737 Sweptwing Airlines  30-DEC-07
737 Northwest Orient    01-JAN-08
737 U.S. Air Force      03-JAN-08
737 American Airlines   05-JAN-08
737                     07-JAN-08
737 Southwest Airlines  09-JAN-08
737 Intl. Leasing Corp. 11-JAN-08

10 rows selected.

SQL> SELECT program_id,
  2         DECODE(customer_id,
  3               'AAL', 'American Airlines',
  4               'ILC', 'Intl. Leasing Corp.',
  5               'NWO', 'Northwest Orient',
  6               'SAL', 'Southwest Airlines',
  7               'SWA', 'Sweptwing Airlines',
  8               'USAF', 'United States Air Force',
  9               'Not Known') AIRLINE,
 10         delivered_date
 11  FROM airplanes
 12  WHERE ROWNUM < 11;

PRO AIRLINE                 DELIVERED
--- ----------------------- ---------
737 Not Known               24-DEC-07
737 Southwest Airlines      26-DEC-07
737 Intl. Leasing Corp.     28-DEC-07
737 Sweptwing Airlines      30-DEC-07
737 Northwest Orient        01-JAN-08
737 United States Air Force 03-JAN-08
737 American Airlines       05-JAN-08
737 Not Known               07-JAN-08
737 Southwest Airlines      09-JAN-08
737 Intl. Leasing Corp.     11-JAN-08

10 rows selected.

SQL> SELECT program_id,
  2         DECODE(customer_id, 'AAL', 'AAL') AMERICAN,
  3         DECODE(customer_id, 'DAL', 'DAL') DELTA,
  4         DECODE(customer_id, 'NWO', 'NWO') NORTHWEST,
  5         DECODE(customer_id, 'ILC', 'ILC') INTL_LEASING
  6  FROM airplanes
  7  WHERE rownum < 20;

PRO AME DEL NOR INT
--- --- --- --- ---
737     DAL
737
737             ILC
737
737         NWO
737
737 AAL
737     DAL
737
737             ILC
737
737         NWO
737
737 AAL
737     DAL
737
737             ILC
737
737         NWO

19 rows selected.

SQL> SELECT program_id,
  2         COUNT (AMERICAN) AAL,
  3         COUNT (DELTA) DAL,
  4         COUNT (NORTHWEST) NWO,
  5         COUNT(INTL_LEASING) ILC
  6  FROM (
  7     SELECT program_id,
  8            DECODE(customer_id, 'AAL', 'AAL') AMERICAN,
  9            DECODE(customer_id, 'DAL', 'DAL') DELTA,
 10            DECODE(customer_id, 'NWO', 'NWO') NORTHWEST,
 11            DECODE(customer_id, 'ILC', 'ILC') INTL_LEASING
 12     FROM airplanes)
 13  GROUP BY program_id;

PRO        AAL        DAL        NWO        ILC
--- ---------- ---------- ---------- ----------
737       7142       7143       7143       7143
747       7143       7143       7143       7143
767       7143       7143       7143       7143
777       7143       7143       7143       7142
757       7143       7143       7142       7143

SQL>

Download Code



Comments

No comments posted yet.



© Copyright. All rights reserved. Designed by Bilal Hatipoğlu. RSS Feed  Valid W3C XHTML 1.0 Document  Valid W3C CSS Document