How to make this query more efficient

Hi, i have query to find out the count of records based on certain conditions like below.
SELECT count(*)
FROM new_orders WHERE card_number IS NOT NULL
AND exp_date IS NOT NULL
AND card_id in ( select card_id from old_orders );
There are millions of records in both the tables. , so it is taking long time to run. Is there any solution to optimize this query.....thanks for help. Bcj

you might want to give this a try.
SELECT count(*)
  FROM new_orders no
WHERE no.card_number IS NOT NULL
   AND no.exp_date IS NOT NULL
   AND exists (select 'x'
                 from old_orders oo
                where oo.card_id = no.card_id);it would also help if you can post the information needed as suggested by rob.

Similar Messages

  • Make this query more elegant?

    can anybody tell me how to make this subquery more elegant?
    select 1 lfdidx from dual union
    select 2 lfdidx from dual union
    select 49 lfdidx from dual union
    select 50 lfdidx from dual
    Thanks in advance

    Sergey, thanks, that's what I hoped for.
    http://www.sqlsnippets.com/en/topic-11821.html has some additional info concerning this.
    Regards, Thomas

  • How do make this query ?

    CREATE TABLE CLIENT (
         CLIENTID NUMBER PRIMARY KEY,
         NAME VARCHAR2(40)
    CREATE TABLE SALESMAN (
         SALESMANID NUMBER PRIMARY KEY,
         NAME VARCHAR2(40),
         ALL_CLIENTS NUMBER -- ACCESS ALL CLIENTS IF VALUE IS 1
    CREATE TABLE CLIENTSALESMAN (
         SALESMANID NUMBER,
         CLIENTID NUMBER
    INSERT INTO CLIENT VALUES(1,'Bob');
    INSERT INTO CLIENT VALUES(2,'Jhon');
    INSERT INTO CLIENT VALUES(3,'Robert');
    INSERT INTO CLIENT VALUES(4,'Clarck');
    INSERT INTO SALESMAN VALUES (1,'Christina',0);
    INSERT INTO SALESMAN VALUES (2,'Doug',1); -- access all clients
    INSERT INTO CLIENTSALESMAN VALUES (1,1);
    INSERT INTO CLIENTSALESMAN VALUES (1,2);
    How do you return all the clients of a salesman ? same that SALESMAN.ALL = 1 OR SALESMAN.ALL = 0.
    the salesman.all is 1 then he access all clients no need insert in CLIENTSALESMAN. If SALESMAN.ALL = 0 he
    access clientsalesman.
    Does somebody some suggestion how i make this ?
    thanks !

      1  select *
      2  from (select a.name SALESMAN, b.name CLIENT
      3  from   salesman a, client b, clientsalesman
      4  where  a.SALESMANID = c.SALESMANID
      5  and    b.CLIENTID = c.CLIENTID
      6  union
      7  select a.name SALESMAN, b.name CLIENT
      8  from   salesman a, client b
      9  where   a.ALL_CLIENTS = 1)
    10* where salesman = '&1'
    SQL> /
    Enter value for 1: Christina
    old  10: where salesman = '&1'
    new  10: where salesman = 'Christina'
    Christina                                Bob
    Christina                                Jhon
    SQL> /
    Enter value for 1: Doug
    old  10: where salesman = '&1'
    new  10: where salesman = 'Doug'
    Doug                                     Bob
    Doug                                     Clarck
    Doug                                     Jhon
    Doug                                     RobertNicolas.

  • How to make this query go faster

    Hi ,
    I have the following query :
    select a.* from
    tbl1 a , tbl2 b
    where a.id = b.id
    substr(b.id , 3, 2) <> 'XX'
    and b.date1 is not null
    and b.date1 >= sysdate - 90 ;
    tbl1 - 21 million rows
    tbl2 - 2 millions
    i specify this hints /*+ INDEX(idxa_1 , idxa_2) INDEX(ixdb_1)
    where idxa_1 --> b.lotid
    idxa_2 --> b.date1
    idxb_1 --> a.lotid
    IF i DO NOT include b.date1 is not null and b.date1 >= sysdate - 90 ,
    from explain plan i could see it using a FAST FULL SCAN which really returns very fast
    HOWEVER if i include b.date1 is not null and b.date1 >= sysdate - 90
    , from explain plain it uses row index and then there's a range scan and its slow
    how can i improve the performance of this query ?
    pls advise
    tks & rdgs

    Don't create the temporary table.
    Create a function based index on table two
    substr(id , 3, 2)Make sure you have gathered statistics on the tables.
    Remove the hint.
    select a.* from
    tbl1 a , tbl2 b
    where a.id = b.id
    and substr(b.id , 3, 2) <> 'XX'
    and b.date1 >= sysdate - 90;If you still have performance problems, post the formatted explain plan from sqlplus.
    Read the Performance Tuning Guide.
    Unfortunately this is not urs advice.

  • How to make this query

    hi,
    i have 2 tables emp1 & emp2
    emp1 consist
    empno month amt
    001 201002 200
    001 201003 100
    emp2 consist
    empno month amt
    001 201001 100
    001 201002 200
    001 201003 100
    i want to make a query on emp1 table where i want to show amt according to month ,if data is not available in emp1 table then only then it should take data from emp2 table ,if emp2 has that month data o/w 0.
    my output should be like this
    empno month amt
    001 201001 100
    001 201002 200
    001 201003 100
    regards

    May be....
    SQL> WITH emp1 AS (SELECT '001' empno,'201002' mon,200 amt FROM DUAL UNION ALL
      2                SELECT '001' empno,'201003' mon,100 amt FROM DUAL
      3                )
      4  ,emp2 AS   ( SELECT '001' empno,'201001' mon,100 amt FROM DUAL UNION ALL 
      5               SELECT '001' empno,'201002' mon,200 amt FROM DUAL UNION ALL
      6               SELECT '001' empno,'201003' mon,100 amt FROM DUAL
      7              )
      8   SELECT coalesce(e1.empno,e2.empno) empno,
      9          coalesce(e1.mon,e2.mon) mon,
    10          coalesce(e1.amt,e2.amt)amt
    11   FROM emp1 e1 FULL OUTER JOIN emp2 e2
    12   ON e1.empno =e2.empno
    13     AND   e1.mon=e2.mon
    14  ORDER BY 2   ;
    EMP MON           AMT
    001 201001        100
    001 201002        200
    001 201003        100

  • To make the query more efficient (create table wiht select command)

    Hi,
    I have written this query to create another table, but it takes approx two hours while both tables are indexed with 891353, 769023, i have used the following query.
    create table source1 as select a.idx, a.source from tt a where a.idx not in (select b.idx from ttt b)
    thanks

    Try this one if you're on oracle 8i or older
    create table source1 as
      select a.idx, a.source
        from tt a
       where not exists (select null from ttt b where a.idx = b.idx)

  • How to make this query efficient

    create table temp)au_sa_poi_geocoding2 as select idx, address_form, suburb_form
    from temp_au_Sa_poi_geocoding a where idx not in (select idx from gc1_Sa_sub where status='m' ) and exists (select null from sh_poi_small cites c
    where upper (trim(a.suburb_form))=c.city)
    one table contain round 74214 records while the other has less than that.
    the tables were not indexed, i created index using the following commands.
    create index sa_idx on temp_au_sa_poi_geocoding(idx)
    create index sa1_idx on gc1_sa_sub(idx)
    anyhelp would be appreciated.
    thanks

    create index sa0_idx on temp_au_Sa_poi_geocoding(upper(trim(suburb_form)));
    create index sa1_idx on gc1_sa_sub(status,idx); -- instead of only (idx)
    create index sh_idx on sh_poi_small (city);
    then try as follows
    create table temp_au_sa_poi_geocoding2 as select idx,
    address_form, suburb_form
    from temp_au_Sa_poi_geocoding a where idx not in
    (select /*+ index gc1 */ idx from gc1_Sa_sub gc1 where status='m' ) and
    exists (select /*+ index_join c a */ null from sh_poi_small cites c
    where upper (trim(a.suburb_form))=c.city)
    however effects of indexes will vary by cardinality.

  • How to make this query executable in SSRS: The query cannot be prepared: The query must have at least one axis.

    WITH 
     MEMBER [FYDay].[DateHierarchy].[CurrentDay]    AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[PreviousDay]          AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]  .PREVMEMBER  }
    , [Measures].CURRENTMEMBER) 
    MEMBER [FYDay].[DateHierarchy].[CurrentDay1]           AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]  .LEAD(1)  }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[CurrentDay2]          AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2)  }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[CurrentDay3]          AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]  .LEAD(3)  }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[CurrentDay4]          AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]  .LEAD(4)  }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[CurrentDay5]          AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]  .LEAD(5)    }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[CurrentDay6]          AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]  .LEAD(6)  }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[CurrentDay7]          AS AGGREGATE( 
    {  [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]  .LEAD(7)  }
    , [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[PTD]                         AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD], 
      [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
    ), [Measures].CURRENTMEMBER) 
     MEMBER [FYDay].[DateHierarchy].[WTD]                         AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK], 
     [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
    ), [Measures].CURRENTMEMBER) 
    SELECT  
     [FYDay].[DateHierarchy].[WTD], 
           [FYDay].[DateHierarchy].[PTD], 
           [FYDay].[DateHierarchy].[PreviousDay], 
           [FYDay].[DateHierarchy].[CurrentDay], 
           [FYDay].[DateHierarchy].[CurrentDay1], 
           [FYDay].[DateHierarchy].[CurrentDay2], 
           [FYDay].[DateHierarchy].[CurrentDay3], 
           [FYDay].[DateHierarchy].[CurrentDay4], 
           [FYDay].[DateHierarchy].[CurrentDay5], 
           [FYDay].[DateHierarchy].[CurrentDay6], 
           [FYDay].[DateHierarchy].[CurrentDay7] 
     } ON COLUMNS, 
     [Measures].[Store Budget], 
     [MEASURES].[SNAPSHOTSOLDAMOUNT], 
     [MEASURES].[SHIPPEDAMOUNT], 
     [MEASURES].[SHIPPED VS SOLD], 
     [Measures].[% To Budget]
     {[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS} 
     )} ON ROWS 
     from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns 
     FROM [Model] 

    Hi Ramparasad,
    In your query, you add a measures and dimension on Row axis which is not supported in query designer in SSRS. Please use the query below.
    WITH
    MEMBER [FYDay].[DateHierarchy].[CurrentDay] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[PreviousDay] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .PREVMEMBER }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[CurrentDay1] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(1) }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[CurrentDay2] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(2) }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[CurrentDay3] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(3) }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[CurrentDay4] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(4) }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[CurrentDay5] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(5) }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[CurrentDay6] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(6) }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[CurrentDay7] AS AGGREGATE(
    { [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014] .LEAD(7) }
    , [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[PTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FPERIOD],
    [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
    ), [Measures].CURRENTMEMBER)
    MEMBER [FYDay].[DateHierarchy].[WTD] AS AGGREGATE(PERIODSTODATE([FYDay].[DateHierarchy].[FWEEK],
    [FYDay].[DateHierarchy].[FYEAR].&[2014].&[4].&[10].&[41].&[09/11/2014]
    ), [Measures].CURRENTMEMBER)
    SELECT
    [Measures].[Store Budget],
    [MEASURES].[SNAPSHOTSOLDAMOUNT],
    [MEASURES].[SHIPPEDAMOUNT],
    [MEASURES].[SHIPPED VS SOLD],
    [Measures].[% To Budget]
    }ON COLUMNS,
    { [FYDay].[DateHierarchy].[WTD],
    [FYDay].[DateHierarchy].[PTD],
    [FYDay].[DateHierarchy].[PreviousDay],
    [FYDay].[DateHierarchy].[CurrentDay],
    [FYDay].[DateHierarchy].[CurrentDay1],
    [FYDay].[DateHierarchy].[CurrentDay2],
    [FYDay].[DateHierarchy].[CurrentDay3],
    [FYDay].[DateHierarchy].[CurrentDay4],
    [FYDay].[DateHierarchy].[CurrentDay5],
    [FYDay].[DateHierarchy].[CurrentDay6],
    [FYDay].[DateHierarchy].[CurrentDay7]
    {[STOREMASTER].[SERVICINGDC].[SERVICINGDC].ALLMEMBERS}
    } ON ROWS
    from ( select {[STOREMASTER].[SERVICINGDC].&[Houston]} on columns
    FROM [Model]
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to make this code more simplified?

    hi, is there any possiibilty or logic to simply my code than below one?
    here my data is like that in a table
    sql>> select * from drawn order by effdate,code desc;
    CODE EFFDATE AMT
    1 01-JAN-06 30
    2 01-JUL-08 100
    2 01-JUL-09 150
    2 01-OCT-09 160
    1 01-OCT-09 50
    2 01-FEB-10 200
    2 01-MAR-10 250
    1 01-MAR-10 80
    1 01-APR-10 100
    from this my desired output should be:
    EXEC DUE_DRAWN ('01-SEP-08');
    code effdate amt(1+2)
    2 01-SEP-08 130
    2 01-JUL-09 180
    2 01-OCT-09 210
    2 01-FEB-10 250
    2 01-MAR-10 330
    1 01-APR-10 350
    here i want to display total amt as on particular date and with the particular code. if date are same in different code then code 2 will be given as priority . here outputput of amt is amt(code1+code2). so i have written below
    code...
    PROCEDURE DUE_DRAWN(V_DATE IN DATE) IS
    CURSOR C1(V_DATE IN DATE) IS SELECT * from drawn order by effdate,code desc;
    PREV_REC C1%ROWTYPE;
    CURR_REC C1%ROWTYPE;
    V_FDATE DATE;
    V_INL_GPY NUMBER(5):=0;
    V_BPY     NUMBER(5):=0;
    BEGIN
    OPEN C1(V_DATE);
    FETCH C1 INTO PREV_REC;
    V_INL_GPY:=PREV_REC.AMT;
    LOOP
         FETCH C1 INTO CURR_REC;
         EXIT WHEN C1%NOTFOUND;
         IF V_DATE > CURR_REC.EFFDATE THEN
              V_FDATE:=V_DATE;
         ELSE
              V_FDATE:=CURR_REC.EFFDATE;
         END IF;
         IF CURR_REC.CODE=2 THEN
              BEGIN
              SELECT AMT INTO V_INL_GPY FROM DRAWN WHERE CODE=1 AND EFFDATE=CURR_REC.EFFDATE;
              EXCEPTION
                   WHEN OTHERS THEN
                   NULL;
              END ;
              DBMS_OUTPUT.PUT_LINE(CURR_REC.CODE|| ' '||V_FDATE || ' '||(CURR_REC.AMT+V_INL_GPY));
         ELSIF CURR_REC.EFFDATE != PREV_REC.EFFDATE THEN
              SELECT AMT INTO V_BPY FROM DRAWN WHERE CODE=2 AND EFFDATE=(SELECT MAX(EFFDATE) FROM DRAWN
                                                                                                                            WHERE CODE=2 AND EFFDATE<=CURR_REC.EFFDATE);
                   DBMS_OUTPUT.PUT_LINE(CURR_REC.CODE|| ' '||V_FDATE || ' '||(CURR_REC.AMT+V_BPY));
              END IF;           
         PREV_REC:=CURR_REC;     
    END LOOP;
    END;
    please tell is there any other way to write this ...
    thanks
    Edited by: Hi FRNzzz!! on Jun 3, 2010 6:45 PM
    Edited by: Hi FRNzzz!! on Jun 3, 2010 7:43 PM
    Edited by: Hi FRNzzz!! on Jun 3, 2010 7:44 PM
    Edited by: Hi FRNzzz!! on Jun 3, 2010 7:47 PM

    The if condition is without an operator
    ELSIF CURR_REC.EFFDATE PREV_REC.EFFDATE THENwhat operator did you apply?
    When I run your code, with your sample data I get a different output to you, but I assumed a ">" operator for the above condition:
    SQL> declare
      2 
      3  V_DATE DATE :=TO_DATE('010908','ddmmyy');
      4  cursor c1 is
      5    select * from drawn order by effdate, code desc;
      6   
      7    PREV_REC  C1%ROWTYPE;
      8    CURR_REC  C1%ROWTYPE;
      9    V_FDATE   DATE;
    10    V_INL_GPY NUMBER(5) := 0;
    11    V_BPY     NUMBER(5) := 0;
    12   
    13  begin
    14 
    15    OPEN C1;
    16   
    17    FETCH C1 INTO PREV_REC;
    18    V_INL_GPY := PREV_REC.AMT;
    19   
    20    LOOP
    21      FETCH C1 INTO CURR_REC;
    22      EXIT WHEN C1%NOTFOUND;
    23     
    24      IF V_DATE > CURR_REC.EFFDATE THEN
    25        V_FDATE := V_DATE;
    26      ELSE
    27        V_FDATE := CURR_REC.EFFDATE;
    28      END IF;
    29     
    30      IF CURR_REC.CODE = 2 THEN
    31        BEGIN
    32          SELECT  AMT
    33          INTO    V_INL_GPY
    34          FROM    DRAWN
    35          WHERE   CODE    = 1
    36          AND     EFFDATE = CURR_REC.EFFDATE;
    37   
    38        EXCEPTION
    39          WHEN OTHERS THEN
    40            NULL;
    41 
    42        END ;
    43        DBMS_OUTPUT.PUT_LINE(CURR_REC.CODE || ' ' ||V_FDATE || ' ' || ( (CURR_REC.AMT + V_INL_GPY) * 0.1) );
    44 
    45      ELSIF CURR_REC.EFFDATE = PREV_REC.EFFDATE THEN
    46        SELECT  AMT
    47        INTO    V_BPY
    48        FROM    DRAWN
    49        WHERE   CODE    = 2
    50        AND     EFFDATE = (SELECT MAX(EFFDATE)
    51                           FROM   DRAWN
    52                           WHERE  CODE    = 2
    53                           AND    EFFDATE <= CURR_REC.EFFDATE);
    54                          
    55        DBMS_OUTPUT.PUT_LINE( CURR_REC.CODE|| ' ' || V_FDATE || ' ' || ( (CURR_REC.AMT+V_BPY) * 0.1 ) );
    56      END IF;
    57 
    58      PREV_REC := CURR_REC;
    59 
    60    END LOOP;
    61 
    62  END;
    63  /
    2 01-09-2008 00:00:00 13
    2 01-07-2009 00:00:00 18
    2 01-10-2009 00:00:00 21
    1 01-10-2009 00:00:00 21
    2 01-02-2010 00:00:00 25
    2 01-03-2010 00:00:00 33
    1 01-03-2010 00:00:00 33Also, could you kindly place before and after any code you post.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to solve this query

    hi,
    i have a product table like
    product month1 month2 month3 .................
    soap 1200 1256 1895 ............
    i want use a query where i can select column name with a parameter.
    like
    select month||:num from product;
    in num variable it cud be 1 to 10 of value that is dependent on my program.
    so how to make this query .
    thxs

    Hi,
    Here is an example that i am helpful.
    In the example , I am using a table 'table_name' which contains columns like
    assign_attribute1
    assign_attribute2
    assign_attribute15
    Now I will pass any number from 1 to 15 to the function.
    create or replace procedure pass_col_number(v_number varchar2) as
    v_sql varchar2(2000);
    v_assign_attribute1   varchar2(150);
    begin
    v_sql := 'select  assign_attribute'||v_number||'  from  table_name where person_id = 1345';
    execute immediate v_sql into v_assign_attribute1;
    dbms_output.put_line('v_assign_attribute1='||v_assign_attribute1);
    end;Edited by: Sreekanth Munagala on Dec 18, 2008 1:18 AM

  • How to write this query ?

    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno

    Hi,
    806540 wrote:
    how to write this query ?
    list the emp name who is working for the highest avg sal department.
    I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?ROW_NUMBER is just plain SQL, and has been since Oracle 8.1.
    ROW_NUMBER (or its close relative, RANK) is the simplest and most efficient way to solve this problem. Why not do this the right way?
    the row_number version is like this
    select emp.* from emp ,
    select deptno, row_number() over (order by avg(sal) desc) r from emp
    group by deptno
    )e
    where e.r = 1
    and emp.deptno = e.deptno
    If there happens to be a tie (that is, two or more departments have the same average sal, and it is the highest), then the query above will only arbitrarily treat one of them (no telling which one) as the highest. Change ROW_NUMBER to RANK to get all departments with a claim to having the highest average sal.
    You could use the ROWNUM pseudo-column instead of ROW_NUMBER, if all you want to do is avoid ROW_NUMBER.
    Without using ROW_NUMBER or RANK, there are lots of ways involving other analytic functions, such as AVG and MAX.
    If you really, really don't want to use analytic functions at all, you can do this:
    SELECT     *
    FROM     scott.emp
    WHERE     deptno     IN  (
                      SELECT       deptno
                      FROM       scott.emp
                      GROUP BY  deptno
                      HAVING       AVG (sal) =  (
                                                       SELECT    MAX (AVG (sal))
                                               FROM          scott.emp
                                               GROUP BY  deptno
    ;

  • How to write this query to filter combination of few values

    Hi,
    I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
    columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
    HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
    I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
    OR
    if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
    How to write this query?
    Regards

    Hi,
    I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
    CHILD_ID
           3
           4? If so, here's one way to get them:
    WITH     all_vacc_ids     AS
         SELECT     c.child_id
         ,     c.vacc_id          AS child_vacc_id
         ,     v.vacc_id
         ,     COUNT ( CASE
                             WHEN  c.vacc_id = 'HEXA'
                       THEN  1
                         END
                    )       OVER ( PARTITION BY  c.child_id
                                       )    AS hexa_itself
         FROM          vacc   v
         LEFT OUTER JOIN     chimm  c     PARTITION BY (c.child_id)
                          ON     c.vacc_id     = v.vacc_id
         WHERE   v.vacc_desc       = 'HEXA'     -- See note below
    SELECT       child_id
    FROM       all_vacc_ids
    WHERE       child_vacc_id     IS NULL
      AND       vacc_id     != 'HEXA'
      AND       hexa_itself     = 0
    GROUP BY  child_id
    rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
    You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher).

  • How To Make Search Query Showing the Result As List of Buttons.

    Can some one give me an idea how to start to make a Search Query showing the results as list of buttons.. i have already have my buttons with names. i just dont know how to make a search query.
    this is my on screen keyboard i made..
    im making a system that the result were a list of buttons.. showing like this
    This was supposed to be the output of the query that i need to do..
    Please help me.. i just need a idea or tips how to make this one.

    Here is code I posted recently for another question
    Public Class Form1
    Const BUTTON_SIZE As Integer = 20
    Const SPACE As Integer = 5
    Sub New()
    ' This call is required by the Windows Form Designer.
    InitializeComponent()
    ' Add any initialization after the InitializeComponent() call.
    Dim buttons As New List(Of List(Of MyRadioButton))
    For row = 1 To 6
    Dim newRow As New List(Of MyRadioButton)
    buttons.Add(newRow)
    For col = 1 To 6
    Dim button As New MyRadioButton()
    button.row = row
    button.col = col
    button.Height = BUTTON_SIZE
    button.Width = BUTTON_SIZE
    button.Left = col * (BUTTON_SIZE + SPACE)
    button.Top = row * (BUTTON_SIZE + SPACE)
    button.Name = String.Format("radGr1{0}_{1}", row.ToString(), col.ToString())
    Me.Controls.Add(button)
    newRow.Add(button)
    AddHandler button.CheckedChanged, AddressOf Radio_Change
    Next col
    Next row
    End Sub
    Private Sub Radio_Change(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim button As MyRadioButton = CType(sender, MyRadioButton)
    Dim row As Integer = button.row
    Dim col As Integer = button.col
    End Sub
    End Class
    Public Class MyRadioButton
    Inherits RadioButton
    Public row As Integer
    Public col As Integer
    End Class
    jdweng

  • Could you please help me make this query less complicated

    could you please help me make this query less complicated
    select t1.R_OBJECT_ID
    from dm_relation_sp a, ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID
    union all
    select t3.R_OBJECT_ID
    from ddt_resolution_sp t3
    where t3.R_OBJECT_ID in (select t2.child_id
    from dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    union all
    select t4.R_OBJECT_ID
    from ddt_resolution_sp t4
    where t4.R_OBJECT_ID in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    union all
    select t5.R_OBJECT_ID
    from ddt_resolution_sp t5
    where t5.R_OBJECT_ID in
    (select t4.child_id
    from dm_relation_sp t4
    where t4.parent_id in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    and t4.relation_name = 'RESOLUTION_RELATION')
    Edited by: user13025450 on 29.04.2010 16:23

    Hi,
    Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
    Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
    Describe what you're doing. Think about it: how do we know that
    SELECT  NULL
    FROM    dual;doesn't do what you want?
    Post CREATE TABLE and INSERT statements for a little sample data.
    Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
    Describe, as well as you can, how the present query is doing it.
    Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
    When posting formatted text (code or results) type these 6 characters
    \(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
    Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
    I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Something keeps trying to download on my mac and I don't know what it is. It is not in the apple store and just comes out nowhere and request for my password to download something and I don't know what it is. How to make this stop?

    Something keeps trying to download on my mac and I don't know what it is. It is not in the apple store and just comes out nowhere and request for my password to download something and I don't know what it is. How to make this stop? It pops up every single day.

    Erica,
         I can, with 99.99% certainty, tell you that you are absolutely right in not wanting to download or install this "Helper," whatever it is (but we can be equally certain it would not "help" anything).
         I cannot comment as to Oglethorpe's recommendation of 'adwaremedic'; I am unfamiliar with it.  His links to the Apple discussion and support pages warrant your time and attention.
         It might be really simple -- Trying looking in your Downloads folder, trash anything that you don't know with certainty is something you want to keep, and then Secure Empty your Trash. Then remove the AdBlock extension, LastPass, and Web of Trust extensions to Safari and re-boot. If the issue goes away, still be extraordinarily careful in the future.
         Unfortunately, it's probably not going to be that simple to get rid of, in which case I'd then try the line by line editing in HT203987. 
         I have no further suggestions (other than a complete wipe and re-install...but that's a pain because trying to restore from Time Machine would simply ... restore the Mal).
       For the rest of us, please post when you find a solution.
         Best.
         BPW
      (Also, try to edit your second post -- black out your last name on the screenshot and re-post it for others)

Maybe you are looking for