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.

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.

  • 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

  • Where can I get some help with my Nokia Maps Licen...

    My problem is I bought a license and a Nokia n97.
    I originally bought the license on my n95 and was able to transfer my license to my new n97. But since I have upgraded to version 3.0 my license has dissapeared.
    I tried doing the sim card transfer method and that works up to the point where it tries to associate it with my new sim card (I changed provides when I upgraded). When it gets to this point it simply states "No updates" and then keeps trying again and again. I have rolled it back to version 2 and now have the same problem. 
    Unfortunately I have lost the email I got when I registered and I can't find any information on how to get this email resent.
    I have tried speaking with Nokia care here in Sydney, Australia and they said it is a known problem but there is no fix for it.
    I would like to try entering my license code again manually to see if thats possible. But I am told and I can see that nokia doesn't allow its customers to get this information again.
    Please do something about this Nokia. It's really a **bleep** situation.
    Solved!
    Go to Solution.

    zgeek wrote:
    My problem is I bought a license and a Nokia n97.
    I originally bought the license on my n95 and was able to transfer my license to my new n97. But since I have upgraded to version 3.0 my license has dissapeared.
    I tried doing the sim card transfer method and that works up to the point where it tries to associate it with my new sim card (I changed provides when I upgraded). When it gets to this point it simply states "No updates" and then keeps trying again and again. I have rolled it back to version 2 and now have the same problem. 
    Unfortunately I have lost the email I got when I registered and I can't find any information on how to get this email resent.
    I have tried speaking with Nokia care here in Sydney, Australia and they said it is a known problem but there is no fix for it.
    I would like to try entering my license code again manually to see if thats possible. But I am told and I can see that nokia doesn't allow its customers to get this information again.
    Please do something about this Nokia. It's really a **bleep** situation.
    Hi zgeek,
    I had a similar issue when moving from my N95-1 (maps 3.0 installed and licence upgraded) to my N86-1 (maps 3.0 pre-loaded). Everything was fine with the old SIM but couldn't transfer the licence across to the new handset and SIM.
    Nokia ended up giving me new licences as the old ones didn't want to work anymore.
    Have you searched your e-mail for the word "openbit"? Not sure if they just do Europe or the worldwide licencing sales.
    One of the Nokia staff that contributes to the support forums was able to assist me (see this thread), as long as you have your N95 IMEI and SIM and your N97 IMEI and SIM then they should be able to sort it - It took me 3 weeks to resolve  and cbidlake was excellent and prodding the right people.
    Hope that this helps., 
    Alun.
    N8-00 (Product Code: 059C5Q8 (UK Generic)) FW Belle (111.030.0609.377.01)
    Orange 5.1, NK702, 7110, 8310, 7250, 6230, N70, N95-1, N86 8MP, N8-00

  • Where should one ask for help with a thread   ???

    Having posted a link to this thread because the op needed someone to check a site in Panther.... and because not so long ago I read here that this was the place to ask for such help.....
    I now find the my request has been removed... musta offended the tou of course.
    Sooo - how should a person try to get help with a thread in future? - we ain't all l4's and have a lounge to play in.

    Interesting question. This forum was available for this type of request at certain points in Discussions' history, and it has often been recommended that users post issues like yours here.
    Technically, as per the red print at the top of this forum, it is inappropriate to use this forum for that purpose. In the case you cite, I'd recommend putting a new topic in to the Safari forum with a specific request for the help that is required in the Subject line. If you do it that way, you will most likely reach more users who will be able to help you.
    Good luck.

  • Help with SQL Query - MIN MAX - CTE?

    First and foremost, the SQL is handled dynamically - please ignore some of the crazy coding you see in the WHERE clauses ... its not an issue with the report, trust me.
    What my client needs is a summary by Facility, by Resource for each specific day - broken out in 3 distinct time blocks for that specific Resource at each distinct facility. For each Resource by Facility I need 3 rows - a row for their earliest AM appointment
    to their latest AM appointment (AMStart and AMStop below) - a row for their earliest PM appointment to their latest PM appointment (PMStart and PMStop below) and finally a row for their EVE appointments (EVEStart and EVEStop below).
    I thought doing a MIN and MAX on them would fix this and grouping it but I am missing something because my times for my AM are way off. For my test provider, I have set up a schedule that starts at 7:15 AM and spans to 11:45 AM. I created a break and had
    him re-start at 1:00 PM and go to 2:45 PM. No Evening clinic was made on this example.
    What I would hope to get back is 3 rows - an AM row with the earliest AMStart and latest AMStop time (with the PM and EVE pull NULL), a PM row(earliest and latest) (with the AM and EVE pull NULL) and finally my EVE with same concept.
    My current data set (1 row) - should have as 3 rows and my AM Start and Stop are wrong.
    Scheduledate = 01/21/2014      
    AMStart  = 10:00AM
    AMStop =  9:45AM      
    PMStart =       1:00PM
    PMStop =       2:45PM
    EveStart =       NULL
    EveStop =       NULL
    TotalTime = 375      
    Resource = Bailey MD, William R
    Facility = River Oaks
    /*Appointment Times report*/
    SET NOCOUNT ON
    DECLARE @Today DATETIME
    DECLARE @Tomorrow DATETIME
    SET @Today = '01/21/2014'
    SET @Tomorrow = DATEADD(d , 1 , '01/21/2014')
    DECLARE @tblTemp TABLE
    ApptSlotId INT ,
    Resource VARCHAR(60) ,
    ResourceId INT ,
    Start DATETIME ,
    Stop DATETIME ,
    AMStart DATETIME ,
    AMStop DATETIME ,
    PMStart DATETIME ,
    PMStop DATETIME ,
    EveStart DATETIME ,
    EveStop DATETIME ,
    Patient VARCHAR(256) ,
    [Column] VARCHAR(64) ,
    Facility VARCHAR(60) ,
    FacilityId INT ,
    Allocations VARCHAR(4096) ,
    Scheduledate VARCHAR(15)
    INSERT INTO @tblTemp
    SELECT
    ApptSlotid ,
    d.Listname ,
    d.DoctorFacilityId ,
    Start ,
    Stop ,
    NULL ,
    NULL ,
    NULL ,
    NULL ,
    NULL ,
    NULL ,
    ' ' AS Patient ,
    CAST(aps.ListOrder AS VARCHAR(10)) AS [Column] ,
    f.ListName AS Facility ,
    aps.FacilityId ,
    dbo.sfnGetAllocsForSlot(aps.ApptSlotId) AS Allocations ,
    CONVERT(VARCHAR(15) , Start , 101)
    FROM
    ApptSlot aps
    JOIN Schedule s ON aps.ScheduleId = s.ScheduleId
    JOIN DoctorFacility df ON s.DoctorResourceId = df.DoctorFacilityId
    JOIN DoctorFacility f ON aps.FacilityId = f.DoctorFacilityId
    JOIN DoctorFacility d ON s.DoctorResourceId = d.DoctorFacilityId
    WHERE
    --Filter on resource
    NULL IS NOT NULL
    AND s.Doctorresourceid IN ( NULL )
    OR ( NULL IS NULL )
    AND (
    NULL IS NOT NULL
    AND aps.FacilityId IN ( NULL )
    OR ( NULL IS NULL )
    AND (
    Start >= @Today
    OR @Today IS NULL
    AND (
    Start < @Tomorrow
    OR @Tomorrow IS NULL
    AND ApptId IS NULL
    AND APS.ListOrder <> -1
    INSERT INTO @tblTemp
    SELECT DISTINCT
    ApptSlotid ,
    d.ListName ,
    d.DoctorFacilityId ,
    ApptStart ,
    ApptStop , -- need distinct because =ApptSlot can have more than row per appt
    NULL ,
    NULL ,
    NULL ,
    NULL ,
    NULL ,
    NULL ,
    CASE WHEN a.ApptKind = 1 THEN pp.Last + ', ' + pp.First
    WHEN a.ApptKind = 2 THEN 'Doctor Appt'
    WHEN a.ApptKind = 3 THEN 'Resource Appt'
    WHEN a.ApptKind = 5 THEN 'Block Out Appt'
    ELSE ''
    END AS Patient ,
    CASE WHEN aps.ListOrder IS NULL THEN 'Overbooked'
    ELSE CAST(aps.ListOrder AS VARCHAR(10))
    END AS [Column] ,
    f.ListName AS Facility ,
    a.FacilityId ,
    ISNULL(apt.Name , '<No Appointment Type>') AS Allocations ,
    CONVERT(VARCHAR(15) , ApptStart , 101) AS Scheduledate
    FROM
    Appointments a
    JOIN DoctorFacility f ON a.FacilityId = f.DoctorFacilityId
    LEFT JOIN PatientProfile pp ON a.OwnerId = pp.PatientProfileId
    LEFT JOIN ApptSlot aps ON a.AppointmentsId = aps.ApptId
    JOIN DoctorFacility d ON a.ResourceId = d.DoctorFacilityId
    LEFT JOIN ApptType apt ON a.ApptTypeId = apt.ApptTypeId
    WHERE
    NULL IS NOT NULL
    AND a.ResourceId IN ( NULL )
    OR ( NULL IS NULL )
    AND (
    NULL IS NOT NULL
    AND a.FacilityId IN ( NULL )
    OR ( NULL IS NULL )
    AND (
    ApptStart >= @Today
    OR @Today IS NULL
    AND (
    ApptStop < @Tomorrow
    OR @Tomorrow IS NULL
    AND (
    (ApptKind = 1
    AND ISNULL(Canceled , 0) = 0)
    UPDATE
    @tblTemp
    SET
    AMStart = Start ,
    AMStop = Stop
    FROM
    @tblTemp base
    WHERE
    CONVERT(TIME , start) < CONVERT(TIME , '12:00')
    UPDATE
    @tblTemp
    SET
    PMStart = Start ,
    PMStop = Stop
    FROM
    @tblTemp base
    WHERE
    CONVERT(TIME , start) > CONVERT(TIME , '12:00')
    AND CONVERT(TIME , start) < CONVERT(TIME , '17:00')
    UPDATE
    @tblTemp
    SET
    EveStart = Start ,
    EveStop = Stop
    FROM
    @tblTemp base
    WHERE
    CONVERT(TIME , start) > CONVERT(TIME , '17:00')
    --SELECT * FROM @tblTemp ORDER BY Start
    SELECT
    Scheduledate ,
    Start ,
    Stop ,
    [Column] ,
    Resource ,
    Facility ,
    CONVERT(VARCHAR(60) , CAST(CONVERT(VARCHAR(60) , h.AMStart , 108) AS TIME) , 100) AS AMStart ,
    CONVERT(VARCHAR(60) , CAST(CONVERT(VARCHAR(60) , h.AMStop , 108) AS TIME) , 100) AS AMStop ,
    CONVERT(VARCHAR(60) , CAST(CONVERT(VARCHAR(60) , h.PMStart , 108) AS TIME) , 100) AS PMStart ,
    CONVERT(VARCHAR(60) , CAST(CONVERT(VARCHAR(60) , h.PMStop , 108) AS TIME) , 100) AS PMStop ,
    CONVERT(VARCHAR(60) , CAST(CONVERT(VARCHAR(60) , h.EveStart , 108) AS TIME) , 100) AS EveStart ,
    CONVERT(VARCHAR(60) , CAST(CONVERT(VARCHAR(60) , h.EveStop , 108) AS TIME) , 100) AS EveStop ,
    ISNULL(DATEDIFF(MI , h.AMStart , h.AMStop) , 0) + ISNULL(DATEDIFF(MI , h.PMStart , h.PMStop) , 0) + ISNULL(DATEDIFF(MI , h.EveStart , h.EveStop) , 0) AS TotTime
    INTO
    #tmp
    FROM
    @TblTemp h
    WHERE
    [Column] = 1
    ORDER BY
    START
    --SELECT * FROM #tmp
    SELECT
    Scheduledate ,
    MIN(AMStart) AS AMStart ,
    MAX(AMStop) AS AMStop ,
    MIN(PMStart) AS PMStart ,
    MAX(PMStop) AS PMStop ,
    MIN(EveStart) AS EveStart ,
    MAX(EveStop) AS EveStop ,
    SUM(TotTime) AS TotalTime ,
    Resource ,
    Facility
    FROM
    #tmp
    GROUP BY
    Resource ,
    Facility ,
    Scheduledate
    DROP TABLE #tmp
    SET NOCOUNT OFF

    Since there is some context missing, I don't get everything, but from your narrative, it seems likely you need something like:
    WITH CTE AS (
       SELECT keycol,
              period = CASE WHEN Start < '12:00' THEN 'AM'
                            WHEN Start < '17:00' THEN 'PM'
                            ELSE 'EVE'
                       END,
              start, stop
       FROM   tbl
    SELECT keycol, period, MIN(start), MAX(stop)
    FROM   CTE
    GROUP  BY keycol, period
    Erland Sommarskog, SQL Server MVP, [email protected]

  • 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 Code - Production Order with Manual Issue Method

    Hi,
    I need some assistance here.
    I need to retrieve Production Order which has component's issue method = 'M'.
    Eg:
    Production Order #50001 has 4 components.
    Component A, issue method = 'M'
    Component B, issue method = 'B'
    Component C, issue method = 'B'
    Component D, issue method = 'M'
    Production Order #50002 has 2 components.
    Component B, issue method = 'B'
    Component C, issue method = 'B'
    When I run the query, I want to display the Production #50001 componenets simply because in this Production Order, it contains components with issued method 'M'.   However, Production #50002 will not be displayed because no components are with issued method = M.
    Appreicate any help in advance.

    No, this is not what I need.
    To put in IssueMethod in the where clause will only gives me the component line with Manual.
    Please refer to the example.
    I have a production order which, its components have combination of issue method = 'Manual' as well as Backflush.
    I need to display all of them within the Production Order if the production order contain any line which has issue method = Manual.

  • Need help with SQL or PL/SQL

    Hello
    I have been educating myself in the world of Apex and SQL programming by utilizing the provided "How to Build an Issue Database" from the "2 Day AE Developers Guide. PDF.” I have also been watching this forum and have learned a great deal!
    My question is concerning a provided SQL program from the PDF stated above; the following is a copy of that program:
    DECLARE
    q VARCHAR2(32767); -- query
    w VARCHAR2(4000) ; -- where clause
    we VARCHAR2(1) := 'N'; -- identifies if where clause exists
    BEGIN
    q := 'SELECT "RECORD_NO", '||
    ' "ISSUE_ID", '||
    ' "ISSUE_SUMMARY", '||
    ' "RELATED_PROJECT", '||
    ' "ASSIGNED_TO", '||
    ' "STATUS", '||
    ' "PRIORITY", '||
    ' "PROGRESS", '||
    ' "TARGET_RESOLUTION_DATE", '||
    ' "LAST_MODIFIED_DATE" '||
    ' FROM "#OWNER#"."ISSUE_HISTORY" ';
    IF :P15_RELATED_PROJECT != '-1'
    THEN
    IF we = 'Y'
    THEN
    w := w || ' AND RELATED_PROJECT = :P15_RELATED_PROJECT ';
    ELSE
    w := ' RELATED_PROJECT = :P15_RELATED_PROJECT ';
    we := 'Y';
    END IF;
    END IF;
    IF :P15_ASSIGNED_TO != '-1'
    THEN
    IF we = 'Y'
    THEN
    w := w || ' AND ASSIGNED_TO = :P15_ASSIGNED_TO ';
    ELSE
    w := ' ASSIGNED_TO = :P15_ASSIGNED_TO ';
    we := 'Y';
    END IF;
    END IF;
    IF :P15_STATUS != '-1'
    THEN
    IF we = 'Y'
    THEN
    w := w || ' AND STATUS = :P15_STATUS ';
    ELSE
    w := ' STATUS = :P15_STATUS ';
    we := 'Y';
    END IF;
    END IF;
    IF :P15_PRIORITY != '-1'
    THEN
    IF we = 'Y'
    THEN
    w := w || ' AND PRIORITY = :P15_PRIORITY ';
    ELSE
    w := ' PRIORITY = :P15_PRIORITY ';
    we := 'Y';
    END IF;
    END IF;
    IF we = 'Y'
    THEN q := q || ' WHERE '|| w;
    END IF;
    RETURN q;
    END;
    I would like the query modified to include a DATE search range based on the LAST_MODIFIED_DATE. In other words when a user selects a beginning and ending date I would like to see only those issues based on their last modified date show up in the results.
    I have already created two Items called
    P15_BEG_DATE
    P15_END_DATE
    How do I include these in the SQL query above to accomplish my goal?
    As always, any help provided would be greatly appreciated.
    Thank you

    How about this?
    DECLARE
      q VARCHAR2(32767); -- query
      w VARCHAR2(4000) ; -- where clause
      we VARCHAR2(1) := 'N'; -- identifies if where clause exists
    BEGIN
      q := 'SELECT "RECORD_NO", '||
      ' "ISSUE_ID", '||
      ' "ISSUE_SUMMARY", '||
      ' "RELATED_PROJECT", '||
      ' "ASSIGNED_TO", '||
      ' "STATUS", '||
      ' "PRIORITY", '||
      ' "PROGRESS", '||
      ' "TARGET_RESOLUTION_DATE", '||
      ' "LAST_MODIFIED_DATE" '||
      ' FROM "#OWNER#"."ISSUE_HISTORY" ' ||
      ' WHERE 1 = 1 ' ||
      '   AND ( "LAST_MODIFIED_DATE" BETWEEN TO_DATE( :P15_BEG_DATE, ''DD-MON-YY'' ) AND TO_DATE( :P15_END_DATE, ''DD-MON-YY'' OR :P15_BEG_DATE IS NULL )';
      IF :P15_RELATED_PROJECT != '-1' THEN
        w := w || ' AND RELATED_PROJECT = :P15_RELATED_PROJECT ';
      END IF;
      IF :P15_ASSIGNED_TO != '-1' THEN
        w := w || ' AND ASSIGNED_TO = :P15_ASSIGNED_TO ';
      END IF;
      IF :P15_STATUS != '-1' THEN
        w := w || ' AND STATUS = :P15_STATUS ';
      END IF;
      IF :P15_PRIORITY != '-1' THEN
        w := w || ' AND PRIORITY = :P15_PRIORITY ';
      END IF;
      q := q || w;
      RETURN q;
    END;I added the WHERE 1 = 1 portion to your original query string; this should help you to remove the additional 5 IF-END IF blocks that check to see if WHERE is included. My disclaimer: I have yet to use Dynamic SQL in APEX so I wasn't 100% sure on how to use the bind variables.
    Hope this helps.
    chet

  • Need help with SQL Query

    I am trying to build a query that sums up 12 columns depending on some accounting variables.
    example:
    SELECT gbmcu, gbco, gbfy,'',SUM(gban01 gban02 gban03 gban04 gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12) AS Oil_Volumes
    FROM PRODDTA.F0902
    WHERE GBCO = '00099'
    AND GBFY = 5
    AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
    GROUP BY gbmcu, gbco, gbfy
    The condition that changes is :AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
    I need to do this for 17 different conditions - I need to make the query as optimized as possible.
    I tried using a case statement but that takes forever (the table is over 4 million records to scan through).
    Please let me know if anyone has any suggestions on how to create something to perform these calculations.
    thanks,
    Pam

    I think I would tend to write that query as:
    SELECT gbmcu, gbco, gbfy,
           SUM(CASE WHEN gblt = 'QA' AND gbobj = 5015 AND gbsub = '105' THEN
                    gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Sales
           SUM(CASE WHEN gblt = 'QU' AND gbobj = 5015 AND gbsub = '105' THEN
                    gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Volumes
    FROM proddta.f0902
    WHERE gbco = '00099' and
          gbfy = 5 and
          gblt IN ('QA', 'QU') and
          gbpbj = 5015 and
          gbsub = '105'
    GROUP BY gbmcu, gbco, gbfySUM the CASE rather than CASE SUM. Also, as written, your query will look at all of the records in f0902 whether or not they meet one of the Case criteria, so I would put the required values in the WHERE clause as well. Your samples only show gblt changing, so you may need to make the gbpbj and gbsub predicates IN lists as well.
    If the query runs in 1.5 hours calculating one value, I would expect it to be about the same calculating 17 values, since I would bet that most of the run time is accessing the table rather than doing the math. It would almost certainly be faster than running essentially the same query 17 times.
    Indexes on some or all of the columns in the WHERE clause may help, depending on how selective the columns are. At a guess, I would suggest that gbco and gbfy would be good candidates.
    Finally, are you sure that gbsub is a character field? The only example we have is a number.
    HTH
    John

  • Need help with sql query dates

    Hi,
    I have a sql query where i need to extract some info between given dates. The where clause of this query is as follows:
    WHERE CPD_BUS_UNIT=:ESI_PRM_1
    AND CPD_VOUCHER_DATE >= :P_DATE_FROM
    AND CPD_VOUCHER_DATE < (:P_DATE_TO+1)
    When i execute the query in toad, i can view the data but not the execution plan.It gives an error ORA-00932-Inconsistent Datatypes.
    But when i remove (+1) from :P_DATE_TO, i can c the execution plan and data. Will the data be different from the previous one.
    Please suggest how to rewrite the query.

    Can you please give it a try?
    WHERE CPD_BUS_UNIT=:ESI_PRM_1
    AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM)
    AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1) Regards

  • Help with sql statements and Java

    Hi,
    How can I create a string kind of like this
    Select * From Students Where Name Like "Bob Burns";
    As the sql statement might indicate I am using MS Access. I seem to be having problems with the double quotes required by the Like operator in MS Access, Java views that as a beginning of a string as oppposed to an actual string value.

    Like this:
        Connection connection = null;
        PreparedStatement stmt = null;
        ResultSet res = null;
        try  {
            connection = ...get from connection pool...;
            String sql = "select ... from ... where name like ?";
            stmt = connection.prepareStatement(sql);
            stmt.setObject(1, "%Bob%", java.sql.Types.VARCHAR);
            res = stmt.executeQuery();
            while (res.next()) { ...the usual...; }
        } finally {
            ...close res, stmt & return connection to pool...
        }You can try stmt.setString() instead of setObject() but rumor has it that some mssql drivers have a bug that makes setString() not work with "like", but oddly enough setObject() works.

  • 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
    )

  • TIMESTAMPS need help with sql please!!!!

    I am trying to get back a map from a database that is no problem but, all maps have a time stamps so to I try to retrive the map with a where statment to the time stamp the sql is bellow
    query = "SELECT MAP.MAP FROM MAP WHERE MAP.MAP_DATE = '"+ timestamp_str +"';";
    timestamp_str is a string with the value "2003-02-25 22:21:43.356"

    I for got to put in the problem sorry the problem is I get the error
    com.borland.datastore.q2.QueryError: [line 1, col 44] Operator = doesn't apply to the types <TIMESTAMP> and <STRING>
    I think the problem is that I am comparing it to a string so does any one know how to convert these string values to a time stamp????

  • 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 ;

Maybe you are looking for

  • Address Book - Birthdates

    I am fairly new with the imac and learning how to use the address book.  Previously we had an adddress book on Windows where we could list every person in the family including the children with their birthday. If I want a family contact and list the

  • Is Something Wrong here?

    Hi, I have a K8N Neo2 Platinum with a Winchester 3000+ Running at stock, with stock fan and heatsink and everything, although I am a complete newbie when it comes to temperatures and stuff. Using corecenter it tells me that my CPU fan is running at 1

  • MPEG2 frame size areas greyed out  :(

    I need to take a QuickTime file that was rendered at 864x486 and make an MPEG2 out of it to playback on a PC onto a plasma screen. However, every MPEG2 I create in Compressor changes my frame size to 720x480. The frame size controls are greyed out an

  • Transfering data between two different systems through dedicated port

    Hi! We are developing our system in java. But we need to communicate an existing Tandem COBOL System through a dedicated port to get some information. The user has already developed an interface to listen the request and send the response. What sort

  • "The application iTunes has quit unexpectedly"

    every time I try to open itunes this message pops up. i uninstalled and reinstalled several times and i still have the same problem. also, i started having this problem before updating to itunes 7.3