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 (10431)

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

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

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

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

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

∙ Differences between C and C++ (3983)

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

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

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


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)

∙ "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ı?

∙ "bilgi paylaşıldıkça deger kazanır." By zülfü yıldırım on Turkcell Staj Günlüğü - 12: Partitioning

∙ "Teşekkürler" By serdar on Turkcell Staj Günlüğü - 12: Partitioning

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

∙ "The Power of Attitude" By Tonguç Yılmaz on Matematik Asla Yalan Söylemez!

∙ ":)" By Ozay Akdora on Obfuscated C

∙ By Ömer YURDUSEVEN on Windows Source Codes

∙ By Özgür Macit on Türkçe Karakterli Domain'lerin İç Yüzü

∙ "Thanks" By Ganesh on Difference between db block gets and consistent gets


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
: 120090
: 36

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 #3
Category: SQL-Oracle-PL/SQL
Date: 16.09.2007 23:14:18


SQL*Plus: Release 10.2.0.1.0 - Production on Thu Sep 13 11:36:46 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 payoutpercentage (
  2  productgroup  VARCHAR2(5),
  3  position      NUMBER(1),
  4  payoutpct     NUMBER(3))
  5  PCTFREE 0
  6  PCTUSED 99;

Table created.

SQL>
SQL> INSERT INTO payoutpercentage VALUES ('ACC', 0, 5);

1 row created.

SQL> INSERT INTO payoutpercentage VALUES ('ACC', 1, 10);

1 row created.

SQL> INSERT INTO payoutpercentage VALUES ('ACC', 2, 15);

1 row created.

SQL> INSERT INTO payoutpercentage VALUES ('ACC', 3, 20);

1 row created.

SQL>
SQL> CREATE TABLE accessoryhistory (
  2  dbid       VARCHAR2(1) DEFAULT ('W'),
  3  statustype VARCHAR2(3),
  4  sku        VARCHAR2(21),
  5  quantity   NUMBER(10,0) DEFAULT 1,
  6  saleprice  NUMBER(19,4) DEFAULT 0,
  7  compdate   DATE DEFAULT SYSDATE,
  8  store      NUMBER(10,0) DEFAULT 0)
  9  PCTFREE 0
 10  PCTUSED 99;

Table created.

SQL>
SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', 'ABCD', 6, 100, SYSDATE, 2);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', '987B', 3, 100, SYSDATE, 1);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', 'ABCD', 1, 100, SYSDATE, 3);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', 'RXRX', 2, 100, SYSDATE, 3);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', 'ABCD', 9, 100, SYSDATE, 2);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', 'QV23', 7, 100, SYSDATE, 1);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', 'ABCD', 1, 100, SYSDATE, 4);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', 'QV23', 3, 100, SYSDATE, 5);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', 'ABCD', 2, 100, SYSDATE, 2);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', 'RXRX', 1, 100, SYSDATE, 4);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', 'RXRX', 1, 100, SYSDATE, 5);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', 'QV23', 3, 100, SYSDATE, 1);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', '987B', 1, 100, SYSDATE, 2);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', 'ABCD', 3, 100, SYSDATE, 1);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'ACT', 'RXRX', 4, 100, SYSDATE, 2);

1 row created.

SQL> INSERT INTO accessoryhistory VALUES ('W', 'DEA', 'QV23', 3, 100, SYSDATE, 3);

1 row created.

SQL>
SQL> CREATE TABLE store (
  2  store      NUMBER(10,0) DEFAULT 0,
  3  name       VARCHAR2(60),
  4  areadir    NUMBER(10,0) DEFAULT 0,
  5  areamgr    NUMBER(10,0) DEFAULT 0,
  6  storemgr1  NUMBER(10,0) DEFAULT 0,
  7  storemgr2  NUMBER(10,0) DEFAULT 0,
  8  asstmgr1   NUMBER(10,0) DEFAULT 0,
  9  asstmgr2   NUMBER(10,0) DEFAULT 0,
 10  asstmgr3   NUMBER(10,0) DEFAULT 0);

Table created.

SQL>
SQL> INSERT INTO store VALUES (1, 'San Francisco', 100, 200, 301, 302, 401, 402, 403);

1 row created.

SQL> INSERT INTO store VALUES (2, 'Denver', 131, 225, 310, 0, 447, 407, 0);

1 row created.

SQL> INSERT INTO store VALUES (3, 'Chicago', 155, 222, 311, 354, 401, 402, 403);

1 row created.

SQL> INSERT INTO store VALUES (4, 'London', 178, 0, 301, 0, 377, 402, 403);

1 row created.

SQL> INSERT INTO store VALUES (5, 'Ankara', 0, 298, 301, 390, 401, 402, 403);

1 row created.

SQL>
SQL> CREATE TABLE sku (
  2  dbid          VARCHAR2(1) DEFAULT ('W'),
  3  sku           VARCHAR2(21),
  4  productgroup  VARCHAR2(5) DEFAULT ('ACC'),
  5  name          VARCHAR2(30));

Table created.

SQL>
SQL> INSERT INTO sku VALUES ('W', 'ABCD', 'ACC', 'Phone');

1 row created.

SQL> INSERT INTO sku VALUES ('W', 'RXRX', 'ACC', 'Microphone');

1 row created.

SQL> INSERT INTO sku VALUES ('W', 'QV23', 'ACC', 'Speaker');

1 row created.

SQL> INSERT INTO sku VALUES ('W', '987B', 'ACC', 'Bracket');

1 row created.

SQL> INSERT INTO sku VALUES ('C', 'ABCD', 'ACC', 'Antenna');

1 row created.

SQL> -- DECODE in the WHERE clause
SQL> set serveroutput on
SQL>
SQL> DECLARE
  2   posn  PLS_INTEGER := 0;
  3   empid PLS_INTEGER := 178;
  4   x     NUMBER;
  5  BEGIN
  6    SELECT NVL(SUM(ah.quantity * ah.saleprice * ap.payoutpct), 0)
  7    INTO x
  8    FROM accessoryhistory ah, payoutpercentage ap,
  9    sku s, store st
 10    WHERE empid = DECODE(posn,
 11                            0, st.areadir,
 12                            1, st.areamgr,
 13                            2, NVL(st.storemgr1, st.storemgr2),
 14                            3, NVL(st.asstmgr1, NVL(st.asstmgr2,
 15                         st.asstmgr3)))
 16    AND ah.statustype IN ('ACT', 'DEA')
 17    AND ah.store = st.store
 18    AND s.dbid = ah.dbid
 19    AND s.sku = ah.sku
 20    AND ap.productgroup = s.productgroup
 21    AND ap.position = posn;
 22
 23    dbms_output.put_line(x);
 24  END;
 25  /
1000

PL/SQL procedure successfully completed.

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