Need help in AUTONOMOUS_TRANSACTION(pl/sql)

Hi,
I'm havaing a procedure which is calling a autonomous transaction.
I'm unable to get the changes made by the caller procedure. The commit and rollback of the session is controled by the JSP code and not in procedure.
I have gone thro doc and came to know unless commit is made in the caller procedure autonomous transaction can't get the reflected changes.
Any other way ?
Scenario
JSP -> call C1
on sucess -> commit
else -> rollback
Caller Procedure(C1) Autonomous Procedure(A1)
Insert .... Select form insert and update
Update .... of C1 (Not known:no_data_found/
call A1 old_data)
Insert ...
END Commit
END;
Regards,
Donald.

Hi,
I'm havaing a procedure which is calling a autonomous transaction.
I'm unable to get the changes made by the caller procedure. The commit and rollback of the session is controled by the JSP code and not in procedure.
I have gone thro doc and came to know unless commit is made in the caller procedure autonomous transaction can't get the reflected changes.
Any other way ?
Scenario
JSP -> call C1
on sucess -> commit
else -> rollback
Caller Procedure(C1) Autonomous Procedure(A1)
Insert .... Select form insert and update
Update .... of C1 (Not known:no_data_found/
call A1 old_data)
Insert ...
END Commit
END;
Regards,
Donald.

Similar Messages

  • Need help in rewriting a sql query

    Can any one please tell me if there is any utility that can help me correcting the sql I have I need to tune the query as its taking lot of time. I want to use some tool that will help me re-formating the query.
    Any help in this regard will be highly appreciated.

    If you think that Oracle SQL Tuning Tools like SQL Tuning Advisor and SQL Access Advisor are not helping.
    You might look into thrid party tools like Quest- SQL Navigator and TOAD.
    But I don't advise this based on the following:
    Re: Oracle Third Party Tools and Oracle Database
    Oracle have enough tools of its own to satisfy the various needs.
    Adith

  • Need help to redesign legacy SQL Script

    Hello Experts,
    I have the below code which produces a CREATE TRIGGER statement. as of now this does for updating. I need to re-design this code to add for inserting and deleting as well. I just need help in the structuring wise. I can build the logic for inserting and updating inside. I want to know how i can continue to get for "inserting" and "deleting" as well.
    you will understand my question better if you go through main code, present output and required output format below.
    I know this is a bad design first of all. but the below code is a legacy one. so i cant change the entire structure of the code :-( all i can do is to continue designing it to add new changes. Hence sought help from you all.
    please help
    SQL CODE:
    WITH audit_tables
    AS
       (SELECT object_name,
               MIN (column_id) min_col,
               MAX (column_id) max_col
        FROM   user_objects o,
               user_tab_columns c
        WHERE  o.object_name = 'CHR_VAL_DESC_A_T'
        AND    o.object_name = c.table_name
        GROUP BY object_name
    SELECT txt
    FROM (
    SELECT ' CREATE OR REPLACE TRIGGER ' || REPLACE(object_name,'_A_T') || '_ADT_TRG' || CHR(13) ||
           '   AFTER INSERT ' || CHR(13) ||
           '   OR    UPDATE ' || CHR(13) ||
           '   OR    DELETE ' || CHR(13) ||
           '   ON ' || REPLACE(object_name,'_A_T','_T') || CHR(13) ||
           '   FOR EACH ROW ' || CHR(13) ||
           ' DECLARE ' || CHR(13) ||
           ' BEGIN ' || CHR(13) ||
           ' IF updating THEN ' || CHR(13) ||
           '   INSERT INTO ' || object_name || CHR(13) ||
           '   (' txt, object_name, 1 disp_order, 0 column_id
    FROM audit_tables
    UNION ALL
    SELECT txt, object_name, disp_order, column_id
    FROM (SELECT 
            CASE
              WHEN max_col = column_id THEN
                '    '||column_name
              ELSE
                '    '||column_name || ','
              END AS txt, object_name, 2 disp_order, column_id
          FROM  audit_tables t,
                user_tab_columns C
          WHERE c.table_name = t.object_name
          ORDER BY c.column_id ASC)
    UNION ALL
    SELECT '   )' || CHR(13) ||
           '   VALUES ' || CHR(13) ||
           '   (', object_name, 3 disp_order, 0
    FROM audit_tables t
    UNION ALL
    SELECT txt, object_name, disp_order, column_id
    FROM (SELECT
            CASE
              WHEN max_col = column_id THEN
                CASE
                  WHEN SUBSTR(column_name,1,2) = 'N_' THEN
                    '    :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
                  WHEN SUBSTR(column_name,1,2) = 'O_' THEN
                    '    :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||');'
                  WHEN min_col = column_id THEN
                    '    1'
                  WHEN column_id = 2 THEN
                    '     ''I'''
                  WHEN column_id = 3 THEN
                    '    SYSDATE'
                  ELSE
                  '    :NEW.'||column_name||');'
                END
              ELSE
                CASE
                  WHEN SUBSTR(column_name,1,2) = 'N_' THEN
                    '    :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
                  WHEN SUBSTR(column_name,1,2) = 'O_' THEN
                    '    :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||','
                  WHEN min_col = column_id THEN
                    '    1'||','
                  WHEN column_id = 2 THEN
                    '    ''I'''||','
                  WHEN column_id = 3 THEN
                    '    SYSDATE' ||','
                  ELSE
                    '    :NEW.'||column_name||','
                   END
              END AS txt,object_name, 4 disp_order, column_id
          FROM audit_tables t,
               user_tab_columns c
          WHERE c.table_name = t.object_name
          ORDER BY c.column_id ASC)
    UNION ALL
    SELECT 'END '||REPLACE(object_name,'_A_T') || '_ADT_TRG;' || CHR(13),
           object_name, 5 disp_order, 0
    FROM    audit_tables)
    ORDER BY object_name, disp_order, column_id
    PRESENT OUTPUT:
    CREATE OR REPLACE TRIGGER CHR_VAL_DESC_ADT_TRG
       AFTER INSERT
       OR    UPDATE
       OR    DELETE
       ON CHR_VAL_DESC_T
       FOR EACH ROW
    DECLARE
    BEGIN
    IF updating THEN
       INSERT INTO CHR_VAL_DESC_A_T
        TXN_ID,                                  
        TXN_TYP,                                 
        ADT_DTTM,                                
        CHR_VAL_DESC_ID,                         
        CHR_VAL_ID,                              
        LANG_ID,                                 
        DESC_ID,                                 
        O_CHR_VAL_DESC,                          
        N_CHR_VAL_DESC,                          
        O_TRANS_STATE,                           
        N_TRANS_STATE,                           
        CRTD_BY,                                 
        CRTD_DTTM,                               
        O_UPD_BY,                                
        N_UPD_BY,                                
        O_UPD_DTTM,                              
        N_UPD_DTTM,                              
        O_LOCK_NUM,                              
        N_LOCK_NUM                               
       VALUES
        1,                                       
        'I',                                     
        SYSDATE,                                 
        :NEW.CHR_VAL_DESC_ID,                    
        :NEW.CHR_VAL_ID,                         
        :NEW.LANG_ID,                            
        :NEW.DESC_ID,                            
        :OLD.CHR_VAL_DESC,                       
        :NEW.CHR_VAL_DESC,                       
        :OLD.TRANS_STATE,                        
        :NEW.TRANS_STATE,                        
        :NEW.CRTD_BY,                            
        :NEW.CRTD_DTTM,                          
        :OLD.UPD_BY,                             
        :NEW.UPD_BY,                             
        :OLD.UPD_DTTM,                           
        :NEW.UPD_DTTM,                           
        :OLD.LOCK_NUM,                           
        :NEW.LOCK_NUM);                          
    END CHR_VAL_DESC_ADT_TRG;
    REQUIRED OUTPUT FORMAT:
    CREATE OR REPLACE TRIGGER TRIGGER_NAME
       AFTER INSERT
       OR    UPDATE
       OR    DELETE
       ON TABLE_NAME
       FOR EACH ROW
    DECLARE
    BEGIN
    IF updating THEN
       INSERT TABLE_NAME
        list of column names                               
       VALUES
    IF inserting THEN
       INSERT TABLE_NAME
        list of column names                               
       VALUES
    IF deleting THEN
       INSERT TABLE_NAME
        list of column names                               
       VALUES
    END TRIGGER_NAME;

    can anyone please help?
    i tried adding with inserting and updating also..but when i tried to add deleting part the final output not comes in proper structure.
    WITH audit_tables
    AS
       (SELECT object_name,
               MIN (column_id) min_col,
               MAX (column_id) max_col
        FROM   user_objects o,
               user_tab_columns c
        WHERE  o.object_name IN ('CHR_VAL_DESC_A_T', 'CHR_VAL_A_T')
        AND    o.object_name = c.table_name
        GROUP BY object_name
    SELECT txt
    FROM (
    SELECT ' CREATE OR REPLACE TRIGGER ' || REPLACE(object_name,'_A_T') || '_ADT_TRG' || CHR(13) ||
           '   AFTER INSERT ' || CHR(13) ||
           '   OR    UPDATE ' || CHR(13) ||
           '   OR    DELETE ' || CHR(13) ||
           '   ON ' || REPLACE(object_name,'_A_T','_T') || CHR(13) ||
           '   FOR EACH ROW ' || CHR(13) ||
           ' DECLARE ' || CHR(13) ||
           ' BEGIN ' || CHR(13) ||
           *' IF inserting THEN '* || CHR(13) ||
           '   INSERT INTO ' || object_name || CHR(13) ||
           '   (' txt, object_name, 1 disp_order, 0 column_id
    FROM audit_tables
    UNION ALL
    SELECT txt, object_name, disp_order, column_id
    FROM (SELECT 
            CASE
              WHEN max_col = column_id THEN
                '    '||column_name
              ELSE
                '    '||column_name || ','
              END AS txt, object_name, 2 disp_order, column_id
          FROM  audit_tables t,
                user_tab_columns C
          WHERE c.table_name = t.object_name
          ORDER BY c.column_id ASC)
    UNION ALL
    SELECT '   )' || CHR(13) ||
           '   VALUES ' || CHR(13) ||
           '   (', object_name, 3 disp_order, 0
    FROM audit_tables t
    UNION ALL
    SELECT txt, object_name, disp_order, column_id
    FROM (SELECT
            CASE
              WHEN max_col = column_id THEN
                CASE
                  WHEN SUBSTR(column_name,1,2) = 'N_' THEN
                    '    :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
                  WHEN SUBSTR(column_name,1,2) = 'O_' THEN
                    '    NULL'||');'
                  WHEN min_col = column_id THEN
                    '    1'
                  WHEN column_id = 2 THEN
                    '     ''I'''
                  WHEN column_id = 3 THEN
                    '    SYSDATE'
                  ELSE
                  '    :NEW.'||column_name||');'
                END
              ELSE
                CASE
                  WHEN SUBSTR(column_name,1,2) = 'N_' THEN
                    '    :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
                  WHEN SUBSTR(column_name,1,2) = 'O_' THEN
                    '    NULL'||','
                  WHEN min_col = column_id THEN
                    '    1'||','
                  WHEN column_id = 2 THEN
                    '    ''I'''||','
                  WHEN column_id = 3 THEN
                    '    SYSDATE' ||','
                  ELSE
                    '    :NEW.'||column_name||','
                   END
              END AS txt,object_name, 4 disp_order, column_id
          FROM audit_tables t,
               user_tab_columns c
          WHERE c.table_name = t.object_name
          ORDER BY c.column_id ASC)
    UNION ALL
    SELECT txt, object_name, disp_order, column_id
    FROM(SELECT *' ELSIF updating THEN '* || CHR(13) ||
           '   INSERT INTO ' || object_name || CHR(13) ||
           '   (' txt, object_name, 5 disp_order, 0 column_id
    FROM audit_tables
    UNION ALL
    SELECT txt, object_name, disp_order, column_id
    FROM (SELECT 
            CASE
              WHEN max_col = column_id THEN
                '    '||column_name
              ELSE
                '    '||column_name || ','
              END AS txt, object_name, 6 disp_order, column_id
          FROM  audit_tables t,
                user_tab_columns C
          WHERE c.table_name = t.object_name
          ORDER BY c.column_id ASC)
    UNION ALL
    SELECT '   )' || CHR(13) ||
           '   VALUES ' || CHR(13) ||
           '   (', object_name, 7 disp_order, 0
    FROM audit_tables t
    UNION ALL
    SELECT txt, object_name, disp_order, column_id
    FROM (SELECT
            CASE
             WHEN max_col = column_id THEN
                CASE
                  WHEN SUBSTR(column_name,1,2) = 'N_' THEN
                    '    :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||');'
                  WHEN SUBSTR(column_name,1,2) = 'O_' THEN
                    '    :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||');'
                  WHEN min_col = column_id THEN
                    '    1'
                  WHEN column_id = 2 THEN
                    '     ''U'''
                  WHEN column_id = 3 THEN
                    '    SYSDATE'
                  ELSE
                  '    :NEW.'||column_name||');'
                END
              ELSE
                CASE
                  WHEN SUBSTR(column_name,1,2) = 'N_' THEN
                    '    :NEW.'||decode(substr(column_name,1,2),'N_',substr(column_name,3))||','
                  WHEN SUBSTR(column_name,1,2) = 'O_' THEN
                    '    :OLD.'||decode(substr(column_name,1,2),'O_',substr(column_name,3))||','
                  WHEN min_col = column_id THEN
                    '    1'||','
                  WHEN column_id = 2 THEN
                    '    ''U'''||','
                  WHEN column_id = 3 THEN
                    '    SYSDATE' ||','
                  ELSE
                    '    :NEW.'||column_name||','
                END
              END AS txt,object_name, 8 disp_order, column_id
          FROM audit_tables t,
               user_tab_columns c
          WHERE c.table_name = t.object_name
          ORDER BY c.column_id ASC)
    UNION ALL
    SELECT 'END IF;' || CHR(13) ||
           'END '||REPLACE(object_name,'_A_T') || '_ADT_TRG;' || CHR(13),
           object_name, 9 disp_order, 0
    FROM    audit_tables)
    ORDER BY object_name, disp_order, column_id)

  • Need Help with Formula using SQL maybe

    I need help!  I work with Crystal reports XI and usually manage just fine with the Formula editor but his one I think will require some SQL and I am not good at that.
    We are running SQL 2000 I think (Enterprise Manager 8.0)  Our sales people schedule activities and enter notes for customer accounts.  Each is stored in a separate table.  I need to find activities that are scheduled 240 days into the future and show the most recent note that goes with the account for which that activity is scheduled.
    The two tables, Activities and History, share the an accountID field in common that links them to the correct customer account.   I want to look at dates in the Startdate.Activities field more than 240 days in the future and show the most recent note from the History table where the accountid's match. I figure my query will contain a join on AccountID.Activities and AccountID.History used with Max(completedate.History) but I do not understand how to word it.
    I would like to perform all this in crystal if possible.  I humbly request your help.
    Membery

    You SQL would look something like this...
    SELECT
    a.AccountID,
    a.BlahBlahBlah, -- Any other fields you want from the Activities table
    h.LastComment
    FROM Activities AS a
    LEFT OUTER JOIN History AS h ON a.AccountID = h.AccountID
    WHERE (a.ActivityDate BETWEEN GetDate() AND DateAdd(dd, 240, GetDate()))
    AND h.HistoryID IN (
         SELECT MAX(HistoryID)
         FROM History
         GROUP BY AccountID)
    This method assumes that the History table has a HistoryID that increments up automatically each time a new comment is added... So a comment made today would always have a higher HistoryID that one made yesterday.
    If I'm wrong and there is no HistoryID or the HistoryID doesn't increment in a chronological fashion, it can still be done but the code is a bit more complex.
    HTH,
    Jason

  • Need help with min max sql

    hi all, forgot i had a user name and password and haven't needed help for quite a bit since i didn't do sql for a while but now i'm back at reporting again...
    Here is a sample table as i remember it:
    Item     Date     Time     Time Frame     Duration     Duration Frame
    A     20100926     0     5     500     10
    A     20100926     600     10     500     30
    A     20100926     1500     12     100     30
    B     20100926     1800     28     200     40
    B     20100926     2200     6     150     70
    B     20100926     2600     15     600     60
    B     20100926     3600     30     200     70
    Results Set (expected):                         
    Item     Date     Time     Total Duration          
    A     20100926     0     1600:20     --basically max (time+duration) - min(time+duration)     
    B     20100926     1800     2000:00
    Sorry, but. I didnt put my sql statement as I wasn't planning on posting and left it at work, but, i've been looking on internet and people say to use min/max function and i've attenpted it with it works with just this table (without grouping). But as soon as i group it the values seem to mess up.
    Last i remembered it gave me:
    Item     Date     Time     Total Duration          
    A     20100926     0     1600:30     --basically max(time+duration) - min(time+duration)     
    B     20100926     1800     2000:70
    I think it's looking at max duration which is 30&70 and hence it retrurns those values in the result set. Is it because of the max function hence it's returning this value? any help is appreciated. thanks
    Edited by: stanleyho on Sep 30, 2010 4:44 PM

    Okay, here we go again, repost, hopefully okay this time:
    Hi Madhu, okay, just got to work: I am using TOAD and working in Oracle 10g. Here is my table structure and the query i use to try and get what I am looking for:
    There is one extra table but that is only used to link these two tables listed below so i didn't bother posting it.
    TABLE: TX_RECON_INSTANCE_VIEW
    ColumnName ColID DataType Null
    CHANNEL_CODE 3 VARCHAR2 (4 Char) N
    DURATION 8 NUMBER (10) N
    DURATION_FRAME 9 NUMBER (2) N
    REAL_TIME 6 NUMBER (10) N
    REAL_TIME_FRAME 7 NUMBER (2) N
    ITEM_ID 4 NUMBER Y
    TX_DATE 2 CHAR (8 Byte) N
    TX_ID 1 NUMBER (9) N
    TX_TYPE 13 VARCHAR2 (4 Char) N
    TABLE: TX_SCHEDULE
    ColumnName ColID PK Null DataType
    TX_TYPE 22 N VARCHAR2 (4 Char)
    TX_ID 1 1 N NUMBER (9)
    TX_DATE 2 N CHAR (8 Byte)
    SCHEDULE_TIME_FRAME 9 N NUMBER (2)
    SCHEDULE_TIME 8 N NUMBER (10)
    REAL_TIME 10 N NUMBER (10)
    DURATION_FRAME 13 N NUMBER (2)
    DURATION 12 N NUMBER (10)________________________________________
    And the data and results:
    TX_ID TX_DATE REAL_TIME REAL_TIME_FRAME DURATION DURATION_FRAME ITEM_ID AS RUN TIME AS RUN DURATION SCHEDULED TIME SCHEDULED DURATION SCHEDULE_TIME SCHEDULE_TIME_FRAME DURATION_1 DURATION_FRAME_1
    1651000 20100710 0 0 545 20 1234 00:00:00:00 00:09:05:20 00:00:00:00 00:09:05:20 0 0 545 20
    1752223 20100710 667 12 281 7 1234 00:11:07:12 00:04:41:07 00:11:07:10 00:04:41:07 667 10 281 7
    1846501 20100710 1071 13 335 9 1234 00:17:51:13 00:05:35:09 00:17:50:09 00:05:35:09 1070 9 335 9
    2001102 20100710 1525 6 249 14 1234 00:25:25:06 00:04:09:14 00:25:22:08 00:04:09:14 1522 8 249 14
    3246669 20100710 1800 0 586 2 1235 00:30:00:00 00:09:46:02 00:30:00:00 00:09:46:02 1800 0 586 2
    4456822 20100710 2492 16 276 5 1235 00:41:32:16 00:04:36:05 00:41:32:16 00:04:36:05 2492 16 276 5
    1253168 20100710 2890 15 222 17 1235 00:48:10:15 00:03:42:17 00:48:10:15 00:03:42:17 2890 15 222 17
    1112456 20100710 3277 18 297 0 1235 00:54:37:18 00:04:57:00 00:54:35:10 00:04:57:00 3275 10 297 0
    Grouped results set:
    TX_DATE ITEM_ID AS RUN TIME AS RUN DURATION SCHEDULED TIME SCHEDULED DURATION
    20100710 1234 00:00:00:00 00:29:34:20 00:00:00:00 00:29:31:20
    20100710 1235 00:30:00:00 00:29:34:17 00:30:00:00 00:29:32:17
    --> SCHEDULED DURATION "00:29:31:20" is not correct as it should be (00:25:22:08+00:04:09:14)-(00:00:00:00)=00:29:31:22
    --> see expected results below
    Expected results:
    TX_DATE ITEM_ID AS RUN TIME AS RUN DURATION SCHEDULED TIME SCHEDULED DURATION
    20100710 1234 00:00:00:00 00:29:34:20 00:00:00:00 00:29:31:22
    20100710 1235 00:30:00:00 00:29:34:18 00:30:00:00 00:29:34:10________________________________________
    And the query I am using:
    SELECT --TXR.TX_ID,
    TXR.TX_DATE, TXR.ITEM_ID,
    TO_CHAR(TRUNC((MIN(TXR.REAL_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) )/3600),'FM00')||':'||TO_CHAR(TRUNC(MOD(MIN(TXR.REAL_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,3600)/60),'FM00')||':'||TO_CHAR(MOD(MIN(TXR.REAL_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00')||':'||TO_CHAR(MOD(MIN(TXR.REAL_TIME_FRAME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00') "AS RUN TIME",
    to_char(trunc((MAX(TXR.REAL_TIME+TXR.DURATION)-MIN(TXR.REAL_TIME))/3600),'FM00')||':'||to_char(trunc(mod(MAX(TXR.REAL_TIME+TXR.DURATION)-MIN(TXR.REAL_TIME),3600)/60),'FM00')||':'||to_char(mod(MAX(TXR.REAL_TIME+TXR.DURATION)-MIN(TXR.REAL_TIME),60),'FM00')||':'||to_char(mod(MAX(TXR.REAL_TIME_FRAME+TXR.DURATION_FRAME)-MIN(TXR.REAL_TIME),60),'FM00') "AS RUN DURATION",
    TO_CHAR(TRUNC((MIN(TXS.SCHEDULE_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) )/3600),'FM00')||':'||TO_CHAR(TRUNC(MOD(MIN(TXS.SCHEDULE_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,3600)/60),'FM00')||':'||TO_CHAR(MOD(MIN(TXS.SCHEDULE_TIME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00')||':'||TO_CHAR(MOD(MIN(TXS.SCHEDULE_TIME_FRAME) KEEP (DENSE_RANK FIRST ORDER BY TXR.REAL_TIME) ,60),'FM00') "SCHEDULED TIME",
    to_char(trunc((MAX(TXS.SCHEDULE_TIME+TXS.DURATION)-MIN(TXS.SCHEDULE_TIME))/3600),'FM00')||':'||to_char(trunc(mod(MAX(TXS.SCHEDULE_TIME+TXS.DURATION)-MIN(TXS.SCHEDULE_TIME),3600)/60),'FM00')||':'||to_char(mod(MAX(TXS.SCHEDULE_TIME+TXS.DURATION)-MIN(TXS.SCHEDULE_TIME),60),'FM00')||':'||to_char(mod(MAX(TXS.DURATION_FRAME),60),'FM00') "SCHEDULED DURATION"
    FROM TX_RECON_INSTANCE_VIEW TXR, TX_SCHEDULE TXS, TX_SCHEDULE_RECON TXREC
    WHERE TXR.TX_DATE=20100926 AND TXR.TX_TYPE='P'
    AND TXR.TX_ID=TXREC.RECON_TX_ID(+)
    AND TXREC.BASE_TX_ID=TXS.TX_ID(+)
    GROUP BY TXR.TX_DATE, TXR.ITEM_ID
    ORDER BY TXR.TX_DATE, TXR.ITEM_ID, MAX(TXR.REAL_TIME)--does this work for everyone now? let me know...thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need help in Report From SQL Query

    Hi All,
    I am facing a problem with a report. I need your help.
    I am creating a Report From SQL Query (Portal) with some arguments passed at runtime. I am able to view the output, if the query returns few rows ( arount 1000 rows). But for some inputs it needs to generate >15000 records, at this point the page is getting time out (i think!) and showing error page. I am able to execute query from the SQL Plus console ot using TOAD editor. Here the query is not taking more that 2 mins time to show the result.
    If i am executing from Portal i observed that, once i give the appropriate input and hit submit button a new oracle process is getting created for the query on UNIX (I am usign "TOP" command to check processes). The browser page will be shown error page after 5 minutes (i am assuming session time out!) , but on the backend the process will be executed for more than 30 mins.
    I tried also increase the page time out in httpd.conf, but no use.
    The data returned as a result of the query is sized more than 10 MB. Is caching this much data is possible by the browser page? is the returned data is creating any problem here.
    Please help me to find appropriate reasone for the failure?

    user602513 wrote:
    Hi All,
    I am facing a problem with a report. I need your help.
    I am creating a Report From SQL Query (Portal) with some arguments passed at runtime. I am able to view the output, if the query returns few rows ( arount 1000 rows). But for some inputs it needs to generate >15000 records, at this point the page is getting time out (i think!) and showing error page. I am able to execute query from the SQL Plus console ot using TOAD editor. Here the query is not taking more that 2 mins time to show the result.
    If i am executing from Portal i observed that, once i give the appropriate input and hit submit button a new oracle process is getting created for the query on UNIX (I am usign "TOP" command to check processes). The browser page will be shown error page after 5 minutes (i am assuming session time out!) , but on the backend the process will be executed for more than 30 mins.
    I tried also increase the page time out in httpd.conf, but no use.
    The data returned as a result of the query is sized more than 10 MB. Is caching this much data is possible by the browser page? is the returned data is creating any problem here.
    Please help me to find appropriate reasone for the failure?Do you get any errors or warnings or it is just the slow speed which is the issue?
    There could be a variety of reasons for the delayed processing of this report. That includes parameter settings for that page, cache settings, network configurations, etc.
    - explore best optimization for your query;
    - evaluate portal for best performance configuration; you may follow this note (Doc ID: *438794.1* ) for ideas;
    - third: for that particular page carrying that report, you can use caching wisely. browser cache is neither decent for large files, nor practical. instead, explore the page cache settings that portal provides.
    - also look for various log files (application.log and apache logs) if you are getting any warnings reflecting on some kind of processing halt.
    - and last but not the least: if you happen to bring up a portal report with more than 10000 rows for display then think about the usage of the report. Evaluate whether that report is good/useful for anything?
    HTH
    AMN

  • Need help in installation of SQL Developer in Win7

    Dear Frens,
    I got a task to validate the SQL developer(64 bit version) in Win7 environment. I followed the advice in this form and installed the 64 bit JDK first.
    It can be verified:
    C:\>java -version
    java version "1.6.0_26"
    Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
    Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
    Then SQL developer asked for the path of java.exe for the first time, and after configuring it to the correct path, I found it had problems creating the connection to the database when I tried to click database connection button. Please be noted, I do not have the win admin right for the PC.
    The error messages are listed below. Need some help from you guys.
    java.lang.NoClassDefFoundError: oracle/javatools/db/DBLog
         at oracle.jdeveloper.db.DatabaseConnectionStores.registerStoreProvider(DatabaseConnectionStores.java:388)
         at oracle.jdeveloper.db.DatabaseConnectionStores.<init>(DatabaseConnectionStores.java:74)
         at oracle.jdeveloper.db.DatabaseConnectionStores.getInstance(DatabaseConnectionStores.java:63)
         at oracle.jdeveloper.db.DatabaseActions.<init>(DatabaseActions.java:53)
         at oracle.jdeveloper.db.DatabaseActions.getConnectionEditorAction(DatabaseActions.java:79)
         at oracle.jdevimpl.db.DBConnWizard.invoke(DBConnWizard.java:38)
         at oracle.ide.wizard.WizardManager.invokeWizard(WizardManager.java:372)
         at oracle.ide.wizard.WizardManager$1.run(WizardManager.java:420)
         at oracle.ide.util.IdeUtil$3.run(IdeUtil.java:1079)
         at oracle.javatools.util.SwingUtils.invokeAfterRepaint(SwingUtils.java:520)
         at oracle.ide.util.IdeUtil.invokeAfterRepaint(IdeUtil.java:1092)
         at oracle.ide.wizard.WizardManager$2.run(WizardManager.java:428)
         at oracle.ide.util.IdeUtil$3.run(IdeUtil.java:1079)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
         at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
         at java.awt.EventQueue.access$000(EventQueue.java:84)
         at java.awt.EventQueue$1.run(EventQueue.java:602)
         at java.awt.EventQueue$1.run(EventQueue.java:600)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: oracle.classloader.util.AnnotatedClassNotFoundException:
         Missing class: oracle.javatools.db.DBLog
         Dependent class: oracle.jdeveloper.db.DatabaseConnectionStores
         Loader: ide-global:11.1.1.0.0
         Code-Source: //DBG.ADS.DB.COM/SNG-USERS-U/VF05_USERS08/liustea/config/Desktop/sqldeveloper64-2.1.1.64.45-no-jre/sqldeveloper/jdev/extensions/oracle.jdeveloper.db.connection.jar
         Configuration: extension jar in \\DBG.ADS.DB.COM\SNG-USERS-U\VF05_USERS08\liustea\config\Desktop\sqldeveloper64-2.1.1.64.45-no-jre\sqldeveloper\jdev\extensions
    This load was initiated at ide-global:11.1.1.0.0 using the loadClass() method.
    The missing class is not available from any code-source or loader in the system.
         at oracle.classloader.PolicyClassLoader.handleClassNotFound(PolicyClassLoader.java:2190)
         at oracle.classloader.PolicyClassLoader.internalLoadClass(PolicyClassLoader.java:1733)
         at oracle.classloader.PolicyClassLoader.access$000(PolicyClassLoader.java:143)
         at oracle.classloader.PolicyClassLoader$LoadClassAction.run(PolicyClassLoader.java:331)
         at java.security.AccessController.doPrivileged(Native Method)
         at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1692)
         at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1674)
         ... 27 more
    Steven Liu

    ateeqrahman wrote:
    Hi,
    I am planning to install Oracle 10g on RHEL. Can anyone plss tell me if the kernel parameters are set as default or according to hardware/software specifications. What other parameters should i be careful of. I have a database of around 40GB which i have to export from Oracle 8.0.6 running on Win 2000 server.
    Which linux version you are using .
    For RHEL & SUSE , please refer to :
    http://www.oracle.com/technology/pub/articles/smiley_10gdb_install.html#rhel4
    Also check :
    http://www.akadia.com/services/ora_linux_install_10g.html
    On OEL ,
    http://kamranagayev.wordpress.com/2010/04/25/video-tutorial-installing-oel-and-oracle-10gr2/
    Regards
    Rajesh

  • Need Help in correcting the sql statement

    H Experts,
    I am not if I can post this query in this section, but as I am executing this statement on repository DB , I assumed to post here.
    I have a requirement to calculate the database sizes from the tables in repository.
    table 1 : MGMT$DB_TABLESPACES_ALL : has the information on all the tablespace information from each database. and it has information of all the databases.
    table 2: MGMT$DB_REDOLOGS_ALL : has the information on all the redolog files information from each database. and it has information of all the databases.
    Now to calculate the size of each database , we need to collect the sizes from both tables and then need to add.
    below is the sql i prepared and sql didn't return and systax error , but the final output is completely wrong. Seems like its multiplying the data somewhere and getting the wrong information.
    please help me in doing the required modifications.
    =================================================================================================
    select a.TARGET_NAME "DATABASE_NAME" ,sum(a.TABLESPACE_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE ALLOCATED SPACE(GB)",
    sum(a.TABLESPACE_USED_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE USED SPACE(GB)",
    sum(a.TABLESPACE_SIZE/1024/1024/1024)-sum(a.TABLESPACE_USED_SIZE/1024/1024/1024) "DATABASE FREE SPACE(GB)"
    from MGMT$DB_TABLESPACES_ALL a ,MGMT$DB_REDOLOGS_ALL b
    where a.TARGET_NAME=b.TARGET_NAME and a.TARGET_Name like '%d2oem%'
    group by a.target_name;
    ====================================================================================================
    Note: There are multiple records having the same TARGET_NAME value in both the tables.
    please Help me in correcting the sql statement

    H Experts,
    I am not if I can post this query in this section, but as I am executing this statement on repository DB , I assumed to post here.
    I have a requirement to calculate the database sizes from the tables in repository.
    table 1 : MGMT$DB_TABLESPACES_ALL : has the information on all the tablespace information from each database. and it has information of all the databases.
    table 2: MGMT$DB_REDOLOGS_ALL : has the information on all the redolog files information from each database. and it has information of all the databases.
    Now to calculate the size of each database , we need to collect the sizes from both tables and then need to add.
    below is the sql i prepared and sql didn't return and systax error , but the final output is completely wrong. Seems like its multiplying the data somewhere and getting the wrong information.
    please help me in doing the required modifications.
    =================================================================================================
    select a.TARGET_NAME "DATABASE_NAME" ,sum(a.TABLESPACE_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE ALLOCATED SPACE(GB)",
    sum(a.TABLESPACE_USED_SIZE/1024/1024/1024)+sum(b.LOGSIZE/1024/1024/1024/1024) "DATABASE USED SPACE(GB)",
    sum(a.TABLESPACE_SIZE/1024/1024/1024)-sum(a.TABLESPACE_USED_SIZE/1024/1024/1024) "DATABASE FREE SPACE(GB)"
    from MGMT$DB_TABLESPACES_ALL a ,MGMT$DB_REDOLOGS_ALL b
    where a.TARGET_NAME=b.TARGET_NAME and a.TARGET_Name like '%d2oem%'
    group by a.target_name;
    ====================================================================================================
    Note: There are multiple records having the same TARGET_NAME value in both the tables.
    please Help me in correcting the sql statement

  • Need help connecting a MS Sql Database in CF Administrator

    Good morning,
    I`m hoping someone out there can help me.
    I simply want to add a MS SQL datasource within Coldfusion Administrator.
    I have connected to it successfully with Sql Server Management Studio, using Windows Authentication.
    I`m assuming I need to use Windows Authentication to connect within Coldfusion Administrator
    How do I fill out these fields then:
    because I am getting this error:
    Connection verification failed for data source: test
    java.sql.SQLNonTransientConnectionException: [Macromedia][SQLServer  JDBC Driver]Error establishing socket. Unknown host: local
    The root cause was that:  java.sql.SQLNonTransientConnectionException: [Macromedia][SQLServer JDBC  Driver]Error establishing socket. Unknown host: local
    I have also tried it with localhost as opposed to local.
    Please help?
    Thanks;
    Rhonda

    I believe you DON'T.
    ColdFusion, by default, does not run as any type of user that would work with Windows Authentication.  It can be set up to do so, through the windows services panel.  You configure the ColdFusion service(s) to "Log On As" some windows domain account with the desired permissions.  This is normally done to allow CFML code to access network resources for file operations and the like.
    But, I don't know if that is good enough for a connection to a SQL server.  I've never had to deal with it myself (I have operations and database administrators types who deal with this for me).  But I have read many many times on forums like this that the default security configuration of SQL server does not work with ColdFusion.  That one has to set up an alternate configuration in SQL, TCP/IP I think?

  • Urgently need help pls- error in sql

    hi everyone i need some help please. the error is :
    ("select title from book where resource_ID= (select resource_ID from
    resources where mem_ID='"+id+"')");     
    thanking u in advance
    here is the full program.
    <html>
    <head>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    </head>
    <body background="CLOTH003.GIF">
    <font face="comic sans ms" size="5">
    <br><br>
    <center>
    <center>
    <img border="0" src="search.JPG" width="107" height="30">
    <img border="0" src="edit.JPG" width="106" height="30">
    <img border="0" src="logout.JPG" width="95" height="30">
    <img border="0" src="help.GIF" width="105" height="30">
    <br>
    <br>
    <%
    // define database parameters
    String host="localhost:8080";
    String db="lsib";
    String optionSelected="";
    String conn;
    Statement createStatement = null;
    ResultSet rs = null;
    String user = "kushal";
    String pass = "";
    Class.forName("com.mysql.jdbc.Driver");
    // create connection string
    conn = "jdbc:mysql:" + host + "/" + db + "?user=" + user + "&password=" + pass;
    conn = "jdbc:mysql://localhost/LSIB";
    // pass database parameters to JDBC driver
    Connection Conn = DriverManager.getConnection(conn);
    // query statement
    Statement SQLStatement = Conn.createStatement();
    String id =request.getParameter("mem_ID");
    // generate query
    String sql="select name, fines,from member where mem_ID="+id;
    // get result
    rs= SQLStatement.executeQuery(sql);
    if (rs != null && rs.next() )
         String lname = rs.getString("name");
         int lfines = rs.getInt("fines");
         String ltitle = rs.getString("title");
    %>
         <form method="post" action="renew.jsp">
         <table border = "0" width="400">
         <tr>
         <td><b>hello</b></td><td><input name="logname" type="text" width="30" value="<%= lname           
    %>"></td>
         </tr>
         <tr>
         <td><b>you have a fine of �</b></td><td><input name="logfines" value="<%= lfines
    %>"></td>      
         </tr>
    <tr>
    <td><b>your resources on loan</b></td><td><select name="logtitle">
    <%
    rs= SQLStatement.executeQuery("select title from book where resource_ID= (select resource_ID from
    resources where mem_ID='"+id+"')");     
    if (rs != null)
         while (rs.next()) {
         String title = rs.getString("title");
         if(ltitle==title)
              optionSelected =" selected";
         else
              optionSelected="";
    %>
         <option value='<%= title %>' <%=optionSelected %>>
    <%
         }//end of while
    }//end of if
    %>
    </select></td>
    </tr>
    <tr>
         <td colspan = "2">
              <center>
                   <input type="submit" value=" renew ">
              </center>
         </td>
         </tr>
    </form>
    <%
    else
    out.println("No records found");               
    // close connection
    rs.close();
    SQLStatement.close();
    Conn.close();
    %>
    </table>
    </body>
    </html>

    hi here is the error:
    Error: 500
    Location: /LSIB/login.jsp
    Internal Servlet Error:
    javax.servlet.ServletException: Syntax error or access violation: You have an error in your SQL syntax near 'from member where mem_ID=830099' at line 1
         at org.apache.jasper.runtime.PageContextImpl.handlePageException(Unknown Source)
         at login_2._jspService(login_2.java:188)
         at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source)
         at org.apache.tomcat.core.Handler.invoke(Unknown Source)
         at org.apache.tomcat.core.Handler.service(Unknown Source)
         at org.apache.tomcat.facade.ServletHandler.service(Unknown Source)
         at org.apache.tomcat.facade.RequestDispatcherImpl.doForward(Unknown Source)
         at org.apache.tomcat.facade.RequestDispatcherImpl.forward(Unknown Source)
         at org.apache.jasper.runtime.PageContextImpl.forward(Unknown Source)
         at validate_7._jspService(validate_7.java:121)
         at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source)
         at org.apache.tomcat.core.Handler.invoke(Unknown Source)
         at org.apache.tomcat.core.Handler.service(Unknown Source)
         at org.apache.tomcat.facade.ServletHandler.service(Unknown Source)
         at org.apache.tomcat.core.ContextManager.internalService(Unknown Source)
         at org.apache.tomcat.core.ContextManager.service(Unknown Source)
         at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Unknown Source)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source)
         at java.lang.Thread.run(Thread.java:484)
    Root cause:
    java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near 'from member where mem_ID=830099' at line 1
         at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
         at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
         at com.mysql.jdbc.MysqlIO.sqlQuery(Unknown Source)
         at com.mysql.jdbc.Connection.execSQL(Unknown Source)
         at com.mysql.jdbc.Connection.execSQL(Unknown Source)
         at com.mysql.jdbc.Statement.executeQuery(Unknown Source)
         at com.mysql.jdbc.jdbc2.Statement.executeQuery(Unknown Source)
         at login_2._jspService(login_2.java:100)
         at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source)
         at org.apache.tomcat.core.Handler.invoke(Unknown Source)
         at org.apache.tomcat.core.Handler.service(Unknown Source)
         at org.apache.tomcat.facade.ServletHandler.service(Unknown Source)
         at org.apache.tomcat.facade.RequestDispatcherImpl.doForward(Unknown Source)
         at org.apache.tomcat.facade.RequestDispatcherImpl.forward(Unknown Source)
         at org.apache.jasper.runtime.PageContextImpl.forward(Unknown Source)
         at validate_7._jspService(validate_7.java:121)
         at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
         at org.apache.tomcat.facade.ServletHandler.doService(Unknown Source)
         at org.apache.tomcat.core.Handler.invoke(Unknown Source)
         at org.apache.tomcat.core.Handler.service(Unknown Source)
         at org.apache.tomcat.facade.ServletHandler.service(Unknown Source)
         at org.apache.tomcat.core.ContextManager.internalService(Unknown Source)
         at org.apache.tomcat.core.ContextManager.service(Unknown Source)
         at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Unknown Source)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(Unknown Source)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source)
         at java.lang.Thread.run(Thread.java:484)

  • Need help in writting the sql

    The sql
    select 'alter system kill session '||sid||','||serial#||';' from v$session where username= 'EV05';
    give the output in the below given form
    alter system kill session 69,38769;
    But i need the output to be
    alter system kill session '69,38769';
    Can some one re-writes the sql select statment,
    Thanks
    Naveen

    Naveen,
    This isn't the forum for help with writing SQL - rather with using the SQL Developer product. In future, I would suggest that you use the SQL and PL/SQL forum for these sorts of questions.
    However, to answer your question this time, you can include a ' in a string by having two together ie 'fred''s' will return the string fred's.
    The following SQL will give you the result you want:
    select 'alter system kill session '''||sid||','||serial#||''';' from v$session where username= 'EV05';

  • Need Help With Basics of SQL

    Hey I'm trying to get a working understanding of some of the basics behind SQL, I've composed a few questions that I think may help me with this. Anyone that can help me with any of them will greatly help me thanks.
    1. How to create synonym for tables?
    2. How to describe the structure of tables?
    3. How to list the contents of tables?
    4. How to create a table named with the same structure as another table?
    5. How to copy rows with less than a certain criteria in value (e.g. Price<$5.00) into another table?
    6. How to change the data type to e.g. NUMBER(6)?
    7. How to add a new column named with data type e.g. VARCHAR2(10)?
    8. How to change a specific field within a table (e.g. For ORDER_NUMBER 12489, change the C_NUMBER to 315)?
    9. How to delete a specific row from a table?
    10. How to declare a column as the primary key of a table and call it e.g. PK_something?
    11. How to show certain columns when another column is less than a certain criteria in value (e.g. Price<$5.00)?
    12. How to show certain columns with another column having a certain item class e.g. HW or AP?
    13. How to list certain columns when another column e.g. price is between two values?
    14. How to list certain columns when another column e.g. price is negative?
    15. How to use the IN operator to find certain columns (e.g. first and last name of customers who are serviced by a certain ID)
    16. How to find certain columns when one of the columns begins with a particular letter (e.g. A)
    18. How to list the contents of the a table sorted in ascending order of item class and, within each item class, sorted in descending order of e.g. price?
    19. How to do a count of column in a table?
    20. How to sum a column and make rename is something?
    21. How to do a count of a column in a table (without repeats e.g. if a certain number repeats more than once than to only count it once)?
    22. How to use a subquery to find certain fields in columns when the another column’s fields values are greater than e.g. its average price?

    848290 wrote:
    Hey I'm trying to get a working understanding of some of the basics behind SQL, I've composed a few questions that I think may help me with this. Anyone that can help me with any of them will greatly help me thanks.To use the terminology you have in those questions, you must already have a basic understanding of SQL, so you have exposed yourself as not being the author of such questions.
    Please do not ask homework questions without having at least attempted to answer them yourself first and show where you're struggling.

  • Need help in framing an SQL query

    Hi ,
    Requirement is that
    Let’s say I have a table say X
    I am passing two input params from UI and in DAO i am querying these input prams against the table X(has c1,c2 as columns ) (as it has two columns mapping the input params A,B from UI).
    if either one or Both of the input params matches ,only then i should fetch the records accordingly. It's understood that there won't be a scenario that both input params are null from UI.
    I have three conditions here,
    1.     A match against X, B doesnt Match
    2.     B match against X, A doesnt Match
    3.     Both A & B match against X
    if i use let's say,
    SELECT *FROM X WHERE (c1= A OR c2= B) .
    •     if A match against X B doesnt Match It is fetching all the records matching A - requirement fullfilled
    •     B match against X A doesnt Match It is fetching all the records matching B- requirement fullfilled.
    •     Both A & B match against X It is fetching all the records from the table matching the first condition (which here is A) . requirement not fullfilled.
    I am thinking of using the following query but I need to frame it in a way that based on ACHK & BCHK we need to add the conditions.
    SELECT CASE WHEN C1 = A THEN 0 ELSE 9 END AS ACHK, CASE WHEN C2 = B THEN 0 ELSE 9 END AS BCHK FROM X
    Based on ACHK & BCHK append the conditions. i.e.
    IF ACHK = 0 AND BCHK = 0 THEN
    AND C1 = A AND C2 = B
    ELSE
    AND (C1 = A OR C2 = B)
    Please help.

    Hi,
    963022 wrote:
    Would be glad if you can shed some light on role of DENSE_RANK here (ofcourse i did read the forums but i am confused on what basis a row is ranked).Complicated queries and expressions are usually built of smaller, simpler parts. To understand how the big, complicated thing works, look first at the smaller, simpler components of it, and make sure you understand how they work.
    In this case, the query is composed of a sub-query and a main query. Start by looking at the sub-query only. Display all rows and all columns of the sub-query.
    Break apart the complicated components of that sub-query. Rnk depends on an ORDER BY clause, but the expression used in that ORDER BY clause isn't displayed anywhere. Copy and display just that expression. (I called this case_1_2 in the query below.) Even that may be too complicated to understand, so break it apart. Case_1_2 is formed by adding 2 smaller CASE expressions; in the query below, I displayed each of the in separate columns (case_1 and case_2).
    So here's a query you might use to understand and debug the query I posted:
    WITH     targets          AS
         SELECT     'ABC' AS c1, 10 AS c2  FROM dual     UNION ALL
         SELECT     'ABC',          20            FROM dual     UNION ALL
         SELECT     'FOO',          10            FROM dual     UNION ALL
         SELECT     'FOO',          20            FROM dual     UNION ALL
         SELECT     'FOO',          99            FROM dual
    ,     got_rnk          AS
         SELECT     x.c1, x.c2
         ,     t.c1          AS target_c1
         ,     t.c2          AS target_c2
         ,     DENSE_RANK () OVER ( PARTITION BY  t.c1, t.c2
                                   ORDER BY          CASE
                                                 WHEN  x.c1  = t.c1
                                         THEN  1
                                         ELSE  0
                                             END
                                   + CASE
                                                 WHEN  x.c2  = t.c2
                                         THEN  2
                                         ELSE  0
                                             END
                             DESC
                           )          AS rnk
    --     *****  DEBUGGING SECTION  *****     The following columns are included only
    --                                       to see how the function above works.
         ,                               CASE
                                                 WHEN  x.c1  = t.c1
                                         THEN  1
                                         ELSE  0
                                             END
                                   + CASE
                                                 WHEN  x.c2  = t.c2
                                         THEN  2
                                         ELSE  0
                                             END           AS case_1_2
         ,                               CASE
                                                 WHEN  x.c1  = t.c1
                                         THEN  1
                                         ELSE  0
                                             END           AS case_1
         ,                            CASE
                                                 WHEN  x.c2  = t.c2
                                         THEN  2
                                         ELSE  0
                                             END           AS case_2
    --     *****  END OF DEBUGGING SECTION  *****
         FROM     targets  t
         JOIN           x  ON   x.c1     = t.c1
                       OR   x.c2     = t.c2
    --     The following main query is only for debugging
    SELECT       *
    FROM       got_rnk
    ORDER BY  target_c1, target_c2
    ,            rnk
    ;Output:
                  TARGET TARGET          CASE
    C1         C2 _C1       _C2    RNK   _1_2 CASE_1 CASE_2
    ABC        10 ABC        10      1      3      1      2
    ZZZ        10 ABC        10      2      2      0      2
    ABC         5 ABC        10      3      1      1      0
    ABC         6 ABC        10      3      1      1      0
    ABC         7 ABC        10      3      1      1      0
    ABC         1 ABC        10      3      1      1      0
    ABC         3 ABC        10      3      1      1      0
    ABC         2 ABC        10      3      1      1      0
    ABC         8 ABC        10      3      1      1      0
    ABC         9 ABC        10      3      1      1      0
    ABC         4 ABC        10      3      1      1      0
    ZZZ        20 ABC        20      1      2      0      2
    ABC        10 ABC        20      2      1      1      0
    ABC         2 ABC        20      2      1      1      0
    ABC         1 ABC        20      2      1      1      0
    ABC         9 ABC        20      2      1      1      0
    ABC         8 ABC        20      2      1      1      0
    ABC         7 ABC        20      2      1      1      0
    ABC         6 ABC        20      2      1      1      0
    ABC         5 ABC        20      2      1      1      0
    ABC         4 ABC        20      2      1      1      0
    ABC         3 ABC        20      2      1      1      0
    ABC        10 FOO        10      1      2      0      2
    ZZZ        10 FOO        10      1      2      0      2
    ZZZ        20 FOO        20      1      2      0      2Study this output to see how the different components work.
    For example, the first 12 rows of output show what we found when we were looking for ('ABC', 10). There were 12 rows in table x that had either ca='ABC' or c2=10 (or both). We used the rnk column to find the best match: lower numbers mean better matches. How did we do that? By using the DENSE_RANK function with a DESCending order by clause, that is, we used <tt> DENSE_RANK () OVER (... ORDER BY exp DESC) </tt>, which means that higher values of exp produce lower values from DENSE_RANK. What is exp? It's the column I called case_1_2. As you can see, when there was a perfect match ('ABC', 10), then case_1_2 had the value 3. Less perfect matches got lower values of case_1_2; for example ('ZZZ', 10) only had 2 in the case_1_2 column, and ('ABC', 5) only had 1. Why did case_1_2 have values of 3, 2 or 1 on those rows? Well, it's the sum of case_1 and case_2, so look at those individual columns, and see how they are computed.

  • Need help saving image to SQL as BLOB, then sending as email attachment

    Hi folks,
    These forums have gotten me most of the way through this particular project, but I'm finally stumped...
    First, I'll describe exactly what I'm trying to do: the user chooses an image file client side and the server-side code then converts it to binary data and saves it to SQL. Then as a separate step, an email will be sent out with that image file loaded from the DB as an attachment.
    So I've actually got most of this working. I'm using the O'Reilly MultipartParser class to pull the file input stream from the Request and insert it into SQL BLOB column ("image" datatype). I can successfully send Text attachments by simply converting the binary data back to a string and then using a subclass of DataSource (ByteArrayDataSource) to feed it to the mail object.
    After getting the text documents to work, I then moved on to trying to send images.
    I tried to send images using essentially the same technique as sending text. The image file gets saved to SQL the same way and I then convert the binary data back to a string an attach it. The only difference is that I set the content-type to "image/gif".
    I didn't really expect this to work, however, I am able to "Preview" very simple Gifs (in XP) that I've attached. I cannot "Open" them, though, and I cannot even "Preview" more complicated Gifs.
    So on to my real questions. I didn't really expect that you could simply output binary image data into Text format and simply slap on a ".gif" and expect it to work. Am I right about that? XP's "preview" option seems to read it okay, but I really need to be able to "open" these files.
    So basically I need to know what to DO with that binary data in SQL in order to successfully attach it as a true image file. Is this an encoding issue? MIME type?
    I didn't want to paste all the code but I'll paste the snippet that deals with the attachment section. If you'd like to see any other parts, please just let me know...
    MyBlobObject v_blob = new MyBlobObject(m_cp);  // the getBlobStr() method of this object simply grabs the data from SQL as a String
    DataSource source = new ByteArrayDataSource(v_blob.getBlobStr(),"application/octet-stream");
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setHeader("content-type","image/gif");
    messageBodyPart.setFileName(v_fileName);
    ...Another interesting thing I'm seeing is that when I view the small Gif as text, I see this:
    GIF89a � !� , D ;
    While the file I'm getting from SQL as an attachment looks like this:
    GIF89a ? !? , D ;
    Obviously, the question marks are unknown, but I'm not quite sure why. I outputted the char values as integers and found that the first question mark is 65408 and the second one's value is 65529. Obviously something is getting changed somewhere in the process, but I'm not quite sure how and where.
    anyway, thanks in advance for any advice!

    Nevermind! Of course, I figured it all out after writing that long post.
    I had tried using a byte array instead of the String in the ByteArrayDataSource and it hadn't worked. However once I cleaned up the code a bit I got it working.
    This links has it all...
    http://www.magelang.com/faq/view.jsp?EID=498439
    thanks anyway!

  • Need help with a Java-SQL connection

    My classmates and I created a DesktopFrame. Within it are reports that require a connection to an MS Access Database. When a report in an InternalFrame is opened: the SQL command works, there is a connection, and everything goes well on the first run.
    However, when another InternalFrame is opened or when the same InternalFrame is opened the 2nd time, an error occurs. It produces a java.sql.SQLException: General Error.
    Can anyone help me? Thanks in advance.

    Provide more info, maybe even some code segments. (Not all). May be easier to help

Maybe you are looking for

  • PO Print Problem

    Hi Gurus, If i Click on Print Overview i got below error , No messages found (Please check your input) Message no. ME230 Procedure Enter 1 (processing successful) in the "Processing time spot" field if you want to display the messages for this docume

  • Problem with URL in PDF

    Hi all I have a stange problem using my iPad (actually was tested on original iPad, iPad2, iPad3) I have a PDF documents that was sended to me. Inside a lot of pages and hyperlinks. Some of them are refers to website and some used for navigation insi

  • Users cannot publish and get error message

    Hey everyone. This one is stumping us here at the office. Some clients have been having a problem publishing things they have worked on from both their home AND their office. The error message they have been getting is quote: Contribute encountered a

  • How can I prevent this formating problem (changing fonts, lines etc) when converting PDF to a word document.

    I have a big problem when I convert my PDF to a word document, it is a mess. Is there a way to prevent this from happening. Font changes, table and lines formatting of lots of things. I am having to spend time editing and finding all the mistake, del

  • Hibernate SessionFactory in a cluster?

    I have been developing an application on WLS 8.1.4 with hibernate 3.1.2 .           On WLS I created           - adminServer on localhost:7001           - MyCluster group           - manageServer1 on localhost:7021           - manageServer2 on localh