Internal Table query Please help!!!!!

Q. What is the differance between:
TABLES:  KNA1.
PARAMETERS:  STATE LIKE KNA1-REGIO DEFAULT ‘MA’.
TYPES:       BEGIN OF OUTREC,
             KUNNR LIKE KNA1-KUNNR,
             REGIO  LIKE KNA1-REGIO,
             TELF1  LIKE KNA1-TELF1,
          END OF OUTREC.
DATA:     OUT_ITAB <b>TYPE</b> STANDARD TABLE OF OUTREC
             INITIAL SIZE 10 WITH HEADER LINE.
and
TABLES:  KNA1.
PARAMETERS:  STATE LIKE KNA1-REGIO DEFAULT ‘MA’.
TYPES:       BEGIN OF OUTREC,
             KUNNR LIKE KNA1-KUNNR,
             REGIO  LIKE KNA1-REGIO,
             TELF1  LIKE KNA1-TELF1,
          END OF OUTREC.
DATA:     OUT_ITAB <b>LIKE</b> STANDARD TABLE OF OUTREC
             INITIAL SIZE 10 WITH HEADER LINE.
also cant we write it as:
DATA:     OUT_ITAB LIKE KNA1OCCURS 10 WITH HEADER LINE.
Thanks,
Dhiraj

hi Dhiraj,
Refer to this related thread
Re: Occurs 0 Versus Type standard table of
Difference between Declaring variables

Similar Messages

  • Pivot table query - PLEASE HELP

    I have one requirement whichis similar like this.
    I have following tables.
    POSITIONS (one account holds multiple securities)
    account_id     security_id     total
    1          101          300
    1          102          500
    2          102          300
    2          103          600
    3          104          400
    4          104          800
    SECURITIES
    security_id     security_name     country          region
    101          ABC          USA          NA
    102          EFG          USA          NA
    103          PQR          GBR          EUR
    104          XYZ          CANADA          NA
    I will get all the account numbers from front end application, for which I have to display output like this. For example I am getting accounts, 1,2,3 and 4 and have to display like columns at the end. I have to groupy by region and country.
    REGION     COUNTRY          SECURITY_ID     SECURITY_NAME          1     2     3     4
    NA     USA          101          ABC               300
                   102          EFG               500     300
                             COUNTRY TOTAL          800     300
         CANADA          104          XYZ                         400     800
                             REGION TOTAL          800     300     400     800
    EUR     GBR          103          PQR                    600
                             COUNTRY TOTAL               600          
                             REGION TOTAL          800     900     400     800
    I am working on Oracle 9i Release 2 and front end is .net. Can anyone please help me out with a solution using a query or a stored proc. For Stored procedure, I should send refcurser as OUT parameter or any possible solution.
    Thanks in advance.

    You could do the following:
    In SQL
    You can use the decode function and SUM over it.
    Get the totals by region and country
    select region,country, s.sec_id, sec_name,
    sum(decode(acct_id,1,total,0)) a1,
    sum(decode(acct_id,2,total,0)) a2,
    sum(decode(acct_id,3,total,0)) a3,
    sum(decode(acct_id,4,total,0)) a4
    from positions p, securities s
    where p.SEC_ID = s.SEC_ID
    group by region,country, s.sec_id, sec_name
    You can run similar sql to get totals by country or region separately ... just remove from select and group by clause the column name that you do not want to be displayed.
    The limitation here is that you would need to write the decode statement for every account. Some programming may be needed here.
    In PLSQL
    create or replace procedure acct_sum (cr OUT sys_refcursor)
    is
    cursor c1 is
    select distinct acct_id from positions order by 1 asc;
    var1 varchar2(1000) := ' ';
    var2 varchar2(1000);
    begin
    for i in c1 loop
    var1 := var1 || ' sum(decode(acct_id, ' || i.acct_id || ', total,0) ),';
    end loop;
    var1 := substr(var1,1,length(var1)-1);
    open cr for
    'select region,country, s.sec_id, sec_name, ' || var1 ||
    'from positions p, securities s
    where p.SEC_ID = s.SEC_ID
    group by region,country, s.sec_id, sec_name';
    end acct_sum;
    You may want to modify the code so pass in an array of accounts and loop through the content to get all the accounts.
    Hope this helps
    Shakti
    http://www.impact-sol.com
    Developers of Guggi Oracle - Tool for DBAs and Developers

  • How to improve the performance of the attached query, Please help

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description                    Object_owner          Object_name     Cost     Cardinality     Bytes     
    SELECT STATEMENT, GOAL = ALL_ROWS                              14     1     13
    SORT AGGREGATE                                                  1     13
    VIEW                         GEMINI_REPORTING               14     1     13
    HASH GROUP BY                                        14     1     103
    NESTED LOOPS                                        13     1     103
    HASH JOIN                                             12     1     85
    TABLE ACCESS BY INDEX ROWID     GEMINI_REPORTING     RCAMSIT          2     4     100
    NESTED LOOPS                                        9     5     325
    HASH JOIN                                        7     1     40
    SORT UNIQUE                                        2     1     18
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          SITE          2     1     18
    INDEX RANGE SCAN          GEMINI_PRIMARY          SITE_I0          1     1     
    TABLE ACCESS FULL          GEMINI_PRIMARY          SITE          3     27     594
    INDEX RANGE SCAN          GEMINI_REPORTING     RCAMSIT_I     1     1     5     
    TABLE ACCESS FULL     GEMINI_PRIMARY     CAMPAIGN                    3     127     2540
    TABLE ACCESS BY INDEX ROWID     GEMINI_PRIMARY          CAMBILLING     1     1     18
    INDEX UNIQUE SCAN     GEMINI_PRIMARY     CAMBILLING_U1                    0     1

    Hello,
    This has really nothing to do with the Oracle Forms product.
    Please, send the SQL or/and PL/SQL questions in the corresponding forums.
    Francois

  • How to use internal table in F4 help?

    Hello Experts,
    I need to assign F4 help for Employee Responsible ID field in Search Criteria. I'm able to fetch the details of all employees into an internal table in get_v_xyz method of employee res. attribute. My doubt is,Can we display an internal table as F4 help. If yes, How can we do that?
    Regards
    DNR Varma

    Hi,
    here is the code to be written in GET_V to add itnernal table as search help.
    data:
    GR_DDLB_DIVISION TYPE REF TO CL_CRM_UIU_DDLB,
    data:
    ls_value      TYPE bsp_wd_dropdown_line,
    lt_ddlb       TYPE bsp_wd_dropdown_table.
      IF gr_ddlb_division IS NOT BOUND.
        CREATE OBJECT gr_ddlb_division
          EXPORTING
            iv_source_type = ''T'.
        LOOP AT internal table INTO work area.
          ls_value-key      = work area-key.
          ls_value-value = work area-value.
            INSERT ls_value INTO TABLE lt_ddlb.
          ENDLOOP.
    gr_ddlb_division->set_selection_table( it_selection_table = lt_ddlb ).
    endif.
    rv_valuehelp_descriptor = gr_ddlb_division.
    Thanks
    Sudhir Grover

  • Export specific records from all table? Please help me with my query

    hi
    there are around 200 tables, I want to take a export of all tables of xyz schema.
    My requirement is just a few records of primary key and their relevant records from other tables to be exported by using exp or expdp utility.

    Hi Toni...
    Thanks for your reply.
    Could you please help me understand how to user this expdp query...
    and what exactly should i mention in the parfile. I want all relevant records from all tables of primary key. please help me to write a query accordingly.

  • Help with Internal table - Urgent Please

    I had an internal table declared as below:
    DATA: BEGIN OF i_results OCCURS 0,
            pernr like p0014-pernr,
            begda like zhrccroll-begda,   "Cost center roll out begin date
            endda like zhrccroll-endda,    "Cost center roll out end date
            aedtm like p0014-aedtm,
            uname like p0014-uname,
            kostl like p0001-kostl,
           ittype(7),
          END OF i_results.
    And my SQL to populate the table based on some other results:
    select t1pernr t3begda t3endda t1aedtm t1uname t2kostl
      appending corresponding  fields of table i_results
      from pa0014 as t1
      inner join pa0001 as t2
      on t1pernr = t2pernr
      inner join zhrccroll as t3
      on t2kostl = t3kostl
      for all entries in i_it01
      where t1~pernr = i_it01-pernr
      and t2~kostl = i_it01-kostl
      and t3~kostl = i_it01-kostl
      and t3~syst = 'STAFF'
      and t1~aedtm = p_date
      and t1~uname in so_name.
    Everything was working great and now user wants to see additional dates on the report so I have to add couple of dates to internal table but unfortunately they have same names (begda, endda), Now I need internal table like this:
    DATA: BEGIN OF i_results OCCURS 0,
            pernr like p0014-pernr,
            begda like zhrccroll-begda,   "Cost center roll out begin date
            endda like zhrccroll-endda,    "Cost center roll out end date
            aedtm like p0014-aedtm,
            uname like p0014-uname,
            kostl like p0001-kostl,
            begda like p0014-begda,  "infotype begin date
            endda like p0014-endda,  "infotype end date
            ittype(7),
          END OF i_results.
    I cannot have duplicate declarations in internal table and also my SQL would not work. The new SQL would be:
    select t1pernr t3begda t3endda t1aedtm t1uname t2kostl
      t1begda t1endda
      appending corresponding  fields of table i_results
      from pa0014 as t1
      inner join pa0001 as t2
      on t1pernr = t2pernr
      inner join zhrccroll as t3
      on t2kostl = t3kostl
      for all entries in i_it01
      where t1~pernr = i_it01-pernr
      and t2~kostl = i_it01-kostl
      and t3~kostl = i_it01-kostl
      and t3~syst = 'STAFF'
      and t1~aedtm = p_date
      and t1~uname in so_name.
    This is not working either.
    Could comeone please help me how to acheive the desired result. I am trying to get all the data in one shot, and that is why I have the SQL above. Any ideas you could provide would be greatly appreciated.
    Thanks in advance.
    Mithun

    HI Mithun,
      To add to vishnu do not use "appending corresponding fields of"..
    1) if you are reading this data again and again then use
      "appending table itab"
    2) if it is triggered just once then use
      "into table itab"
    And also define ur itab as:
    DATA: BEGIN OF i_results OCCURS 0,
    pernr like p0014-pernr,
    ccbegda like zhrccroll-begda, "Cost center roll out begin date
    ccendda like zhrccroll-endda, "Cost center roll out end date
    aedtm like p0014-aedtm,
    uname like p0014-uname,
    kostl like p0001-kostl,
    begda like p0014-begda, "infotype begin date
    endda like p0014-endda, "infotype end date
    ittype(7),
    END OF i_results.
    and your select statement as:
    select t1pernr t3begda as ccbegda t3endda as ccenda t1aedtm t1~uname
    t2kostl t1begda t1~endda into table i_results
    from pa0014 as t1
    inner join pa0001 as t2
    on t1pernr = t2pernr
    inner join zhrccroll as t3
    on t2kostl = t3kostl
    for all entries in i_it01
    where t1~pernr = i_it01-pernr
    and t2~kostl = i_it01-kostl
    and t3~kostl = i_it01-kostl
    and t3~syst = 'STAFF'
    and t1~aedtm = p_date
    and t1~uname in so_name
    I am sure you need to tweak and twist the above statements a bit..
    Hope this helps..
    BR
    Rakesh
    PS: Please close the thread if your problem is solved..

  • PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP

    I have got three tables :
    CREATE TABLE FIRM
    (FID INTEGER NOT NULL PRIMARY KEY,
    FNAME VARCHAR(40),
    FTYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE FACULTY
    (FAID INTEGER NOT NULL PRIMARY KEY,
    FANAME VARCHAR(40),
    FATYPE VARCHAR(3),
    MASTERID INTEGER );
    CREATE TABLE EMPLOYEE
         (EID INTEGER NOT NULL PRIMARY KEY,
    ENAME VARCHAR(20),
    ESURNAME VARCHAR(20),
         EJOB VARCHAR(3),
         MASTERID INTEGER );
    This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
    I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
    I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
    I completely don,t know how to write it. Please help.

    create view hierarchy as
    select id, master_id, name from table1
    union all
    select id, master_id, name from table2
    union all
    select id, master_id, name from table3
    Then do your connect by query against hierarchy.
    It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
    Kirill

  • Help to correct to codes to move data from tables! please help!

    HI,
    There is a internal table t and t1. I used loop to move the data which zuonr has no value from t to t1.
    BSID TABLE:
    KUNNR                 ZUONR
    0000052984         no value                            &#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;&#12288;  0000052984          no value                                            00052984              2007/06&#27770;&#31639;
    00052984               no value
    000052984          &#12288;2007/07&#25391;&#24403;      
    0000052984            MSFT047/07
    0000052984           MSFT061/07
    *what I need to do is that to move all the data belonge to the same kunnr whenever zuonr = space happend. *.
    The problem is that the data which zuonr = space is moved to t1 successful, but the other data which belong to the same kunnr has zuonr valune still remain.
    -Question_ : How to move all the data belong to the same kunnr whenever zuonr = space happend.
    DATA: BEGIN OF t OCCURS 0,
            bukrs   LIKE knb1-bukrs,
            zuonr   Like bsid-zuonr,                        "sort key  "CR01
            belnr   LIKE bsid-belnr,
            kunnr   LIKE kna1-kunnr,
            bldat   LIKE bsid-bldat,
            budat   LIKE bsid-budat,
            netdt   LIKE bsega-netdt,
            waers   LIKE bsid-waers,
            wrbtr   LIKE bsid-wrbtr,
            shkzg   LIKE bsid-shkzg,
            xblnr   LIKE bsid-xblnr,                            "WD041005a
            sgtxt   LIKE bsid-sgtxt,
            dmbtr   LIKE bsid-dmbtr,
          END OF t.
    DATA : t1 LIKE STANDARD TABLE OF t WITH HEADER LINE.
    *LOOP AT t WHERE zuonr EQ space.
      MOVE-CORRESPONDING t TO t1.
      APPEND t1.
    ENDLOOP.*
    How can I write the loop statement to mention  the KUNNR
    Please help, thank you!!

    Hi,
    Try this.
    data : wa_t like line of table t.
    field-symbols : <f_t> like line of table t.
    sort t by kunnr.
    Loop at t where zuonr eq space.
    read table t1 with key kunnr = t-kunnr.
    if sy-subrc = 0.
    continue.
    endif.
    read table t into wa_t with key kunnr = t-kunnr.
    if sy-subrc = 0.
    loop at t assigning <f_t> from sy-tabix..
    if <f_t>-kunnr = wa_t-kunnr.
    move-corresponding <f_t> to t1.
    append t1.
    else.
    exit.
    endif.
    endloop.
    endif.
    endloop.
    Regards,
    Mohaiyuddin

  • How to make recursive query.Please help

    Dear Experts:
    I want to retrieve all employees located in a department in addition to all other employees located in the child's nodes of this department too.
    Problem Details:
    I have "Employees" table and "Departments" Table
    The structure of Dept Table is:
    ID   primary key
    parent_dept   foreign key(id)
    deptname  varchar2
    deptType varchar2
    The Employee table structure is
    ID primary key
    dept_id foreign key(Department.id)
    empName varchar2Sample data for departments
    ID : 1
    parent_dept : null
    deptname: General Manager office
    deptType : 'GM'
    ID :=2
    parent_dept : 1
    deptname: Information tech.
    deptType : 'DPT'
    ID :=3
    parent_dept : 2
    deptname: Software Development
    deptType : 'SECTION'Sample Data for employees
    ID : 101
    dept_id  :1
    empName  King
    ID : 102
    dept_id  :2
    empName  ALAN
    ID : 103
    dept_id  :2
    empName  SAM
    ID : 104
    dept_id  :3
    empName  JANEI want to create a query that accepts a parameter "p_department_id" and returns All employees on the following conditions
    1- In case the parameter value is null , then retrieve All Employees "king - alan- sam-jane"
    2- In Case the parameter value is 1 , then retrieve all the employees under department id =1 in addition to all the employees located under the children departments.
    in this case it will be "king - alan- sam-jane"
    3- In case parameter value is 2 , then return all the employees under department id =2 in addition to all the employees located under the children departments.
    In this case it will be " alan- sam-jane"
    4- In case parameter value is 3 , then return all the employees under department id =3 in addition to all the employees located under the children departments.
    in this case it will be only "JANE"
    In brief , If I pass any value to the parameter :p_department_id , I want to retrieve all employees located in this department in addition to other employees located in the child's nodes of this department id
    I use oracle database 11g release 2
    Please help me
    Thanks
    Edited by: ta**** on Apr 3, 2013 5:56 PM
    Edited by: ta**** on Apr 3, 2013 5:58 PM

    SQL> variable p_department_id number
    SQL> exec :p_department_id := null
    PL/SQL procedure successfully completed.
    SQL> with employees as (
      2                     select 101 id,1 dept_id,'King' empName from dual union all
      3                     select 102,2,'ALAN' from dual union all
      4                     select 103,2,'SAM' from dual union all
      5                     select 104,3,'JANE' from dual
      6                    ),
      7     departments as (
      8                     select 1 id,null parent_dept,'General Manager office' deptname,'GM' deptType from dual union all
      9                     select 2,1,'Information tech.','DPT' from dual union all
    10                     select 3,2,'Software Development','SECTION' from dual
    11                    )
    12  select  *
    13    from  employees
    14    where dept_id in (
    15                      select  id
    16                        from  departments
    17                        start with (
    18                                       (
    19                                            :p_department_id is null
    20                                        and
    21                                            parent_dept is null
    22                                       )
    23                                    or
    24                                       id = :p_department_id
    25                                   )
    26                        connect by parent_dept = prior id
    27                     )
    28  /
            ID    DEPT_ID EMPN
           101          1 King
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 1
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           101          1 King
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 2
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           102          2 ALAN
           103          2 SAM
           104          3 JANE
    SQL> exec :p_department_id := 3
    PL/SQL procedure successfully completed.
    SQL> /
            ID    DEPT_ID EMPN
           104          3 JANE
    SQL> SY.

  • SQL Query -- Please Help

    Table1
    QTE_ID     SEQ_NO
    1435177     2
    1435177     5
    1435177     7
    1435177     8
    1435177     12
    1435177     14
    Table2
    QTE_ID     SEQ_NO     CMMT_CURR_AMT
    1435177     1     98500
    1435177     2     98500
    1435177     3     0
    1435177     4     98500
    1435177     5     98500
    1435177     7     98500
    1435177     8     98500
    1435177     11     59300
    1435177     12     59300
    1435177     14     59300
    The result should be
    QTE_ID     SEQ_NO     CMMT_CURR_AMT
    1435177     2     0 (where 0 = cmmt_curr_amt of seq 2 - cmmt_curr_amt of seq 1 from table 2)
    1435177     5     0 (where 0 = cmmt_curr_amt of seq 5 - cmmt_curr_amt of seq 4 from table 2)
    1435177     7     0 (where 0 = cmmt_curr_amt of seq 7 - cmmt_curr_amt of seq 5 from table 2)
    1435177     8     0 (where 0 = cmmt_curr_amt of seq 8 - cmmt_curr_amt of seq 7 from table 2)
    1435177     12     0 (where 0 = cmmt_curr_amt of seq 12 - cmmt_curr_amt of seq 11 from table 2)
    1435177     14     0 (where 0 = cmmt_curr_amt of seq 14 - cmmt_curr_amt of seq 12 from table 2)
    I have to get the difference of cmmt_curr_amt from the table2 from seq 14 to seq 12 for seq14 in table 1.
    Please help me in writing the query.
    Thanks in advance.
    Srinivas

    WITH table1 AS
    (SELECT 1435177 qte_id, 2 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no
    FROM dual
    table2 AS
    SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
    FROM dual
    SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
    FROM
    (SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
    FROM table1 t1, table2 t2
    WHERE t2.qte_id = t1.qte_id (+)
    AND t2.seq_no = t1.seq_no(+)
    ORDER BY 1,2
    WHERE t1_seq_no IS NOT NULL
    ORDER BY 1,2
    QTE_ID T2_SEQ_NO DIFF
    1435177 2 0
    1435177 5 0
    1435177 7 0
    1435177 8 0
    1435177 12 0
    1435177 14 0

  • Passing parameter to a SQL query - Please help

    Hi All,
    I am new to JDBC. I have been trying to pass an external variable to an SQL Query.
    The query is
    String username1="le";
    PreparedStatement pstmt = null;
    pstmt = c.prepareStatement("select * from users where USER_NAME like '%?%'");
         pstmt.setString(1, username1);
         pstmt.executeQuery();
         ResultSet rs = pstmt.getResultSet();
    I am trying to retrieve values from the users table where the USER_NAME column value that is a String contains the supplied value username1.
    I am using the question mark (?) character to pass the value from the variable username1. I am also using the '%' substitution character which matches for any number of characters. So, the above query should retrieve rows where the USER_NAME is something like "charles","leander","Elena" etc.( that contains "le")
    I am getting the error:
    SQLException: java.sql.SQLException: ORA-01006: bind variable does not exist
    I changed the query to
    PreparedStatement pstmt = null;
    pstmt = c.prepareStatement("select * from users where USER_NAME like '% " + username1 + "%'");
         //pstmt.setString(1, username1);
         pstmt.executeQuery();
    This time , it is not giving the error and retrieving properly.
    But I want to use the original query and use the "pstmt.setString(1, username1); " . Is there any way of achieving this?
    Please help.
    Cheers,
    charles_am

    hi,
    try this...
    String username1="%le%";
    pstmt = c.prepareStatement("select * from users where USER_NAME like ?")
    pstmt.setString(1,username1);
    cheers,
    rpk

  • Single sql query-please help

    Hi experts,
    what i want to do is write a single query which will show whether a employee
    exits in the company or not.I have two tables emp and dept.There are as follows.
    SQL> select * from emp;
    NAME DEPTNO EMPNO
    xxx 10 33036
    YYY 12 2345
    ZZZ 13 678
    KKK 14 5678
    RRR 15 7865
    SQL> select * from dept;
    DEPTNO LOCATION
    10 AAA
    11 BBB
    12 CCC
    13 DDD
    what i want is it will select records from the emp table and find whether corrosponding
    deptno really exists in the dept table.If the value is found in deptno column the dept table then it will set the value
    Y other wise it will be N and all i have to do with the help of a single query.
    expected result
    name empno exists
    xxx 33036 Y
    YYY 2345 Y
    ZZZ 678 Y
    KKK 5678 N
    RRR 7865 N
    Please help.
    Regards
    Rajat

    SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM    DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N') EXIST
    FROM EMP
    ORDER BY 1
    Demo
    SQL> WITH EMP AS(
      2  SELECT 'XXX' NAME , 10 DEPTNO ,33036  EMPNO FROM DUAL UNION
      3  SELECT 'YYY', 12, 2345 FROM DUAL UNION
      4  SELECT 'ZZZ', 13 ,678 FROM DUAL UNION
      5  SELECT 'KKK', 14 ,5678 FROM DUAL UNION
      6  SELECT 'RRR', 15 ,7865 FROM DUAL  ),
      7  DEPT AS(
      8  SELECT 10  DEPTNO,'AAA' DNAME FROM DUAL UNION
      9  SELECT 11 ,'BBB' FROM DUAL UNION
    10  SELECT 12 ,'CCC' FROM DUAL UNION
    11  SELECT 13 ,'DDD'FROM DUAL )
    12  SELECT EMPNO, NAME , EMPNO , NVL( ( SELECT 'Y' FROM    DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO),'N')
    EXIST
    13  FROM EMP
    14  ORDER BY 1
    15  /
         EMPNO NAM      EMPNO E
           678 ZZZ        678 Y
          2345 YYY       2345 Y
          5678 KKK       5678 N
          7865 RRR       7865 N
         33036 XXX      33036 Y
    SQL> Edited by: Salim Chelabi on Dec 7, 2008 4:15 AM

  • Query--please help

    Hello Forum Members,
    Can you please help me out:
    SQL> select * from quarter_test4;
    QUARTER CONFIG REP_DATE
    Q1-2007 10 12-JAN-07
    Q2-2007 10 21-APR-07
    Q3-2007 870 14-AUG-07
    Q4-2007 50 15-NOV-07
    Q1-2008 60 02-JAN-09
    Q4-2006 160 02-DEC-06
    I want the following out put:
    Please note that the future quarters should have current quarter sum(config).Please note that The current table
    does not hold future quarters.I have to genarate query on which a report is based.
    My Query:
    SELECT quarter,
    CASE
    WHEN qtr > TRUNC(SYSDATE, 'q')
    THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
    ELSE sum_config
    END sum_config
    FROM (SELECT qtr, q.qtrstr quarter, SUM(qt.config) sum_config
    FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
    FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
    FROM DUAL
    CONNECT BY LEVEL <= 9)
    ORDER BY qtr) q,
    quarter_test4 qt
    WHERE qt.quarter(+) = q.qtrstr
    GROUP BY qtr, q.qtrstr)
    ORDER BY qtr;
    Correct Output Generated:
    QUARTER SUM_CONFIG
    Q4-2006 160
    Q1-2007 10
    Q2-2007 10
    Q3-2007 870
    Q4-2007 50
    Q1-2008 60
    Q2-2008 60
    Q3-2008 60
    Q4-2008 60
    ====================================================================================================================================
    New Requirement:Product column has been added.
    SQL> select * from quarter_test3;
    QUARTER CONFIG REP_DATE PRODUCT
    Q1-2007 10 12-JAN-07 P1
    Q2-2007 10 21-APR-07 P1
    Q3-2007 870 14-AUG-07 P1
    Q4-2007 50 15-NOV-07 P1
    Q1-2008 60 02-JAN-09 P1
    Q4-2006 160 02-DEC-06 P1
    Q4-2006 997 02-DEC-06 P2
    Q4-2007 60 14-NOV-07 P2
    Q3-2007 970 14-NOV-07 P2
    Q2-2007 20 21-APR-07 P2
    Q1-2007 20 12-JAN-07 P2
    QUARTER CONFIG REP_DATE PRODUCT
    Q1-2008 70 12-JAN-08 P2
    Expected Output:
    Q4-2006 160 P1
    Q1-2007 10 P1
    Q2-2007 10 P1
    Q3-2007 870 P1
    Q4-2007 50 P1
    Q1-2008 60 P1
    Q2-2008 60 P1
    Q3-2008 60 P1
    Q4-2008 60 P1
    Q4-2006 260 P2
    Q1-2007 20 P2
    Q2-2007 20 P2
    Q3-2007 970 P2
    Q4-2007 60 P2
    Q1-2008 70 P2
    Q2-2008 70 P2
    Q3-2008 70 P2
    Q4-2008 70 P2
    My Query:
    SELECT quarter,product,
    CASE
    WHEN qtr > TRUNC(SYSDATE, 'q')
    THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
    ELSE sum_config
    END sum_config
    FROM (SELECT qtr, q.qtrstr quarter,product, SUM(qt.config) sum_config
    FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
    FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
    FROM DUAL
    CONNECT BY LEVEL <= 9)
    ORDER BY qtr) q,
    quarter_test3 qt
    WHERE qt.quarter(+) = q.qtrstr
    GROUP BY qtr,product, q.qtrstr)
    ORDER BY substr(qtr,-4),substr(QTR,2,1)
    Output:
    QUARTER PRODUCT SUM_CONFIG
    Q4-2006 P1 160
    Q4-2006 P2 997
    Q4-2007 P1 50
    Q4-2007 P2 60
    Q4-2008 70
    Q2-2007 P1 10
    Q2-2007 P2 20
    Q2-2008 70
    Q3-2007 P1 870
    Q3-2007 P2 970
    Q3-2008 70
    QUARTER PRODUCT SUM_CONFIG
    Q1-2007 P1 10
    Q1-2007 P2 20
    Q1-2008 P1 70
    Q1-2008 P2 70
    The query had not generated q2-2008,q3-2008,q4-2008 values [60]for P1...it had only generated q2-2008,q3-2008,q4-2008 values[70] for product P2.
    Can you please advise me.

    You can make up the data using the model clause:
    SQL> create table quarter_test3 (quarter, config, product)
      2  as
      3  select 'Q1-2007', 10, 'P1' from dual union all
      4  select 'Q2-2007', 10, 'P1' from dual union all
      5  select 'Q3-2007', 870, 'P1' from dual union all
      6  select 'Q4-2007', 50, 'P1' from dual union all
      7  select 'Q1-2008', 60, 'P1' from dual union all
      8  select 'Q4-2006', 160, 'P1' from dual union all
      9  select 'Q4-2006', 997, 'P2' from dual union all
    10  select 'Q1-2007', 60, 'P2' from dual union all
    11  select 'Q2-2007', 970, 'P2' from dual union all
    12  select 'Q3-2007', 20, 'P2' from dual union all
    13  select 'Q4-2007', 20, 'P2' from dual union all
    14  select 'Q1-2008', 70, 'P2' from dual
    15  /
    Tabel is aangemaakt.
    SQL> select 'Q' || to_char(mod(q,4) + 1) || '-' || to_char(trunc(q/4)) quarter
      2       , config
      3       , product
      4    from quarter_test3
      5   model
      6         partition by (product)
      7         dimension by (to_number(substr(quarter,4))*4 + to_number(substr(quarter,2,1)) - 1 q)
      8         measures (config)
      9         rules
    10         ( config[for q from 2006*4 + 3 to 2008*4 + 3 increment 1]
    11           = nvl(config[cv()],config[cv()-1])
    12         )
    13   order by product
    14       , q
    15  /
    QUARTER                                                                                CONFIG PR
    Q4-2006                                                                                   160 P1
    Q1-2007                                                                                    10 P1
    Q2-2007                                                                                    10 P1
    Q3-2007                                                                                   870 P1
    Q4-2007                                                                                    50 P1
    Q1-2008                                                                                    60 P1
    Q2-2008                                                                                    60 P1
    Q3-2008                                                                                    60 P1
    Q4-2008                                                                                    60 P1
    Q4-2006                                                                                   997 P2
    Q1-2007                                                                                    60 P2
    Q2-2007                                                                                   970 P2
    Q3-2007                                                                                    20 P2
    Q4-2007                                                                                    20 P2
    Q1-2008                                                                                    70 P2
    Q2-2008                                                                                    70 P2
    Q3-2008                                                                                    70 P2
    Q4-2008                                                                                    70 P2
    18 rijen zijn geselecteerd.Regards,
    Rob.

  • Error 500--Internal Server Error.PLEASE   HELP .

    hi,
    I am using BEA weblogic server 9.0.i created a new domain named myproject.I have created directory mywebapp under applications dir.
    i.e C:\bea\user_projects\domains\myproject\applications\mywebapp
    I have placed my servlet class in :
    C:\bea\user_projects\domains\myproject\applications\mywebapp\WEB-INF\classes\Mypackage
    I deployed my apllication mywebapp using admin console.
    when i run the program in the browser,i get this error:
    Error 500--Internal Server Error
    javax.servlet.ServletException: [HTTP:101249][weblogic.servlet.internal.WebAppServletContext@17e5fde - name: 'mywebapp', context-path: '/mywebapp']: Servlet class HelloServlet for servlet myHello could not be loaded because the requested class was not found in the classpath C:\bea\user_projects\domains\myproject\applications\mywebapp\WEB-INF\classes.
    java.lang.ClassNotFoundException: HelloServlet.
         at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:497)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:234)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:2970)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1888)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1810)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1274)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:167)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:139)
    what should i do?please help me.
    bye

    you are reason our error is slightly different is
    Error 500--Internal Server Error
    javax.servlet.ServletException: [HTTP:101249][ServletContext(id=21255917,name=BonusRoot,context-path=/BonusRoot)]: Servlet class Beans.BonusServlet for servlet BonusServlet could not be loaded because the requested class was not found in the classpath C:\bea\weblogic81\samples\domains\workshop\cgServer\.wlnotdelete\essai\war-ic.war.
    java.lang.ClassNotFoundException: Beans.BonusServlet.
         at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:799)
         at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:518)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:362)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
         at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
    We have try with your proposition but we find the same error
    we must request servlet??? because i've one
    package Beans;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import javax.naming.*;
    import javax.rmi.PortableRemoteObject;
    public class BonusServlet extends HttpServlet {
      CalcHome homecalc;
      public void init(ServletConfig config) throws ServletException{
    //Look up home interface
       try {
         InitialContext ctx = new InitialContext();
         Object objref = ctx.lookup("calcs");
         homecalc = (CalcHome)PortableRemoteObject.narrow(objref, CalcHome.class);
       } catch (Exception NamingException) {
         NamingException.printStackTrace();
      public void doGet (HttpServletRequest request,
         HttpServletResponse response)
         throws ServletException, IOException
        String socsec = null;
        int multiplier = 0;
        double calc = 0.0;
        PrintWriter out;
        response.setContentType("text/html");
        String title = "EJB Example";
        out = response.getWriter();
        out.println("<HTML><HEAD><TITLE>");
        out.println(title);
        out.println("</TITLE></HEAD><BODY>");
        try{
        Calc theCalculation;
    //Retrieve Bonus and Social Security Information
       String strMult =
               request.getParameter("MULTIPLIER");
       Integer integerMult = new Integer(strMult);
       multiplier = integerMult.intValue();
       socsec = request.getParameter("SOCSEC");
    //Calculate bonus
        double bonus = 100.00;
        theCalculation = homecalc.create();
        calc = theCalculation.calcBonus(multiplier, bonus);
        }catch(Exception CreateException){
           CreateException.printStackTrace();
    //Display Data
        out.println("<H1>Bonus Calculation</H1>");
        out.println("<P>Soc Sec: " + socsec + "<P>");
        out.println("<P>Multiplier: " + multiplier + "<P>");
        out.println("<P>Bonus Amount: " + calc + "<P>");
        out.println("</BODY></HTML>");
        out.close();
      public void destroy() {
        System.out.println("Destroy");
    }Help us please
    Thanks

  • NOKIA N80 Internal Error Message PLEASE HELP

    Does anbody Know why I Get an Internal Error Message When I Send a Multimedia Message.... Everytime I Try to Send a Picture as Multimedia it Says Unable to Send Message and When I Click Details it Says Internal Error....... Please Help

    -----
    I thought maybe it was the site itself. Then I tried it with another site and the same problem
    well, thanks for that info -- considering this I can´t help suspecting that your ADDT (or Dreamweaver) installation might be broken. For a start I suggest to uninstall/reinstall ADDT first and see if this solves your issues
    Cheers,
    Günter Schenk
    Adobe Community Expert, Dreamweaver

Maybe you are looking for

  • Creating Variants in MIGO to block tree display in item overview

    Hi, I would like to know how to create Screen Variants in MIGO to hide the Tree display from the Item overview block. Also I wish to know how to set this variant as default settings. Because of this, user will not be able to even view the the sub-par

  • Install SQL Server 2014 in Windows Server 2012 R2

    Hi, I had install a Windows server 2012 R2 Standard version in my VM and i make it as my domain server as well. I had create another account "ABC" and login with this new created account "ABC" in the same machine to install SQL server 2014, it give m

  • Dynamic table name in select statment

    hai, Please help me.... oracle 9i i am using. i have four tables abc_121, abc_122, abc_123, abc_124. i want to pick records from a table.table name should be prepared dynamically. i.e., i want to pick records from a quarter table of this year.(ex: ab

  • BPM Process won't start

    Hi, I'm trying to start a process via the process repository, but keep getting the message "Problem occured fulfilling the request. Log entries created with ID: 00199921BE7E0C7C00000000000040DC" - when I look at the log via NWA I can only see the "Nu

  • Sorting a datatable with a boolean value

    Hi all, I have a datatable and one of the columns is just a true or false field. I'm using the DTOComparator from the BalusC (here: http://balusc.xs4all.nl/srv/dev-jep-dat.html) server but I'm getting the error: Error 500: java.lang.RuntimeException: