How do I put a crosstab on a form?

I need to set up a matrix-type canvas on a form where each cell will become a record on a table with the row value and column value forming the key. The row and column values will be retrieved from another table.
Any ideas? I don't even know where to start.

for example I have a table:
emps( empno number, start_time date, end_time date );
And I'd like to have a form that looks like:
EMPNO 8am 9am 10am 11am 12pm 1pm 2pm
1 - x x x x - x ....
2 x x x x - x x ....
that shows empno = 1 works from 9am-12pm, is off for 1 hour (and
so on...)
and I said...
Well, once we create a view, this is easy. The view isn't easy
to come up with perhaps but once there -- its trivial to use.
We'll start with an extra table:
[email protected]> create table hours
2 as
3 select rownum-1 hour
4 from all_objects
5 where rownum <= 24;
Table created.
That has a row for every hour in the day...
Here is my emp table. I have a column DAY that is for
illustrative purposes -- you might not need it (you could also
substitute TRUNC(start_date) where I reference DAY in the view
below). I made it a column so I could index it and query it
easily...
[email protected]> create table emp
2 ( empno number,
3 day date,
4 start_time date,
5 end_time date
6 )
7 /
Table created.
[email protected]> create index emp_idx on emp(empno);
Index created.
[email protected]> create index start_idx on emp(day);
Index created.
[email protected]> alter session set
nls_date_format='dd-mon-yyyy hham';
Session altered.
[email protected]>
[email protected]> insert into emp values
2 ( 1, '07-jul-2000', '07-jul-2000 9am', '07-jul-2000 12pm'
1 row created.
[email protected]> insert into emp values
2 ( 1, '07-jul-2000', '07-jul-2000 1pm', '07-jul-2000 6pm' );
1 row created.
[email protected]>
[email protected]> insert into emp values
2 ( 2, '07-jul-2000', '07-jul-2000 8am', '07-jul-2000 11am'
1 row created.
[email protected]> insert into emp values
2 ( 2, '07-jul-2000', '07-jul-2000 12pm','07-jul-2000 5pm' );
1 row created.
[email protected]>
[email protected]> insert into emp
2 select empno, day-1,
3 start_time-(1+1/24), end_time-(1+1/24)
4 from emp;
4 rows created.
[email protected]>
[email protected]> select * from emp;
EMPNO DAY START_TIME END_TIME
1 07-jul-2000 12am 07-jul-2000 09am 07-jul-2000 12pm
1 07-jul-2000 12am 07-jul-2000 01pm 07-jul-2000 06pm
2 07-jul-2000 12am 07-jul-2000 08am 07-jul-2000 11am
2 07-jul-2000 12am 07-jul-2000 12pm 07-jul-2000 05pm
1 06-jul-2000 12am 06-jul-2000 08am 06-jul-2000 11am
1 06-jul-2000 12am 06-jul-2000 12pm 06-jul-2000 05pm
2 06-jul-2000 12am 06-jul-2000 07am 06-jul-2000 10am
2 06-jul-2000 12am 06-jul-2000 11am 06-jul-2000 04pm
8 rows selected.
So that is the data we have to work with. 2 days worth for 2
emps. Hours are different by day...
[email protected]> alter session set
nls_date_format='dd-mon-rr';
Session altered.
Here comes the view:
[email protected]> create or replace view empV
2 as
3 select empno, day,
4 max( decode( hour, 0, flag, null ) ) "0",
5 max( decode( hour, 1, flag, null ) ) "1",
6 max( decode( hour, 2, flag, null ) ) "2",
7 max( decode( hour, 3, flag, null ) ) "3",
8 max( decode( hour, 4, flag, null ) ) "4",
9 max( decode( hour, 5, flag, null ) ) "5",
10 max( decode( hour, 6, flag, null ) ) "6",
11 max( decode( hour, 7, flag, null ) ) "7",
12 max( decode( hour, 8, flag, null ) ) "8",
13 max( decode( hour, 9, flag, null ) ) "9",
14 max( decode( hour, 10, flag, null ) ) "10",
15 max( decode( hour, 11, flag, null ) ) "11",
16 max( decode( hour, 12, flag, null ) ) "12",
17 max( decode( hour, 13, flag, null ) ) "13",
18 max( decode( hour, 14, flag, null ) ) "14",
19 max( decode( hour, 15, flag, null ) ) "15",
20 max( decode( hour, 16, flag, null ) ) "16",
21 max( decode( hour, 17, flag, null ) ) "17",
22 max( decode( hour, 18, flag, null ) ) "18",
23 max( decode( hour, 19, flag, null ) ) "19",
24 max( decode( hour, 20, flag, n ull ) ) "20",
25 max( decode( hour, 21, flag, null ) ) "21",
26 max( decode( hour, 22, flag, null ) ) "22",
27 max( decode( hour, 23, flag, null ) ) "23"
28 from ( select empno, day, hour,
29 decode( sign(
start_time-(trunc(start_time)+
30 hour/24)), 1, NULL,
31 decode( sign(end_time-(trunc(end_time)+
32 hour/24)), 1, 'X', NULL ) ) flag
33 from ( select * from hours ),
34 emp
35 )
36 group by empno, day
37 /
View created.
The view works by:
o "from (select * from hours ), emp" creates 24 rows for each
row in the emp table we are interested in. Each of these rows
has an hour associated with it now. So, where we had 8 rows,
we'll get 8x24 rows (less if we use a predicate on the view as
see below)...
o the decode in the from list says:
if ( start_time - HOUR ) > 0
then
-- start time is bigger then hour, we did not work in that
-- hour
return NULL
else
if ( end_time - HOUR ) > 0
then
-- end_time happens AFTER that hour hence we WORKED in
-- that hour
return 'X'
else
return NULL
end if
end if
o we now have a set such that for each row in emp we have 24
rows with the numbers 0..23 and a flag that says whether we
worked in that hour or not...
o we can use a simple decode and group by to pivot on empno and
day...
Now lets see how it works and how it performs
[email protected]> select * from empV;
EMPNO DAY 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2
1 06-jul-00 X X X X X X X X
1 07-jul-00 X X X X X X X X
2 06-jul-00 X X X X X X X X
2 07-jul-00 X X X X X X X X
That shows empno=1 works from 8am-11am (upto not including
11am) and 1pm-5pm on 6/jul (easier to read with a wider screen
The following shows that we can efficiently query this as
well:
[email protected]> set autotrace on explain
[email protected]> select * from empV where empno = 1;
EMPNO DAY 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2
1 06-jul-00 X X X X X X X X
1 07-jul-00 X X X X X X X X
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 VIEW OF 'EMPV'
2 1 SORT (GROUP BY)
3 2 NESTED LOOPS
4 3 TABLE ACCESS (FULL) OF 'HOURS'
5 3 TABLE ACCESS (BY INDEX ROWID) OF 'EMP'
6 5 INDEX (RANGE SCAN) OF 'EMP_IDX' (NON-UNIQUE)
Even though the view looks too complex to merge predicates
into -- it can. It used the index on emp to find empno 1 and
then did the work. The following shows the same can be true of
the other indexed columns:
[email protected]> select * from empV where day = to_date(
'07-jul-00' );
EMPNO DAY 0 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2
1 07-jul-00 X X X X X X X X
2 07-jul-00 X X X X X X X X
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 VIEW OF 'EMPV'
2 1 SORT (GROUP BY)
3 2 NESTED LOOPS
4 3 TABLE ACCESS (FULL) OF 'HOURS'
5 3 TABLE ACCESS (BY INDEX ROWID) OF 'EMP'
6 5 INDEX (RANGE SCAN) OF 'START_IDX'
(NON-UNIQUE)
null

Similar Messages

  • How do i put a box in my form and have consecutive numbering in it

    How do i put a box in my form and have consecutive numbering in it

    Hi,
    Sorry, this is not supported in Adobe FormsCentral.
    Thanks,
    Lucia

  • How do I put a timestamp in a form field in a business process?

    At a specific step in the process, when a user approves a form, I would like to put their name and a timestamp in a text field that is locked.  I think there are some different ways to do this, but each has their own issues.
    Javascript in form:
    I could do this via javascript before the form is submitted, but how do I know which step in the process we are in?
    Business Process:
    I don't think I can directly access the form from the process.  I can read from the form, but cannot set values, correct?
    Custom Render Process:
    I have a custom render process but I would need to extract all the data from the form, merge with the xml for the new field, then merge back in with the document.  Not sure how to do this.
    Any ideas on what the best way to handle this would be?
    Thanks

    Hi,
    You can use the executeScript component to set the timestamp in the form or varible. Mention below is an example to get the timestamp in dd/MM/yyyy format.
    java.text.DateFormat dateFormat = new java.text.SimpleDateFormat(
                    "dd/MM/yyyy");
    java.util.Date date = new java.util.Date();
    String datetime = dateFormat.format(date);
    System.out.println("Current Date Time : " + datetime);
    patExecContext.setProcessDataStringValue("xpath of the form field or variable", datetime);
    Regards,
    Waqas

  • How can i put apps from one ipod to a new ipod?

    how can i put apps from one ipod to a new ipod?

    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device

  • Ok, I have two itunes library account one for the PC and one for my Mac, I have my first iphone on my PC, but i just upgrade and I would like to use my new iphone on my Mac but all of my apps and other stuff is in the first library.. How do I put my apps

    ok, I have two itunes librarys account, one for my PC and one for my Mac, I use the PC for my iphone, but I upgrade my iphone and all my apps and
    stuff is on the first itunes library. How do I put the apps from one iphone to the otherusing two dirffernt itunes library? please help..

    Drrhythm2 wrote:
    What's the best solution for this? I
    Copy the entire /Music/iTunes/ folder from her old compouter to /Music/ in her account on this new computer.

  • How do I put these songs and videos onto the Music App?

    How do I load mp3 content, videos, and other content from applications onto the music app? For example, I have applications such as Video Hunter Pro that downloads youtube videos, but how do I put the videos or audio track into my Music app? I don't want to constantly switch apps. For iTunes on all devices.

    Only items directly downloaded from iTunes Store or synced over from iTunes on a computer can be placed in the music or video app.

  • I recently sync one song to my friends iphone 4 and it erased all the music and only put that one song. I tried backing it up but it didnt help. How do I put all previous music back on the iphone?

    I recently sync one song to my friends iphone 4 and it erased all the music and only put that one song. I tried backing it up but it didnt help. How do I put all previous music back on the iphone?

    Re- sync the phone with the computer it was originally synced with.

  • How do I put text into an Edge File that clients can edit easily afterwards

    Hi
    Can anyone explain how I can put text into an edge file (styled with google fonts) and make it so that clients can access the text and update the text as they require?
    Previous suggestion was dynamically loading a .txt file - any instructions would be most appreciated.
    Thanks.

    Hi Resdesign!
    Your code is very useful to learn how to use Json in Adobe Edge Animate!
    But I have a question: why you use ( i ) as argument of the function UpdateInfo and when you recall it you use ( index )?
    $.getJSON('slides.json', function(data){
              //for(var i=0; i<data.length; i++){
    function updateInfo(i){
                        sym.$("photo").css({"background-image": "url('"+data[i].image+"')"});
                        sym.$("pillar").html(data[i].pillar);
                        sym.$("what").html(data[i].what);
                        // position
              index = -1;
              sym.$("btn").click(function(){
              index++;
                        if (index>=5){
                                  index = 0;
              updateInfo(index);
    Many thanks for your attention!
    Davide

  • How do you put edge animation in Magento?

    How do  you put edge animation in Magento please?

    Provide the name of the program you are using so a Moderator may move this message to the correct program forum
    This Cloud forum is not about help with program problems... a program would be Photoshop or Lighroom or Muse or ???

  • How do you put safari web pages into icloud with the safari iCloud button?

    how do you put safari web pages into icloud with the safari iCloud button?

    What that button does is sync your tabs between your devices. So if you have multiple macs with Mountain Lion and/or devices with iOS 6 (once it comes out this fall) you can pick up where you left off. For example, let's say I have apple.com, nytimes.com, and facebook.com open on my mac, but I need to run. Later, if I need to use another computer in my household, I can just restore the tabs that I was using before on this other mac.

  • How do I put an external display to sleep when I am using my MacBook Air for presentation?

    How do I put an external display to sleep when I am using my MacBook Air for presentation? I do not want to go to the projector just to turn it off and turn on again after a while? Is there a keyboard shortcut for that?

    I want to be able to sleep the external display and at the same time do things in the MacBook.( This feature is useful for me so that I can prepare some things and so that my audience will not see what I am about to show them.)
    Is there a feature for Mountain Lion?

  • How do i put a music icon on my iphone

    how do i put a music icone on my iphone

    Are you asking about a music icon instead of an "iPod" icon?
    If so, you need only to upgrade your iOS software.
    In iOS 5 Apple renamed iPod to music and in addition created a separate "videos" app, making iPhone consistent with iPod Touch and iPad devices.

  • How can I put my icloud photos to camera roll or photo stream?

    I got a nee iphone, i backed up everything and restored it into mu new iphone, but the pictures didn't restore so i did it manually but now on my phone i got different albums icloud photo stream and camera roll. How can i put the icloud picture into camera roll or photo stream. Any ideas?? On my old iphone ive deleted everything.

    Hello Ozzie94,
    Thanks for the additional information. The camera roll is designed for photos taken on your device, or saved images from Mail and other applications. Photos synced from a computer are organized into their own album(s):
    View photos and videos - iPhone
    http://help.apple.com/iphone/7/#/iph3d267610
    - Camera Roll—photos and videos you took on iPhone, or saved from an email, text message, webpage, or screenshot
    - Shared photos and videos—Photos and videos that you’ve shared with iCloud Photo Sharing or that others have shared with you (see iCloud Photo Sharing)
    - Photos and videos synced from your computer (see Sync with iTunes)
    Additionally, you may find more information by using another one of Apple's support resources - https://getsupport.apple.com
    Thanks,
    Matt M.

  • How do I put the music on my IPod onto the ITunes on my new computer? Help

    Just got a new computer. How do I put the music, ect. on my IPod onto the ITunes on the new computer?
    I downloaded ITunes onto the new computer, plugged in my Ipod, and a box popped up asking to either erase or transfer what was on my Ipod. I'd read before we put up the new computer that all you have to do is click the Transfer button and it will put all the music, ect. onto the ITunes account. Well, it didn't work. The page where it shows the bar that shows the memory is on the ITunes and shows exactly what it did on the old computer, but that's it. There's no music, nothing. I logged on to my ITunes account, that did nothing. What can I do? There has to be SOMETHING. Thanks so much!
    Message was edited by: tbatt

    1). Connect your iPod to your new computer. When you get the message that it is linked to a different library and asking if you want to link to this one and replace all your songs etc, press "Cancel". Pressing "Erase and Sync" will irretrievably remove all the songs from your iPod.
    2). When your iPod appears in the iTunes source list change the update setting to manual, that will let you continue to use your iPod without the risk of accidentally erasing it. Check the "manually manage music and videos" box in Summary then press the Apply button. Also when using most of the utilities listed below your iPod needs to be enabled for disc use, changing to manual update will do this by default: Managing content manually on iPod and iPhone
    3). Once you are connected and your iPod is safely in manual mode there are a few things you can do to restore your iTunes from the iPod. iTunes will only let you copy your iTunes Store purchases directly from an iPod to the computer, you'll find details in this article: Copying iTunes Store purchases from your iPod or iPhone to a computer
    For everything else (music from CDs, other downloads and including iTunes purchased songs and in some cases, videos and games) there are a number of third party utilities that you can use to retrieve the music files and playlists from your iPod. You'll find that they have varying degrees of functionality and some will transfer movies, videos, photos, podcasts and games as well. You can read reviews and comparisons of some of them here:
    Wired News - Rescue Your Stranded Tunes
    Comparison of iPod managers
    A selection of iPod to iTunes utilities:
    TuneJack Windows Only (iPhone and iPod Touch compatible)
    SharePod Windows Only (iPhone and iPod Touch compatible)
    iPod2PC Windows Only
    iDump Windows Only
    YamiPod Mac and Windows
    iPod Music Liberator Mac & Windows
    Floola Mac & Windows
    iPodRip Mac & Windows (iPhone and iPod Touch compatible)
    iPod Music Liberator Mac & Windows (iPhone and iPod Touch compatible)
    Music Rescue Mac & Windows (iPhone and iPod Touch compatible)
    iGadget Mac & Windows (iPhone and iPod Touch compatible)
    iRepo Mac & Windows (iPhone and iPod Touch compatible)
    iPod Access Mac & Windows (iPhone and iPod Touch compatible)
    TouchCopy Mac & Windows (iPhone and iPod Touch compatible)
    There's also a manual method of copying songs from your iPod to a Mac or PC. The procedure is a bit involved and won't recover playlists but if you're interested it's available on page 2 at this link: Copying Content from your iPod to your Computer - The Definitive Guide
    4). Whichever of these retrieval methods you choose, keep your iPod in manual mode until you have reloaded your iTunes and you are happy with your playlists etc then it will be safe to return it auto-sync.
    5). I would also advise that you get yourself an external hard drive and back your stuff up, relying on an iPod as your sole backup is not a good idea and external drives are comparatively inexpensive these days, you can get loads of storage for a reasonable outlay: Back up your iTunes library by copying to an external hard drive

  • How do i put creative cloud on another computer

    How do I put creative cloud on another computer

    Davidm29914240 for information on how install the Adobe Creative applications included with your membership please see Install and update apps - https://helpx.adobe.com/creative-cloud/help/install-apps.html.

Maybe you are looking for

  • Backing up with iOS 4 on a iPod Touch 2G

    I had to Restore the iPod Touch to get the iOS 4 onto it. This took forever (nearly 12 hours). I played around with the Folders and rearranged the nearly 300 Apps. Then I tried to Sync it. Well...it tried and tried, but eventually the screen on the i

  • 2x playstatio​n plus 1-year cards not activated

    hello! i bought these on 12/25/2013 at that time i had a bought a years worth of plus via the ps store. so when i got the call about the cards if they worked or not, i just said it worked fine. now fast foward to today, trying to redeem it now and it

  • Pre-configured standalone OC4J with PDK - ZIP corrupt - ??

    zip is corrupt, what can I do, who can I contact?? pre-configured standalone OC4J with PDK http://www.oracle.com/technology/products/ias/portal/files/pdk_oc4j_extended.zip found at page http://www.oracle.com/technology/products/ias/portal/pdk.html

  • N8 DAB Radio - now available in UK

    Just thought I would post the fact that today I bought the DAB Radio USB kit from my local Nokia Store - in fact it was the first one they sold. Had to go to Ovi Store to download the application onto the phone, but have tried it out and it works wel

  • Field LFM1-SPERM not updating

    Hello Wonder if anyone can help me? If this is in the wrong part of the Forum can someone point me in the right direction? SRM version 5.5 & ECC 6.0 When putting a block on a Vendor for Purchasing Orgs in transaction XK05  it is not replicating in SR