Help with SQL join

I've got a query where I'm joining several tables. One of the tables (schedule_status) has no rows to match for the join and it's causing no rows to be returned.. What I need for it to happen would be to return a -1 for c_schedulestatusid..
This is what I have
select distinct li.location as locationid, li.city, li.state as stateid, li.descr as location,
s.state, sl.name as mgrname, 'default' as locationtype, c_schedulestatusid
from location_info li
left outer join states s on li.state = s.abbreviation
left outer join mvw_sm_location sl on li.location = sl.location
left outer join schedule_status ss on li.location = ss.location
where li.emplid = '0087890'
and year = 2007
and week = 11This is the part that returns no data
select c_schedulestatusid
from schedule_status
where year = 2007
and week = 11
and location = 4131I've tried using nvl() and a couple other tricks but I can't get it to work... Thanks!

Maybe it's bacause I don't have real/sample data.
here is my sample data, states and mvw_sm_location doesn't have any row
SQL> select * from location_info;
LOCATION   CITY       STATE      DESCR      EMPLID
4131                                        0087890
3376                                        0087890
SQL> select * from schedule_status;
C_SCHEDULE       YEAR       WEEK LOCATION
1                2007          3 3376
here is the result with location=3376 outside inline query
SQL> set autotrace on expl
SQL> select distinct li.location as locationid, li.city,
  2         li.state as stateid, li.descr as location,
  3         s.state, sl.name as mgrname, 'default' as locationtype,
  4         nvl(c_schedulestatusid,-1) c_schedulestatusid
  5  from location_info li
  6       left outer join states s on li.state = s.abbreviation
  7       left outer join mvw_sm_location sl on li.location = sl.location
  8       left outer join ( select location, c_schedulestatusid
  9                         from schedule_status
10                         where year = 2007
11                         and week = 3 ) ss
12       on li.location = ss.location
13  where li.emplid = '0087890' and li.location = 3376;
LOCATIONID CITY       STATEID    LOCATION   STATE      MGRNAME    LOCATIO C_SCHEDULE
3376                                                              default 1
Execution Plan
Plan hash value: 115315777
| Id  | Operation             | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT      |                 |     1 |    55 |    13  (24)| 00:00:01 |
|   1 |  HASH UNIQUE          |                 |     1 |    55 |    13  (24)| 00:00:01 |
|*  2 |   HASH JOIN OUTER     |                 |     1 |    55 |    12  (17)| 00:00:01 |
|*  3 |    HASH JOIN OUTER    |                 |     1 |    41 |     8  (13)| 00:00:01 |
|*  4 |     HASH JOIN OUTER   |                 |     1 |    27 |     6  (17)| 00:00:01 |
|*  5 |      TABLE ACCESS FULL| LOCATION_INFO   |     1 |    13 |     3   (0)| 00:00:01 |
|   6 |      TABLE ACCESS FULL| STATES          |     1 |    14 |     2   (0)| 00:00:01 |
|   7 |     TABLE ACCESS FULL | MVW_SM_LOCATION |     1 |    14 |     2   (0)| 00:00:01 |
|*  8 |    TABLE ACCESS FULL  | SCHEDULE_STATUS |     1 |    14 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   2 - access("LI"."LOCATION"="LOCATION"(+))
   3 - access("LI"."LOCATION"="SL"."LOCATION"(+))
   4 - access("LI"."STATE"="S"."ABBREVIATION"(+))
   5 - filter("LI"."EMPLID"='0087890' AND TO_NUMBER("LI"."LOCATION")=3376)
   8 - filter("YEAR"(+)=2007 AND "WEEK"(+)=3)
here is the result with location=3376 inside inline query
SQL> select distinct li.location as locationid, li.city,
  2         li.state as stateid, li.descr as location,
  3         s.state, sl.name as mgrname, 'default' as locationtype,
  4         nvl(c_schedulestatusid,-1) c_schedulestatusid
  5  from location_info li
  6       left outer join states s on li.state = s.abbreviation
  7       left outer join mvw_sm_location sl on li.location = sl.location
  8       left outer join ( select location, c_schedulestatusid
  9                         from schedule_status
10                         where year = 2007
11                         and week = 3
12                         and location = 3376 ) ss
13       on li.location = ss.location
14  where li.emplid = '0087890' ;
LOCATIONID CITY       STATEID    LOCATION   STATE      MGRNAME    LOCATIO C_SCHEDULE
3376                                                              default 1
4131                                                              default -1
Execution Plan
Plan hash value: 115315777
| Id  | Operation             | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT      |                 |     1 |    55 |    13  (24)| 00:00:01 |
|   1 |  HASH UNIQUE          |                 |     1 |    55 |    13  (24)| 00:00:01 |
|*  2 |   HASH JOIN OUTER     |                 |     2 |   110 |    12  (17)| 00:00:01 |
|*  3 |    HASH JOIN OUTER    |                 |     2 |    82 |     8  (13)| 00:00:01 |
|*  4 |     HASH JOIN OUTER   |                 |     2 |    54 |     6  (17)| 00:00:01 |
|*  5 |      TABLE ACCESS FULL| LOCATION_INFO   |     2 |    26 |     3   (0)| 00:00:01 |
|   6 |      TABLE ACCESS FULL| STATES          |     1 |    14 |     2   (0)| 00:00:01 |
|   7 |     TABLE ACCESS FULL | MVW_SM_LOCATION |     1 |    14 |     2   (0)| 00:00:01 |
|*  8 |    TABLE ACCESS FULL  | SCHEDULE_STATUS |     1 |    14 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   2 - access("LI"."LOCATION"="LOCATION"(+))
   3 - access("LI"."LOCATION"="SL"."LOCATION"(+))
   4 - access("LI"."STATE"="S"."ABBREVIATION"(+))
   5 - filter("LI"."EMPLID"='0087890')
   8 - filter("YEAR"(+)=2007 AND "WEEK"(+)=3 AND TO_NUMBER("LOCATION"(+))=3376)
Your last query give the same result but with more costly execution plan
SQL> select *
  2  from (
  3     select to_char(a.location) locationid,
  4                 a.c_schedulestatusid + nvl(b.c_schedulestatusid,0) as c_schedulestatusid
  5     from
  6     (
  7             select distinct to_char(location) location, -1 as c_schedulestatusid
  8             from location_info
  9     ) a
10     full outer join
11     (
12             select location, c_schedulestatusid + 1 as c_schedulestatusid
13             from schedule_status
14             where week = 3
15             and year = 2007
16     ) b
17     on b.location = a.location
18  ) status
19  right outer join
20  (
21     select distinct li.location as locationid, li.city,
22                 li.state as stateid, li.descr as location,
23            s.state, sl.name as mgrname
24     from location_info li
25     left outer join states s on li.state = s.abbreviation
26     left outer join mvw_sm_location sl on li.location = sl.location
27     where emplid = '0087890'
28  ) locations
29  on locations.locationid = status.locationid;
LOCATIONID C_SCHEDULESTATUSID LOCATIONID CITY       STATEID    LOCATION   STATE      MGRNAME
3376                        1 3376
4131                       -1 4131
Execution Plan
Plan hash value: 2617725192
| Id  | Operation               | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT        |                 |     2 |   130 |    24  (21)| 00:00:01 |
|*  1 |  HASH JOIN OUTER        |                 |     2 |   130 |    24  (21)| 00:00:01 |
|   2 |   VIEW                  |                 |     1 |    42 |     9  (23)| 00:00:01 |
|   3 |    HASH UNIQUE          |                 |     1 |    41 |     9  (23)| 00:00:01 |
|*  4 |     HASH JOIN OUTER     |                 |     2 |    82 |     8  (13)| 00:00:01 |
|*  5 |      HASH JOIN OUTER    |                 |     2 |    54 |     6  (17)| 00:00:01 |
|*  6 |       TABLE ACCESS FULL | LOCATION_INFO   |     2 |    26 |     3   (0)| 00:00:01 |
|   7 |       TABLE ACCESS FULL | STATES          |     1 |    14 |     2   (0)| 00:00:01 |
|   8 |      TABLE ACCESS FULL  | MVW_SM_LOCATION |     1 |    14 |     2   (0)| 00:00:01 |
|   9 |   VIEW                  |                 |     3 |    69 |    14  (15)| 00:00:01 |
|  10 |    UNION-ALL            |                 |       |       |            |          |
|  11 |     VIEW                |                 |     2 |    34 |     8  (25)| 00:00:01 |
|  12 |      HASH UNIQUE        |                 |     2 |    54 |     8  (25)| 00:00:01 |
|* 13 |       HASH JOIN OUTER   |                 |     2 |    54 |     7  (15)| 00:00:01 |
|  14 |        TABLE ACCESS FULL| LOCATION_INFO   |     2 |    26 |     3   (0)| 00:00:01 |
|* 15 |        TABLE ACCESS FULL| SCHEDULE_STATUS |     1 |    14 |     3   (0)| 00:00:01 |
|* 16 |     HASH JOIN ANTI      |                 |     1 |    19 |     7  (15)| 00:00:01 |
|* 17 |      TABLE ACCESS FULL  | SCHEDULE_STATUS |     1 |    14 |     3   (0)| 00:00:01 |
|  18 |      TABLE ACCESS FULL  | LOCATION_INFO   |     2 |    10 |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - access("LOCATIONS"."LOCATIONID"=INTERNAL_FUNCTION("A"."LOCATION"(+)))
   4 - access("LI"."LOCATION"="SL"."LOCATION"(+))
   5 - access("LI"."STATE"="S"."ABBREVIATION"(+))
   6 - filter("LI"."EMPLID"='0087890')
  13 - access("LOCATION"(+)=INTERNAL_FUNCTION("LOCATION"))
  15 - filter("WEEK"(+)=3 AND "YEAR"(+)=2007)
  16 - access("LOCATION"=INTERNAL_FUNCTION("LOCATION"))
  17 - filter("WEEK"=3 AND "YEAR"=2007)Cheers,
NH.

Similar Messages

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Help with Inner Join query in SQL

    Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
    My table structure is :
    table_packages
    packageID
    package
    packageDetails
    etc
    table_destinations
    destinationID
    destination
    destinationDetails
    etc
    table_packagedestinations
    packageID
    destinationID
    ..so nothing that complicated.
    So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
    So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
    This is the PHP from the header, including my INNER JOIN query....
    PHP Code:
    <?php
    $ParampackageID_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    $ParamSessionpackageID_WADApackages = "-1";
    if (isset($_SESSION['WADA_Insert_packages'])) {
      $ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
    $ParampackageID2_WADApackages = "-1";
    if (isset($_GET['packageID'])) {
      $ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
    mysql_select_db($database_connPackages, $connPackages);
    $query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
    $WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
    $row_WADApackages = mysql_fetch_assoc($WADApackages);
    $totalRows_WADApackages = mysql_num_rows($WADApackages);
    $colname_educationalDestinations = "1";
    if (isset($_GET['PackageID'])) {
      $colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
    mysql_select_db($database_connPackages, $connPackages);
    $query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
    $educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
    $row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
    $totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
    ?>
    And where I'm trying to display the destinations themselves, I have : 
    <table>
            <tr>
                     <td>Destinations :</td>
                </tr>
               <?php do { ?>
            <tr>
                 <td><?php echo $row_educationalDestinations['destination']; ?></td>
            </tr>
            <?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
    </table>
    If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working. 
    Thanks.

    First off, you need to get the database tables so that there is a relationship between them.
    In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
    table_packages
    packageID
    package
    packageDetails
    destination
    destinationDetails
    etc
    If there is a one to many relationship, then the following would be true
    packages
    packageID
    package
    packageDetails
    etc
    destinations
    destinationID
    packageID
    destination
    destinationDetails
    etc
    The above assumes that there are many destinations to one package with the relationship coloured orange.
    Once you have the above correct you can apply your query as follows
    SELECT *
    FROM packages
    INNER JOIN destinations
    ON packages.packageID = destinations.packageID
    WHERE packages.packageID = %s
    ORDER BY destination ASC
    The above query will show all packages with relevant destinations

  • Need help with query joining several tables into a single return line

    what i have:
    tableA:
    puid, task
    id0, task0
    id1, task1
    id2, task2
    tableB:
    puid, seq, state
    id0, 0, foo
    id0, 1, bar
    id0, 2, me
    id1, 0, foo
    id2, 0, foo
    id2, 1, bar
    tableC:
    puid, seq, date
    id0, 0, 12/21
    id0, 1, 12/22
    id0, 2, 12/22
    id1, 0, 12/23
    id2, 0, 12/22
    id2, 1, 12/23
    what i'd like to return:
    id0, task0, 12/21, 12/22, 12/22
    id1, task1, 12/23, N/A, N/A
    id2, task2, 12/22, 12/23, N/A
    N/A doesn't mean return the string "N/A"... it just means there was no value, so we don't need anything in this column (null?)
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line...
    id0, task0, 12/21
    id0, task0, 12/22
    id0, task0, 12/23
    id1, task1, 12/23
    is this possible fairly easily?
    Edited by: user9979830 on Mar 29, 2011 10:53 AM
    Edited by: user9979830 on Mar 29, 2011 10:58 AM

    Hi,
    Welcome to the forum!
    user9979830 wrote:
    what i have:...Thanks for posting that so clearly!
    Whenever you have a question, it's even better if you post CREATE TABLE and INSERT statements for your sample data, like this:
    CREATE TABLE     tablea
    (       puid     VARCHAR2 (5)
    ,     task     VARCHAR2 (5)
    INSERT INTO tablea (puid, task) VALUES ('id0',  'task0');
    INSERT INTO tablea (puid, task) VALUES ('id1',  'task1');
    INSERT INTO tablea (puid, task) VALUES ('id2',  'task2');
    CREATE TABLE     tablec
    (       puid     VARCHAR2 (5)
    ,     seq     NUMBER (3)
    ,     dt     DATE          -- DATE is not a good column name
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  0,  DATE '2010-12-21');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  1,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id0',  2,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id1',  0,  DATE '2010-12-23');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  0,  DATE '2010-12-22');
    INSERT INTO tablec (puid, seq, dt) VALUES ('id2',  1,  DATE '2010-12-23');This way, people can re-create the problem and test their ideas.
    It doesn't look like tableb plays any role in this problem, so I didn't post it.
    Explain how you get the results from that data. For example, why do you want this row in the results:
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/21/2010 12/22/2010 12/22/2010rather than, say
    PUID  TASK  DT1        DT2        DT3
    id0   task0 12/22/2010 12/21/2010 12/22/2010? Does 12/21 have to go in the first column because it is the earliest date, or is it because 12/21 is related to the lowest seq value? Or do you even care about the order, just as long as all 3 dates are shown?
    Always say what version of Oracle you're uisng. The query below will work in Oracle 9 (and up), but starting in Oracle 11, the SELECT ... PIVOT feature could help you.
    i can get output like below through several joins, however i was hoping to condense each "id" into a single line... Condensing the output, so that there's only one line for each puid, sounds like a job for "GROUP BY puid":
    WITH     got_r_num     AS
         SELECT     puid
         ,     dt
         ,     ROW_NUMBER () OVER ( PARTITION BY  puid
                                   ORDER BY          seq          -- and/or dt
                           )         AS r_num
         FROM    tablec
    --     WHERE     ...     -- If you need any filtering, put it here
    SELECT       a.puid
    ,       a.task
    ,       MIN (CASE WHEN r.r_num = 1 THEN r.dt END)     AS dt1
    ,       MIN (CASE WHEN r.r_num = 2 THEN r.dt END)     AS dt2
    ,       MIN (CASE WHEN r.r_num = 3 THEN r.dt END)     AS dt3
    ,       MIN (CASE WHEN r.r_num = 4 THEN r.dt END)     AS dt4
    FROM       tablea    a
    JOIN       got_r_num r  ON   a.puid  = r.puid
    GROUP BY  a.puid
    ,            a.task
    ORDER BY  a.puid
    ;I'm guessing that you want the dates arranged by seq; that is, for each puid, the date related to the lowest seq comes first, regardless of whther that date is the earliest date for that puid or not. If that's not what you need, then change the analytic ORDER BY clause.
    This does not assume that the seq values are always consecutive integers (0, 1, 2, ...) for each puid. You can skip, or even duplicate values. However, if the values are always consecutive integers, starting from 0, then you could simplify this. You won't need a sub-query at all; just use seq instead of r_num in the main query.
    Here's the output I got from the query above:
    PUID  TASK  DT1        DT2        DT3        DT4
    id0   task0 12/21/2010 12/22/2010 12/22/2010
    id1   task1 12/23/2010
    id2   task2 12/22/2010 12/23/2010As posted, the query will display the first 4 dts for each puid.
    If there are fewer than 4 dts for a puid, the query will still work. It will leave some columns NULL at the end.
    If there are more than 4 dts for a puid, the query will still work. It will display the first 4, and ignore the others.
    There's nothing special about the number 4; you could make it 3, or 5, or 35, but whatever number you choose, you have to hard-code that many columns into the query, and always get that many columns of output.
    For various ways to deal with a variable number of pivoted coolumns, see the following thread:
    PL/SQL
    This question actually doesn't have anything to do with SQL*Plus; it's strictly a SQL question, and SQL questions are best posted on the "SQL and PL/SQL" forum:
    PL/SQL
    If you're not sure whether a question is more of a SQL question or a SQL*Plus question, then post it on the SQL forum. Many more people pay attention to that forum than to this one.

  • Where clause "where 1=1" help with SQL tuning

    Hello Tuning experts,
    Is it helpful to use "where 1=1" and then put all the joins and conditions in the "AND" statements of the SQL when writing SQL queries. I would like to know if it helps with query performance to write SQL queirs that way.
    Thanks in advance.
    Edited by: oracle_developer on Oct 8, 2012 10:41 AM

    You can see here that "where 1 = 1" is gone from the predicate info in the explain plan.
    The optimizer simply discarded it.
    SQL> explain plan for
      2  select *
      3  from emp
      4  where 1 = 1
      5  and job = 'SALESMAN';
    Explained.
    PLAN_TABLE_OUTPUT
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     3 |   114 |     3   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| EMP  |     3 |   114 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("JOB"='SALESMAN')
    13 rows selected.

  • Where to find help with SQL Developer installation?

    Hi,
    I just want to try out SQL Developer and compare its capabilities to TOAD's. Unfortunately, I am not PC software savvy and now am stuck with a SQL Developer (sqldeveloper-1.2.2998) installation problem. When I clicked on the .exe file, I got a blank SQL Developer screen - there is nothing in the screen except a heading that reads 'Oracle SQL Developer'...
    Does anyone know of a blog or a site that I can get some help with problems like mine?
    Any help is much appreciated!

    Hi,
    SQL Developer forum link:
    "http://forums.oracle.com/forums/forum.jspa?forumID=260"
    There are 2 versions of SQL Developer, with/without JRE.
    Try out the full install version with JRE.
    HTH
    Zack

  • Need help with SQL*Loader not working

    Hi all,
    I am trying to run SQL*Loader on Oracle 10g UNIX platform (Red Hat Linux) with below command:
    sqlldr userid='ldm/password' control=issue.ctl bad=issue.bad discard=issue.txt direct=true log=issue.log
    And get below errors:
    SQL*Loader-128: unable to begin a session
    ORA-01034: ORACLE not available
    ORA-27101: shared memory realm does not exist
    Linux-x86_64 Error: 2: No such file or directory
    Can anyone help me out with this problem that I am having with SQL*Loader? Thanks!
    Ben Prusinski

    Hi Frank,
    More progress, I exported the ORACLE_SID and tried again but now have new errors! We are trying to load an Excel CSV file into a new table on our Oracle 10g database. I created the new table in Oracle and loaded with SQL*Loader with below problems.
    $ export ORACLE_SID=PROD
    $ sqlldr 'ldm/password@PROD' control=prod.ctl log=issue.log bad=bad.log discard=discard.log
    SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Control File: prod.ctl
    Data File: prod.csv
    Bad File: bad.log
    Discard File: discard.log
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array: 64 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table TESTLD, loaded from every logical record.
    Insert option in effect for this table: REPLACE
    Column Name Position Len Term Encl Datatype
    ISSUE_KEY FIRST * , CHARACTER
    TIME_DIM_KEY NEXT * , CHARACTER
    PRODUCT_CATEGORY_KEY NEXT * , CHARACTER
    PRODUCT_KEY NEXT * , CHARACTER
    SALES_CHANNEL_DIM_KEY NEXT * , CHARACTER
    TIME_OF_DAY_DIM_KEY NEXT * , CHARACTER
    ACCOUNT_DIM_KEY NEXT * , CHARACTER
    ESN_KEY NEXT * , CHARACTER
    DISCOUNT_DIM_KEY NEXT * , CHARACTER
    INVOICE_NUMBER NEXT * , CHARACTER
    ISSUE_QTY NEXT * , CHARACTER
    GROSS_PRICE NEXT * , CHARACTER
    DISCOUNT_AMT NEXT * , CHARACTER
    NET_PRICE NEXT * , CHARACTER
    COST NEXT * , CHARACTER
    SALES_GEOGRAPHY_DIM_KEY NEXT * , CHARACTER
    value used for ROWS parameter changed from 64 to 62
    Record 1: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 2: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 3: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 4: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 5: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 6: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 7: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 8: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 9: Rejected - Error on table ISSUE_FACT_TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 10: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 11: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 12: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 13: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 14: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 15: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 16: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 17: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 18: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 19: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 20: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 21: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 22: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 23: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 24: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 39: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    MAXIMUM ERROR COUNT EXCEEDED - Above statistics reflect partial run.
    Table TESTLD:
    0 Rows successfully loaded.
    51 Rows not loaded due to data errors.
    0 Rows not loaded because all WHEN clauses were failed.
    0 Rows not loaded because all fields were null.
    Space allocated for bind array: 255936 bytes(62 rows)
    Read buffer bytes: 1048576
    Total logical records skipped: 0
    Total logical records read: 51
    Total logical records rejected: 51
    Total logical records discarded: 0
    Run began on Tue May 23 11:04:28 2006
    Run ended on Tue May 23 11:04:28 2006
    Elapsed time was: 00:00:00.14
    CPU time was: 00:00:00.01
    [oracle@casanbdb11 sql_loader]$
    Here is the control file:
    LOAD DATA
    INFILE issue_fact.csv
    REPLACE
    INTO TABLE TESTLD
    FIELDS TERMINATED BY ','
    ISSUE_KEY,
    TIME_DIM_KEY,
    PRODUCT_CATEGORY_KEY,
    PRODUCT_KEY,
    SALES_CHANNEL_DIM_KEY,
    TIME_OF_DAY_DIM_KEY,
    ACCOUNT_DIM_KEY,
    ESN_KEY,
    DISCOUNT_DIM_KEY,
    INVOICE_NUMBER,
    ISSUE_QTY,
    GROSS_PRICE,
    DISCOUNT_AMT,
    NET_PRICE,
    COST,
    SALES_GEOGRAPHY_DIM_KEY
    )

  • Please help with SQL amount calulation

    -- Results
    with t as ( 
    select 'P11877' Mstr_Program,   1 Year_of_study, 'BUSI1490' program_module,  20 no_of_stud,    1 rank,   30 program_credits,  30 cumm_credits   from dual union all
    select 'P11877',                1,              'COMP1365',                 20,               2,        30,                  60               from dual union all
    select 'P11877',                1,              'BUSI1375',                 20,               3,        30,                  90               from dual union all
    select 'P11877',                1,              'COMP1363',                 20,               4,        30,                  120              from dual union all
    select 'P11877',                2,              'MARK1174',                 8,                1,        30,                  30               from dual union all
    select 'P11877',                2,              'FINA1068',                 8,                2,        15,                  45               from dual union all
    select 'P11877',                2,              'INDU1062',                 8,                3,        30,                  75               from dual union all
    select 'P11877',                2,              'BUSI1329',                 8,                4,        15,                  90               from dual union all
    select 'P11877',                2,              'MARK1138',                 8,                5,        30,                  120              from dual)
    select * from t;-- Each MSTR_PROGRAM can have 1 or many program_module
    -- MSTR_PROGRAM's can run for 1 or 2 years (case above is two years) so some modules run in year 1 and some in year 2
    -- NO_OF_STUD is the number of students on the module
    -- RANK basically ranks the modules by the number of students on them grouped by program and year
    -- e.g.row_number() OVER (PARTITION BY Mstr_Program, Year_of_study) ORDER BY COUNT(STUDENT_ID) DESC) rank
    -- PROGRAM_CREDITS: each module has a fixed number of credits
    -- CUMM_CREDITS: Increments the credit count of modules
    -- SUM(program_credits * 10) OVER (PARTITION BY Mstr_Program, Year_of_study
    -- ORDER BY count(STUDENT_ID) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    -- I want to trim of any modules once the CUM_CREDITS hits 120. As seen above. I achieve this by wrapping the main query is another SELECT then LIMIT
    -- that WHERE cum_credit <=120.
    -- But what I need is:
    -- In some cases the the cumm_credit maybe on lets say 90credits then the next module is worth 40 credits. This next module will not show as it
    -- will be greater than 120 credits, so i need to pro-rata it:
    -- So if credit_count > 120, then the last module is counted pro-rata as follows: 1- ((credit count - 120) / credits from last module
    -- Can anyone help with how I can incorporate this into my current code: The SELECT portion of the Original SQL is below: I simplified column names
    -- e.t.c in the above so they wont be the same
    SELECT * FROM (
         SELECT
               ,SR_PROGRAM Mstr_Program
               ,DECODE (SORLCUR_YEAR, 1, 1,
                                      2, 2,
                                      3, 3,
                                      4, 3, SR_YEAR) year_of_study
               ,SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module
               ,COUNT(student_ID)                    no_of_stud
               ,row_number() OVER (PARTITION BY sr_program,
                                            DECODE (sr_year, 1, 1,
                                                                  2, 2,
                                                                  3, 3,
                                                                  4, 3, SR_YEAR) ORDER BY COUNT(student_id) DESC, scbcrse_title asc) rank
               ,(SCT_CREDIT_HRS * 10) program_credits
               ,SUM(SCT_CREDIT_HRS * 10) OVER (PARTITION BY sr_program, DECODE (sorlcur_year, 1, 1,
                                                                                                       2, 2,
                                                                                                       3, 3,
                                                                                                       4, 3, SR_YEAR)
                                                    ORDER BY count(student_id) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    WHERE cumm_credit <=120
    ORDER BY Mstr_Program, YEAR_OF_STUDY, RANK asc;

    Maybe
    SELECT Mstr_Program,year_of_study,program_module,no_of_stud,rank,program_credits old_program_credits,cumm_credits old_cumm_credits,
           case when cumm_credits > 120
                then program_credits - cumm_credits + 120
                else program_credits
           end new_program_credits,
           case when cumm_credits > 120
                then 120
                else cumm_credits
           end new_cumm_credits
      FROM (SELECT SR_PROGRAM Mstr_Program,
                   DECODE(SORLCUR_YEAR,1,1,2,2,3,3,4,3,SR_YEAR) year_of_study,
                   SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module,
                   COUNT(student_ID) no_of_stud,
                   row_number() OVER (PARTITION BY sr_program,DECODE(sr_year,1,1,2,2,3,3,4,3,SR_YEAR)
                                          ORDER BY COUNT(student_id) DESC,scbcrse_title) rank,
                   10 * SCT_CREDIT_HRS program_credits,
                   10 * SUM(SCT_CREDIT_HRS) OVER (PARTITION BY sr_program,DECODE(sorlcur_year,1,1,2,2,3,3,4,3,SR_YEAR)
                                                      ORDER BY count(student_id) desc
                                                  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    WHERE 0 <= case when cumm_credits > 120
                     then program_credits - cumm_credits + 120
                     else program_credits
                end
    ORDER BY Mstr_Program,YEAR_OF_STUDY,RANKRegards
    Etbin
    Edited by: Etbin on 16.12.2011 8:50
    with
    t as   /* simulating the result achieved */
    (select 'P11877' Mstr_Program,1 Year_of_study, 'BUSI1490' program_module,20 no_of_stud,1 rank,30 program_credits,30 cumm_credits from dual union all
    select 'P11877',             1,               'COMP1365',               20,           2,     40,                70              from dual union all
    select 'P11877',             1,               'BUSI1375',               20,           3,     30,                100             from dual union all
    select 'P11877',             1,               'COMP1363',               20,           4,     40,                140             from dual union all
    select 'P11877',             2,               'MARK1174',               8,            1,     30,                30              from dual union all
    select 'P11877',             2,               'FINA1068',               8,            2,     50,                80              from dual union all
    select 'P11877',             2,               'INDU1062',               8,            3,     30,                110             from dual union all
    select 'P11877',             2,               'BUSI1329',               8,            4,     50,                160             from dual union all
    select 'P11877',             2,               'MARK1138',               8,            5,     30,                190             from dual
    select Mstr_Program,Year_of_study,program_module,no_of_stud,rank,program_credits old_credits,cumm_credits old_cumm,
           case when cumm_credits > 120
                then program_credits - cumm_credits + 120
                else program_credits
           end new_program_credits,
           case when cumm_credits > 120
                then 120
                else cumm_credits
           end new_cumm_credits
      from t
    where 0 <= case when cumm_credits > 120
                     then program_credits - cumm_credits + 120
                     else program_credits
                end

  • Help with SQL Server 2005 http Endpoint

    I am trying to use mx:webservice to directly connect to a SQL
    Server 2005 HTTP Endpoint. Is this possible. Is there going to be a
    problem with crossdomain issues? If the Endpoint is actively
    listening on port 80 then IIS cannot. So I cannot place
    crossdomain.xml in webserver, how will I overcome this crossdomain
    problem? Am I making this more complicated than it is? If anyone
    has an example it would be appreciated. All I want is a flex2 app
    talking directly to sql server. Seems possible.

    Kent, I see that many others have reported that error (doing
    a google search), but I see no ready answers. I saw something that
    reminded me of a connection string value that I've seen answer some
    problems. May be worth a shot for you: try adding this string to
    the connection string (in "advanced options") for your datasource:
    AuthenticationMethod=Type2
    If it doesn't solve it, remove it. But keep it handy in case
    it ever may help with some other problem.
    Here's one other possible answer for you:
    http://www.webmasterkb.com/Uwe/Forum.aspx/coldfusion-server/3206/SQL-Server-2000-Windows-A uth
    Sorry I can't be more clear for you.

  • Need help with self join query

    Hello,
    I have table A with the following data
    oid parent_oid
    10 4
    4 2
    2 2
    12 6
    6 6
    parent_oid is the parent of oid. I'd like a query that shows the final parent of the oid. The result should show the following
    oid final parent
    10 2
    4 2
    2 2
    12 6
    6 6
    I'm using Oracle 10g. I'm familiar with self joins, but that alone will not do the job. Thanks!

    Hi,
    arizona9952 wrote:
    ... I'm familiar with self joins, but that alone will not do the job.You're absolutely right!
    A 2-way self join would work for rows have no parent, or rows that are directly connected to their final ancestor (such as oid=4), but not for anything farther away.
    A 3-way self-join would work for one more level away from the final row, but no more. That would be enough for the small set of sample data that you posted, but it would not work if you added a new row with parent_id=10.
    An N-way self-join would work for up to N+1 levels, but no more.
    You need something that can go any number of levels, such as CONNECT BY:
    SELECT     CONNECT_BY_ROOT oid     AS oid
    ,     parent_oid          AS final_parent
    FROM     a
    WHERE     CONNECT_BY_ISLEAF     = 1
    CONNECT BY     oid     = PRIOR parent_oid
         AND     oid     != parent_oid
    ;Edited by: Frank Kulash on Feb 22, 2010 7:09 PM
    Upon sober reflection, I think that a Top-Down query, like the one below, would be more efficient than a Bottom-Up query, like the one above:
    SELECT     oid
    ,     CONNECT_BY_ROOT     parent_oid     AS final_parent
    FROM     a
    START WITH     parent_oid     = oid
    CONNECT BY     parent_oid     = PRIOR oid
         AND     oid          != PRIOR oid
    ;

  • I need help with SQL query

    Hi All,
    I have a problem in the query below. When I run the query I got a pop-up screen to ente value for
    :total_balance,
    :emp_code,
    :from_date,
    :to_date
    total_balance supose to be a result of a calculation.
    Your assistance is apreciated. Thanks,
    Ribhi
    select      FK_VOUCHERSERIAL_N,
         FK_VOUCHERVALUE_DA,
         DESCRIPTION,
         nvl(AMOUNT,0) amount,
         TYPE,
         Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) postive_amount,
         Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) negative_amount,
         Accnt101.total_balanceformula(:total_balance, EMPLOYEE_TRANSACTI.TYPE,Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) ,Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) , nvl(AMOUNT,0)) total_balance
    from      EMPLOYEE_TRANSACTI
    where     FK_EMPLOYEENUMBER0=:emp_code
    and     STATUS=1
    and     FK_VOUCHERVALUE_DA<=:to_date
    and     FK_VOUCHERVALUE_DA>=:from_date
    and     ((TYPE >7 and TYPE <16)
         or (TYPE >34 and TYPE <43)
         or (TYPE =7)
         or (TYPE =18)
         or (TYPE >26 and TYPE <35)
         or (TYPE =17)
         OR (TYPE = 60)
         OR (TYPE = 70)
    OR (TYPE = 72)
    OR (TYPE = 73)
    OR (TYPE = 74)
         or (type = 21)
         or (type =24)
         or (type = 81)
         or (type = 82))
    order by      FK_VOUCHERVALUE_DA asc, FK_VOUCHERSERIAL_N asc, type desc

    Hi Satyaki,
    My problem is with SQL and PL/SQL codd. I managed to convert some of my reports and now I'm facing a problem with converted SQL and PL/SQL code. To give you an Idea the following is a sample of a converted report.
    Pls have a look. (p.s how can i post formated text)
    Thanks,
    Ribhi
    1 - XML template file
    <?xml version="1.0" encoding="UTF-8" ?>
    - <dataTemplate name="Accnt101" defaultPackage="Accnt101" version="1.0">
    - <properties>
    <property name="xml_tag_case" value="upper" />
    </properties>
    - <parameters>
    <parameter name="FROM_DATE" dataType="date" defaultValue="01/01/1998" />
    <parameter name="TO_DATE" dataType="date" defaultValue="31/12/1998" />
    <parameter name="EMP_CODE" dataType="number" defaultValue="44" />
    </parameters>
    <lexicals />
    - <dataQuery>
    - <sqlStatement name="employee_trans">
    - <![CDATA[
    select      FK_VOUCHERSERIAL_N,
         FK_VOUCHERVALUE_DA,
         DESCRIPTION,
         nvl(AMOUNT,0) amount,
         TYPE,
         Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) postive_amount,
         Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) negative_amount,
         Accnt101.total_balanceformula(:total_balance, EMPLOYEE_TRANSACTI.TYPE,Accnt101.negative_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) ,Accnt101.postive_amountformula(EMPLOYEE_TRANSACTI.TYPE, nvl(AMOUNT,0)) , nvl(AMOUNT,0)) total_balance
    from      EMPLOYEE_TRANSACTI
    where     FK_EMPLOYEENUMBER0=:emp_code
    and     STATUS=1
    and     FK_VOUCHERVALUE_DA<=:to_date
    and     FK_VOUCHERVALUE_DA>=:from_date
    and     ((TYPE >7 and TYPE <16)
         or (TYPE >34 and TYPE <43)
         or (TYPE =7)
         or (TYPE =18)
         or (TYPE >26 and TYPE <35)
         or (TYPE =17)
         OR (TYPE = 60)
         OR (TYPE = 70)
                    OR (TYPE = 72)
                    OR (TYPE = 73)
                    OR (TYPE = 74)
         or (type = 21)
         or (type =24)
         or (type = 81)
         or (type = 82))
    order by      FK_VOUCHERVALUE_DA asc, FK_VOUCHERSERIAL_N asc, type desc
      ]]>
    </sqlStatement>
    - <sqlStatement name="employee">
    - <![CDATA[
    select NAME,NUMBER0
    from EMPLOYEE
    where  NUMBER0=:emp_code
      ]]>
    </sqlStatement>
    </dataQuery>
    <dataTrigger name="beforeReportTrigger" source="Accnt101.beforereport" />
    - <dataStructure>
    - <group name="G_employee_trans" dataType="varchar2" source="employee_trans">
    <element name="FK_VOUCHERSERIAL_N" dataType="number" value="FK_VOUCHERSERIAL_N" />
    <element name="FK_VOUCHERVALUE_DA" dataType="date" value="FK_VOUCHERVALUE_DA" />
    <element name="DESCRIPTION" dataType="varchar2" value="DESCRIPTION" />
    <element name="AMOUNT" dataType="number" value="AMOUNT" />
    <element name="postive_amount" dataType="number" value="postive_amount" />
    <element name="negative_amount" dataType="number" value="negative_amount" />
    <element name="total_balance" dataType="number" value="total_balance" />
    <element name="TYPE" dataType="number" value="TYPE" />
    <element name="CS_1" function="sum" dataType="number" value="G_employee_trans.total_balance" />
    </group>
    - <group name="G_employee" dataType="varchar2" source="employee">
    <element name="NUMBER0" dataType="number" value="NUMBER0" />
    <element name="NAME" dataType="varchar2" value="NAME" />
    </group>
    <element name="balance" dataType="number" value="Accnt101.balance_p" />
    <element name="CS_2" function="count" dataType="number" value="G_employee.NUMBER0" />
    <element name="CS_3" function="count" dataType="number" value="G_employee_trans.AMOUNT" />
    </dataStructure>
    </dataTemplate>
    2 - PLS/SQL package
    CREATE OR REPLACE PACKAGE Accnt101 AS
         from_date     date;
         to_date     date;
         emp_code     number;
         balance     number := 0 ;
         function postive_amountformula(TYPE in number, amount in number) return number ;
         function negative_amountformula(TYPE in number, amount in number) return number ;
         function BeforeReport return boolean ;
         function total_balanceformula(total_balance in number, TYPE in number, negative_amount in number, postive_amount in number, amount in number) return number ;
         Function balance_p return number;
    END Accnt101;
    3- Package Body
    CREATE OR REPLACE PACKAGE BODY Accnt101 AS
    function postive_amountformula(TYPE in number, amount in number) return number is
    begin
         if ((TYPE>26 and TYPE<35)
              or (TYPE=17))
         then
              return(amount);
         elsif (type = 70)and (amount >=0) then
              return (amount) ;
    elsif (type = 72)and (amount >=0) then
              return (amount) ;
    elsif (type = 73)and (amount >=0) then
              return (amount) ;
    elsif (type = 74)and (amount >=0) then
              return (amount) ;
         elsif (type = 60)and (amount >=0) then
              return (amount) ;
         else
              return (null) ;
         end if;
    RETURN NULL; end;
    function negative_amountformula(TYPE in number, amount in number) return number is
    begin
         if ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)
              or (TYPE=18)
              or (type=21)
              or (type=24)
              or (type= 81)
              or (type=82))
         then
              return(amount);
         elsif (type = 70)and (amount <0) then
              return (abs (amount)) ;
    elsif (type = 72)and (amount <0) then
              return (abs (amount)) ;
    elsif (type = 73)and (amount <0) then
              return (abs (amount)) ;
    elsif (type = 74)and (amount <0) then
              return (abs (amount)) ;
         elsif (type = 60)and (amount <0) then
              return (abs(amount)) ;
         else
              return (null) ;
         end if;
    RETURN NULL; end;
    function BeforeReport return boolean is
    var_pos     number(15,3) ;
    var_neg     number(15,3) ;
    beg_bal     number(15,3) ;
    Begin
    begin
    select sum (nvl(amount,0)) into beg_bal
         from EMPLOYEE_TRANSACTI
         where (TYPE=99 or type = 92 or type = 93 or type = 94)
         and to_char(from_date,'YYYY')=to_char(date0,'YYYY')
         and FK_EMPLOYEENUMBER0=emp_code;
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
         beg_bal := 0;
    end;
    begin
         select      sum(nvl(amount,0)) into var_pos
         from      EMPLOYEE_TRANSACTI
         where      
              (TYPE=17
              or type=60
              OR TYPE=70
    oR TYPE=72
    OR TYPE=73
    OR TYPE=74
              or (TYPE>26 and TYPE<35))
         and      fk_vouchervalue_da<from_date
         and      fk_vouchervalue_da>= trunc(from_date,'year')
         and      FK_EMPLOYEENUMBER0=emp_code;
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
         var_pos := 0;
    end;
    Begin     
         select sum(nvl(amount,0)) into var_neg
         from EMPLOYEE_TRANSACTI
         where ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)
              or (TYPE=18)
              or (type=21)
              or (type=24)
              or (type= 81)
              or (type=82) )
         and fk_vouchervalue_da<from_date
         and fk_vouchervalue_da>= trunc(from_date,'year')
         and FK_EMPLOYEENUMBER0=emp_code;
         balance :=nvl(beg_bal,0) + nvl(var_pos,0) - nvl(var_neg,0);
         return(true);
    EXCEPTION
         WHEN NO_DATA_FOUND THEN
         balance :=nvl(beg_bal,0) + nvl(var_pos,0) - nvl(var_neg,0);
              RETURN (TRUE);
    end;
    RETURN NULL; end;
    function total_balanceformula(total_balance in number, TYPE in number, negative_amount in number, postive_amount in number, amount in number) return number is
    begin
         if total_balance is null then
         if ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)or (TYPE=18)
              or (type=21) or (type=24)
              or (type= 81)
              or (type=82))
         then
              return(balance-negative_amount);
         elsif ((TYPE>26 and TYPE<35) or (TYPE=17))
              then
                   return(balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount >=0) then
                   return(balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount <0) then
                   return(balance-negative_amount);
         end if;
         else
         if ((TYPE>7 and TYPE<16)
              or (TYPE >34 and TYPE <43)
              or (TYPE=7)or (TYPE=18)
              or (type=21) or (type=24)
              or (type= 81)
              or (type=82))
         then
              return(total_balance-negative_amount);
         elsif ((TYPE>26 and TYPE<35) or (TYPE=17))
              then
                   return(total_balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount >=0) then
                   return(total_balance+postive_amount);
              elsif (type=70 or type=72 or type=73 or type=74
    or type=60) and (amount <0) then
                   return(total_balance-negative_amount);
         end if;
         end if ;
    RETURN NULL; end;
    Functions to refer Oracle report placeholders
    Function balance_p return number is
         Begin
         return balance;
         END;
    END Accnt101 ;

  • Help with sql - Left Join

    Hi,
    Below are the details of what I am attempting to do.
    DB version: 10.2.0.4.0
    Sample Table Definition
    create table t_cnf
    conf_id number,
    conf_value number,
    conf_cat_id number,
    actv_flg    char(1)
    create table t_int_act
    int_acc_id   number,
    frst_mrch_id number,
    create_date  date
    create table t_int_act_cast
    int_acc_id   number,
    cast_id      number
    create t_cast_alt_nmnt
    cas_alt_nmt_id number,
    cas_alt_id     number,
    cast_id        number,
    enrl_flg       char(1),
    src_id         number
    );Sample Data
    insert into t_cnf values (1, 78965098, 12, 'Y');
    insert into t_cnf values (1, 78965098, 13, 'Y');
    insert into t_int_act values (234,78965098, trunc(sysdate) - 1);
    insert into t_int_act_cast values (234, 560432);
    insert into t_cas_alt_nmnt values (1, 2, 560432, 'Y', 2); Need to fetch all cast_ids that are not in t_cast_alt_nmnt or cast_ids that are present in t_cast_alt_nmnt but have t_cast_alt_nmnt.enrl_flg = 'N' and t_cast_alt_nmnt.cast_alt_id in (2,3) and t_cast_alt_nmnt.src_id <> 2
    for t_int_act.frst_mrch_ids matching t_cnf.conf_vale
    Records fetch will insert a record into t_cast_alt_nmnt with css_alt_id 2 or 3 (determined by pe_or_pd).
    I attempted to write below sql. This works fine when cast_id does not exists in t_cast_alt_nmnt but will not return correct results when there is a record in t_cast_alt_nmnt matching above criteria.
    select
        iac.cast_id                            cast_id,
        sysdate                                upd_date,               
        case
            when c.conf_cat_id = 12 then 2
            when c.conf_cat_id = 13 then 3
        end
            pe_or_pd           
    from
        t_cnf                  c
    join    
        t_int_act          ia
    on
        ia.frst_mrch_id = c.conf_value
    join              
        t_int_act_cast iac
    on
        ia.int_acc_id = iac.int_acc_id
    left join       
        t_cast_alt_nmnt     can
    on
        can.cast_id = iac.cast_id     and
        can.enrl_flg = 'N'            and
        can.cas_alt_id in (2,3)       and
        can.src_id <> 2      
    where                 
        c.conf_cat_id              in (12,13)                           and
        c.actv_flg                 = 'Y'                                and
        -- Fetch all new customer created day before.   
        ia.create_date             >= trunc(sysdate) - 1                   
        Expected results
    With no cast_id record in t_cast_alt_nmnt
    cast_id upd_date pe_or_pd
    560432 4/19/2012 2
    560432 4/19/2012 3
    With cast_id record in t_css_alt_nmt (insert provided)
    cast_id upd_date pe_or_pd
    560432 4/19/2012 3
    Appreciate your help
    Edited by: user572194 on Apr 19, 2012 1:04 PM

    Thanks Frank for taking time to look into this and providing sql. I will test is against use cases (mentioned below).
    And I apologize for the typos. I had to change table and column names as it is policy of our company not to post data model details in public forums.
    Requirement:
    1. New cast ids will be added daily and these will get inserted into t_int_act and t_int_act_cas
    2. t_cnf has 2 conf_cat_id configured 12 and 13 and each conf_cat_id will have same conf_values (same as t_int_act.frst_mrch_id) but actv_flg might be different (set to N for 12 and Y for 13). Need to fetch only active ones
    3. t_cas_alt_nmnt will have cast_ids that are enrolled to receive certain mails if enrl_flg is Y for these. Not all cast_ids will have record in this table.
    When a cast_id is enrolled by customer service, a record will get inserted with src_id = 2.
    4. Requirement is to enroll new cast_ids created with frst_mrch_id matching t_cnf.conf_value where conf_cat_id in (12,13)
    Match criteira:
    If t_int_act_cas.cast_id exists in t_cas_alt_nmnt and have enrl_flg = 'Y' for cas_alt_id = 2 then
    insert record with same cast_id, enrl_flg = 'Y' and css_alt_id = 3
    If t_int_act_cas.cast_id exists in t_cas_alt_nmnt and have enrl_flg = 'Y' for cas_alt_id = 3 then
    insert record with same cast_id, enrl_flg = 'Y' and css_alt_id = 2
    If t_int_act_cas.cast_id exists in t_cas_alt_nmnt and have enrl_flg = 'N' for cas_alt_id in (2,3) and src_id = 2 then
    Ignore this record.
    if t_int_act_cas.cast_id not exists in t_cas_alt_nmnt then
    insert 1 record each with cast_id, enrl_flg = 'Y' for css_alt_id 2 and 3
    Hope above explanation makes sense.
    By the way I tried below sql. Yet to test it for all use cases but it worked for the last two.
    Note on PE_OR_PD column. I am just using this column to write separate inserts for css_alt_id 2 and 3.
    select
         cast_id,
         upd_date,
         pe_or_pd
    from    
         (select
                    iac.cast_id                        cast_id,
                    sysdate                            upd_date,
                    case
                        when c.conf_cat_id = 12 and can.cas_alt_id in (2,3) and enrl_flg = 'Y' then null
                        when c.conf_cat_id = 13 and can.cas_alt_id in (2,3) and enrl_flg = 'Y' then null
                        when c.conf_cat_id = 12 and nvl(can.cas_alt_id,2) = 2 and nvl(can.enrl_flg,'Y') = 'N' and can.src_id <> 2 then 'PE'
                        when c.conf_cat_id = 13 and nvl(can.cas_alt_id,3) = 3 and nvl(can.enrl_flg,'Y') = 'N' and can.src_id <> 2 then 'PD'       
                        when c.conf_cat_id = 12 and nvl(can.cas_alt_id,2) = 2 and nvl(can.enrl_flg,'Y') = 'Y' then 'PE'                                                                     
                        when c.conf_cat_id = 13 and nvl(can.cas_alt_id,3) = 3 and nvl(can.enrl_flg,'Y') = 'Y' then 'PD'                                                          
                    end
                        pe_or_pd              
                from
                    t_cnf              c,   
                    t_int_act          ia,      
                    t_intl_act_cus     iac,
                    t_cas_alt_nmnt     can              
                where
                    c.conf_value               = ia.frst_mrch_id               and
                    ia.internal_account_id     = iac.int_act_id                and 
                    can.cast_id(+)             = iac.cast_id                   and                               
                    c.conf_cat_id              in (12,13)                      and
                    c.actv_flg                 = 'Y'                           and
                    -- Fetch all new customer created after last run.   
                    ia.create_date             >= trunc(sysdate) - 1                                                                     
         ) enrl_cust
    where
        pe_or_pd is not null               
                    ;

  • Help with outer joins in Oracle!!

    so far this is what i've come up with and the code below does not work. Can anyone please help me on how the sytanx of left joins and how to use multiple left joins in a single query in oracle?
    SELECT a.*, b.Position_CD, c.Skill_CD, d.Team_Name, d.Team_Country, d.Club, e.Structure_Name
    FROM Roster a, Roster_position b, roster_skill c, Team d, Team_Structure e
    where (a.Roster_ID = ((b.Roster_ID= c.Roster_Id(+)) b.roster_id(+)).......
    I dont' know how to add more left joins!
    Here is the query I'm trying to duplicate (which is a query from Ms Access databaase which works fine).
    SELECT a.*, b.Position_CD, c.Skill_CD, d.Team_Name, d.Team_Country, d.Club, e.Structure_Name
    from ((Roster a LEFT JOIN (Roster_Position b LEFT JOIN Roster_Skill c ON b.Roster_ID=c.Roster_ID) ON a.Roster_ID=b.Roster_ID) LEFT JOIN Team d ON a.Team_CD=d.Team_CD) LEFT JOIN Team_Structure e ON a.Team_Structure_CD=e.Team_Structure_CD
    ORDER BY a.Roster_Id;
    Any help or comments are greatly appreciated

    First,
    I am not one of the leading SQL brains here...but I'm taking a stab, nonetheless.
    Second,
    Here's my best guess - and it seems to me that it should work as there are not two outer joins between any two tables. I hope I decoded your joins correctly - quite a mess that Access syntax!
    SELECT a.*, b.position_cd, c.skill_cd, d.team_name, d.team_country, d.club, e.structure_name
    FROM ROSTER a, ROSTER_POSITION b, ROSTER_SKILL c, TEAM d, TEAM_STRUCTURE e
    WHERE a.roster_id = b.roster_id(+)
    AND b.roster_id = c.roster_id(+)
    AND a.team_cd = d.team_cd(+)
    AND a.team_structure = e.team_structure(+);Third,
    As an architect-dude, it seems to me that you have a serious
    modeling problem to need so many outer joins in such a basic
    grab of data. In any scale other than minute, the performance
    of this model will suffer dramatically. Specifically, why can't
    ROSTER have an equijoin with TEAM and with TEAM_STRUCTURE - as they
    appear to be lookup tables...
    Good Luck
    (I'm certain you'll get better SQL from the others),
    Michael O'Neill
    Publisher of the PigiWiki
    clever-idea.com

  • Help with outer join

    I have two tables:
    PS and Entity whose data are as follows
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-DEC-08','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-DEC-08','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-DEC-08','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-DEC-08','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-DEC-08','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('27-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('27-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('27-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('27-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('27-JAN-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-FEB-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('30-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('30-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('30-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('30-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('30-MAR-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-APR-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-APR-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-APR-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-APR-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-APR-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('29-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),14);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('29-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),9);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('29-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('29-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('29-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('29-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('29-MAY-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-JUN-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),14);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),9);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('28-JUL-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),14);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),9);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-AUG-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),14);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),9);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-SEP-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-OCT-09','DD-MON-RR HH.MI.SSXFF AM'),14);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-OCT-09','DD-MON-RR HH.MI.SSXFF AM'),9);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-OCT-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-OCT-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-OCT-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-OCT-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('26-OCT-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('24-NOV-09','DD-MON-RR HH.MI.SSXFF AM'),14);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('24-NOV-09','DD-MON-RR HH.MI.SSXFF AM'),9);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('24-NOV-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('24-NOV-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('24-NOV-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('24-NOV-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('24-NOV-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-DEC-09','DD-MON-RR HH.MI.SSXFF AM'),9);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-DEC-09','DD-MON-RR HH.MI.SSXFF AM'),13);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-DEC-09','DD-MON-RR HH.MI.SSXFF AM'),10);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-DEC-09','DD-MON-RR HH.MI.SSXFF AM'),6);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-DEC-09','DD-MON-RR HH.MI.SSXFF AM'),3);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-DEC-09','DD-MON-RR HH.MI.SSXFF AM'),1);
    Insert into PS (DATE_TIME,ENTITY_ID) values (to_timestamp('25-DEC-09','DD-MON-RR HH.MI.SSXFF AM'),14);
    Entity:
    Insert into ENTITY (ENTITY_ID,ENTITY_ADDRESS) values (1,'AAA');
    Insert into ENTITY (ENTITY_ID,ENTITY_ADDRESS) values (3,'CCC');
    Insert into ENTITY (ENTITY_ID,ENTITY_ADDRESS) values (6,'DDD');
    Insert into ENTITY (ENTITY_ID,ENTITY_ADDRESS) values (9,'EEE');
    Insert into ENTITY (ENTITY_ID,ENTITY_ADDRESS) values (10,'FFF');
    Insert into ENTITY (ENTITY_ID,ENTITY_ADDRESS) values (13,'GGG');
    Insert into ENTITY (ENTITY_ID,ENTITY_ADDRESS) values (14,'HHH');
    I want to display data for each entity available in entity table
    What is wrong with this query??
    Select ps.date_time,ps.entity_id,et.entity_id from entity et left outer join PS ps on (et.entity_id = ps.entity_id)
    This query gives me result like
    26-DEC-08     1     1
    26-DEC-08     3     3
    26-DEC-08     6     6
    26-DEC-08     10     10
    26-DEC-08     13     13
    27-JAN-09     13     13
    27-JAN-09     10     10
    27-JAN-09     6     6
    27-JAN-09     3     3
    27-JAN-09     1     1...
    But for 26-Dec-08, i want to display
    26-DEC-08     1     1
    26-DEC-08     3     3
    26-DEC-08     6     6
    26-DEC-08     10     10
    26-DEC-08     13     13
    26-DEC-08 NULL 9
    26-DEC-09 NULL 14
    27-JAN-09     13     13
    27-JAN-09     10     10
    27-JAN-09     6     6
    27-JAN-09     3     3
    27-JAN-09     1     1
    But the unmatching ids are not displaying when i am using the outer join..please help me..

    Almost there.
    In this case you need a partitioned outer join, partitioning by date_time:
    SQL> Select ps.date_time
      2       , ps.entity_id
      3       , et.entity_id
      4    from ps partition by (ps.date_time)
      5         right outer join entity et on (et.entity_id = ps.entity_id)
      6  /
    DATE_TIME                                 ENTITY_ID  ENTITY_ID
    26-12-08 00:00:00,000000                          1          1
    26-12-08 00:00:00,000000                          3          3
    26-12-08 00:00:00,000000                          6          6
    26-12-08 00:00:00,000000                                     9
    26-12-08 00:00:00,000000                         10         10
    26-12-08 00:00:00,000000                         13         13
    26-12-08 00:00:00,000000                                    14
    27-01-09 00:00:00,000000                          1          1
    27-01-09 00:00:00,000000                          3          3
    27-01-09 00:00:00,000000                          6          6
    27-01-09 00:00:00,000000                                     9
    27-01-09 00:00:00,000000                         10         10
    27-01-09 00:00:00,000000                         13         13
    27-01-09 00:00:00,000000                                    14
    26-02-09 00:00:00,000000                          1          1
    26-02-09 00:00:00,000000                          3          3
    26-02-09 00:00:00,000000                          6          6
    26-02-09 00:00:00,000000                                     9
    26-02-09 00:00:00,000000                         10         10
    26-02-09 00:00:00,000000                         13         13
    26-02-09 00:00:00,000000                                    14
    30-03-09 00:00:00,000000                          1          1
    30-03-09 00:00:00,000000                          3          3
    30-03-09 00:00:00,000000                          6          6
    30-03-09 00:00:00,000000                                     9
    30-03-09 00:00:00,000000                         10         10
    30-03-09 00:00:00,000000                         13         13
    30-03-09 00:00:00,000000                                    14
    28-04-09 00:00:00,000000                          1          1
    28-04-09 00:00:00,000000                          3          3
    28-04-09 00:00:00,000000                          6          6
    28-04-09 00:00:00,000000                                     9
    28-04-09 00:00:00,000000                         10         10
    28-04-09 00:00:00,000000                         13         13
    28-04-09 00:00:00,000000                                    14
    29-05-09 00:00:00,000000                          1          1
    29-05-09 00:00:00,000000                          3          3
    29-05-09 00:00:00,000000                          6          6
    29-05-09 00:00:00,000000                          9          9
    29-05-09 00:00:00,000000                         10         10
    29-05-09 00:00:00,000000                         13         13
    29-05-09 00:00:00,000000                         14         14
    26-06-09 00:00:00,000000                          1          1
    26-06-09 00:00:00,000000                          3          3
    26-06-09 00:00:00,000000                          6          6
    26-06-09 00:00:00,000000                                     9
    26-06-09 00:00:00,000000                         10         10
    26-06-09 00:00:00,000000                         13         13
    26-06-09 00:00:00,000000                                    14
    28-07-09 00:00:00,000000                          1          1
    28-07-09 00:00:00,000000                          3          3
    28-07-09 00:00:00,000000                          6          6
    28-07-09 00:00:00,000000                          9          9
    28-07-09 00:00:00,000000                         10         10
    28-07-09 00:00:00,000000                         13         13
    28-07-09 00:00:00,000000                         14         14
    26-08-09 00:00:00,000000                          1          1
    26-08-09 00:00:00,000000                          3          3
    26-08-09 00:00:00,000000                          6          6
    26-08-09 00:00:00,000000                          9          9
    26-08-09 00:00:00,000000                         10         10
    26-08-09 00:00:00,000000                         13         13
    26-08-09 00:00:00,000000                         14         14
    25-09-09 00:00:00,000000                          1          1
    25-09-09 00:00:00,000000                          3          3
    25-09-09 00:00:00,000000                          6          6
    25-09-09 00:00:00,000000                          9          9
    25-09-09 00:00:00,000000                         10         10
    25-09-09 00:00:00,000000                         13         13
    25-09-09 00:00:00,000000                         14         14
    26-10-09 00:00:00,000000                          1          1
    26-10-09 00:00:00,000000                          3          3
    26-10-09 00:00:00,000000                          6          6
    26-10-09 00:00:00,000000                          9          9
    26-10-09 00:00:00,000000                         10         10
    26-10-09 00:00:00,000000                         13         13
    26-10-09 00:00:00,000000                         14         14
    24-11-09 00:00:00,000000                          1          1
    24-11-09 00:00:00,000000                          3          3
    24-11-09 00:00:00,000000                          6          6
    24-11-09 00:00:00,000000                          9          9
    24-11-09 00:00:00,000000                         10         10
    24-11-09 00:00:00,000000                         13         13
    24-11-09 00:00:00,000000                         14         14
    25-12-09 00:00:00,000000                          1          1
    25-12-09 00:00:00,000000                          3          3
    25-12-09 00:00:00,000000                          6          6
    25-12-09 00:00:00,000000                          9          9
    25-12-09 00:00:00,000000                         10         10
    25-12-09 00:00:00,000000                         13         13
    25-12-09 00:00:00,000000                         14         14
    91 rijen zijn geselecteerd.Partitioned outer join became available somewhere during version 10. They are described here: http://download.oracle.com/docs/cd/B28359_01/server.111/b28314/tdpdw_sql.htm#TDPDW00736
    Regards,
    Rob.

  • Help with SQL & Form

    Want to create a recordset using this SQL statement but I get a msg that says Enter a Select statement. Seems it only recognizes Select as first part of the statement. This query runs fine in SQL. Anyway around this. Any help is greatly appreciated.
    IF EXISTS (SELECT DISTINCT  t_aven_dc_site.__NAME,  t_aven_dc_site._CONS_ID,
    CASE WHEN t_aven_dc_site_1._COMPANY_NAME IS NULL OR
    t_aven_dc_site_1._COMPANY_NAME = ' '
    THEN 'NA'
    ELSE t_aven_dc_site_1._COMPANY_NAME END
    AS Consultant
    FROM t_aven_dc_contact
    INNER JOIN t_aven_dc_site AS t_aven_dc_site_1 ON t_aven_dc_contact._INTERNID = t_aven_dc_site_1._INTERNID INNER JOIN
    t_aven_dc_site ON t_aven_dc_site_1._SPS_ID = t_aven_dc_site._CONS_ID
    WHERE
      t_aven_dc_site._IDB_CLNT_ID_N = 716166 )
    Select Distinct t_aven_dc_site_1._COMPANY_NAME AS Consultant FROM t_aven_dc_contact
    INNER JOIN t_aven_dc_site AS t_aven_dc_site_1 ON t_aven_dc_contact._INTERNID = t_aven_dc_site_1._INTERNID INNER JOIN
    t_aven_dc_site ON t_aven_dc_site_1._SPS_ID = t_aven_dc_site._CONS_ID
    WHERE
      t_aven_dc_site._IDB_CLNT_ID_N = 716166
    ELSE
    Select 'NA' As Consultant

    Acrobat in versions prior to 9 has the ADBC, Adobe Data Base Connection, object which through a series of function or method calls could interact with an SQL data base by passing the SQL statements as a parameter.
    The ability to connect to an SQL data base is now limited to LiveCycle Designer forms.

Maybe you are looking for

  • Should I use Core Data?

    I'm starting a new document-based application. Is Core Data the way of the future, or just a convenience for specific types of apps? That is, in the "old days" you would override -[NSDocument dataOfType:] and readFromData: to archive your objects. It

  • How to synchrorise two workflow tasks/calls?

    Hi all, We are writing a Workflow client application (in Java) and having problem getting valid state of the workflow because of the delay in PL/SQL API. Here's are two example: 1) First we respond to a notification (using WF_Notification.Respond). A

  • Graphical view of share point survey issue

    Hi All, I have created a survey in my sharepoint site with a column as Choice (Check boxes (allow multiple selections)). When I go to graphical view it is showing extra column if users selected more than one option. How can I avoid that and show the

  • Newbee's question: Error connecting to the management server for the first time

    Dear all, I am very new to the oralce world and got stuck today the first time I install oracle 8i on my win2k pro. After the installation, I was trying to connect the Enterprise Manager Console for the first time, using the default user name sysman

  • "-useLegacyAOT no" parameter disables ActionScript Sampler

    I'm trying to profile my app with Scout on iOS but having trouble getting the ActionScript Sampler enabled. If I use the legacy AOT to compile, the sampler is enabled, but if I want to compile faster, the sampler is disabled even if I have it set in