How to write named query if we want to use IN syntax in our sql statement?

I cannot find a suitable category about named query, so please move to appropriate place if there is any.
When we write named query, below statement is fine.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field1 = :input1");             q2.setParameter("input1", "value1");
Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)");             q2.setParameter("input1", "3633, 3644");
Can anyone suggest? Thanks.

roamer wrote:
Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)");
q2.setParameter("input1", "3633, 3644");
Can anyone suggest?The above is in your code right? Not in some configuration file?
Then you do it the same way as with regular jdbc/sql.
1. You start with a collection of values - call it collection A.
1. Create a for loop that dynamically creates the string using 'bind' variables (whatever you want to call the 'colon' entity in the above).
2. Call the createQuery method using the string that was created
3. Create a second loop that iterates over A and populates with setParameter.
Pseudo code
        Object[] A = ...
        String sql = "SELECT o FROM Table1 as o WHERE field2 IN (";
        for (int i=1; i <= A.length; i++)
              if (i == 1)
                 sql += ":input" + i;
             else
                 sql += ",:input" + i;
        sql += ")";
        Query q2 = em.createQuery(sql);
        for (int i=1; i <= A.length; i++
              q2.setParameter("input" + i, A[i-1]);
              }By the way there is a jdbc forum.

Similar Messages

  • 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 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 a Query a table and the return result is the column name

    Hi All
    Pls advise how to write a query whereas the return result is the
    column name.
    I know there is describe <table_name>;
    Is there any other ways?
    Pls advise
    Tj
    Edited by: user600866 on Oct 14, 2008 12:13 AM

    Data Dictionary table user_tab_columns has all the column names. You can query that and get what ever you want.
    To get the column list of a table just query
    select *
      from user_tab_columns     
    where table_name = <your_table>Edited by: Karthick_Arp on Oct 14, 2008 12:18 AM

  • How to write a query?

    Hi all,
    Can you please explain me how to write a query joining tables in SAP ?
    Thanks,
    Avani.

    Hi
    Check info from sdn only
    User T-code: SQVI
    Enter your "query name" and press"create"
    Enter title
    In Data source " select Table join"
    select basis mode and press continue.
    Press Insert table and give the tabes one by one.
    Drag the parameter and drop in another table to establish link and link all the tables.
    Press check to check whether your link is correct, then press back
    You will be able to see the tables and fields on left hand side.
    Select the appropriate parameters for selection fields and list fields
    Selection fields- For selection of data, the initial screen of report.
    List fields are nothing but output.
    Execute the report.
    You will find the initial screen of report.
    Give your parameters for output and execute again.
    You will receive the desired output.
    You can down load the output in spread sheet/ in the format desired.
    At last save your query before coming out of transaction
    Vishal...

  • I want to use jdbc to connect MS SQL SERVER

    hi,
    I want to use jdbc to connect MS SQL SERVER,not the jdbc-odbc bridge.
    I download the driver from MS,deploy it,but when I connect the database such as:
    <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");%>
    <%String sConnStr="jdbc:microsoft:sqlserver://computer2000:1433";%>
    <%Connection conn=DriverManager.getConnection(sConnStr,"sa","123");%>
    <%Statement stmt=conn.createStatement();%>
    but it said
    javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
    java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
    how can i work out this problem
    maybe my configure is wrong,please give me a successful sample configuration
    thanks a lot

    Hi,
    I am not sure where you have got the following code from
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    What happens here, is Java Runtime will search for the Class named:
    com.microsoft.jdbc.sqlserver.SQLServerDriver
    If this Class is not in the Runtime Classpath, it will throw the Error that you have got. Kindly get the proper driver as well as ensure that the Class is available in the Runtime Classpath.
    Thanks and regards,
    Pazhanikanthan. P

  • How to write a query for the given scenario ?

    Hi All ,
    I am having two tables EMP, DEPT with the below data.
    EMP TABLE :--
    EID     ENAME     JOB     SAL     DEPID
    111     RAM     MANAGER     1500     10
    222     SAM     ASST MANAGER     2000     20
    333     KALA     CLERK     2500     10
    444     BIMA     MANAGER     3000     20
    555     CHALA     MANAGER     3500     30
    666     RANI     ASST MANAGER     4000     10
    777     KAMAL     MANAGER     2400     10
    DEPT TABLE :--
    DEPID     DNAME
    10     XX
    20     YY
    30     ZZ
    Q1 : I want the sum of salary of each department and for the particular job . Here in each departmant manager, asst. manager, clerk posts are there .
    I want to display the result like below ....
    JOB     10     20     30
    MANAGER     3900     3000     3500
    ASST MANAGER 4000     2000     NULL
    CLERK     2500     NULL     NULL
    please tell me how to write a sql query ?
    Thanks
    Sai

    In general case, you cannot write this query.
    This is one of the limits of relational database concepts. The number of columns must be known up-front. In the SELECT clause, you have to list and name all columns returned by the query. So you have to know number of departments. (There are some workarounds - you can return one column with concatenated values for all departments, separated by space character).
    If you know that you have 3 departments then you qurey will return 4 columns:
    SELECT
       e.job,
       SUM ( CASE WHEN d.deptid = 10 THEN e.sal ELSE NULL END) d10,
       SUM ( CASE WHEN d.deptid = 20 THEN e.sal ELSE NULL END) d20,
       SUM ( CASE WHEN d.deptid = 30 THEN e.sal ELSE NULL END) d30
    FROM dept d, emp e
    WHERE d.deptno = e.deptno
    GROUP BY e.job

  • How to write a query for grouping them the columns and give the sequence order to each group/

    Hi i have table that contains country columns .
    India,USA,UK like these when ever the group changed into the differt country i make a group and arrange them the sequence into those Countries
    like below
    1)India
    2)India
    1)USA
    2)USA
    like these to write a query ..........pls help me for this query

    Assuming you're using SQL Server you can ask here:
    http://www.sqlteam.com/forums/forum.asp?FORUM_ID=23
    Otherwise, please ask in the relevant forum for the type of technology you're using.
    Basically it's either:
    select *
    from [table name]
    order by country
    If you want to do something with groups do something like:
    select (max) income, country
    from [table name]
    group by country
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • How  to write select query for this

    Hi,
    I had a html form and in the for i had drop down box and it needs to select multiple values from the drop down box. When i select multiple values then i have to write the SQL select statement  query .
    When i try to write the select statement and trying to run i am getting error.
    select * from Table
    where emo_no = '1,2,3'
    this is how i write query please suggest me how  to write query for selecting multiple values from the drop down box.
    Thanks

    select * from Table
    where emo_no in ( 1,2,3)
    for integer values
    select * from Table
    where emo_no in ('1','2','3')
    for characters
    If we talk about large scale applications that may have millions of records, I would suggest this.
    declare @t table (v int)
    insert into t (v) values (1)
    insert into t (v) valves (2)
    insert into t (v) values (3)
    select *
    from table
         inner join @t t on table.emo_no = t.v
    Using "in" for a where clause is not so bad for filtering on a few values, but if you are filtering a lot of rows and a lot of values (emo_no) the performance degrades quickly for some reasons beyond the scope of this.
    This is just one solution, I'll through this out as well, instead of an in memory (@t) table, doing a disk based temp table (#t) and creating an index on the column "v".
    create table #t (v int)
    insert into #t (v) values (1)
    insert into #t (v) valves (2)
    insert into #t (v) values (3)
    create index ix_t on #t (v)
    select *
    from table
         inner join #t t on table.emo_no = t.v
    drop table #t
    Pardon any syntax errors and careful using a drop statement.
    Sometimes in memory tables work better than disk temp tables, it takes some testing and trial and error depending on your datasets to determine the best solution.
    Probably too much info  ;-)
    Byron Mann
    [email protected]
    [email protected]
    Software Architect
    hosting.com | hostmysite.com
    http://www.hostmysite.com/?utm_source=bb

  • How to write complex query with jpa criteria builder.

    Hello,
    I want to write a query in jpa criteriaquery. Here is the query:
    SELECT node.category_name, (COUNT(parent.category_name) - 1) AS depth
    FROM category_subcategories AS node,
    category_subcategories AS parent
    WHERE node.lft BETWEEN parent.lft AND parent.rgt
    AND node.category_name = 'PORTABLE ELECTRONICS'
    GROUP BY node.category_name
    ORDER BY node.lft
    Here is the code I come up with:
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<CategorySubcategories> cq = cb.createQuery( CategorySubcategories.class );
    Root<CategorySubcategories> node = cq.from( CategorySubcategories.class );
    Root<CategorySubcategories> parent = cq.from( CategorySubcategories.class );
    Predicate p1 = cb.equal(node.get("categoryName"), categoryName);
    Predicate p2 = cb.between(node.get("lft").as(Integer.class), parent.get("lft").as(Integer.class), parent.get("rgt").as(Integer.class));
    Order nodeLft = cb.asc(node.get("lft"));
    cq.multiselect(node.get("categoryName"), cb.count(parent.get("categoryName")))
    .where(p1, p2)
    .groupBy(node.get("categoryName"))
    .orderBy(nodeLft);
    return em.createQuery(cq).getResultList();
    When I execue the test, it shown the following error:
    Testcase: testDepthOfSubtree(au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeTest): Caused an ERROR
    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1201)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:324)
    at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:227)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
    at au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeMock.findDepthOfSubtreeBy_categoryName(CategorySubcategoriesFacadeMock.java:228)
    at au.com.houseware.server.ejb.entity.facade.CategorySubcategoriesFacadeTest.testDepthOfSubtree(CategorySubcategoriesFacadeTest.java:44)
    Caused by: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [au.com.houseware.server.ejb.entity.CategorySubcategories] [select new au.com.houseware.server.ejb.entity.CategorySubcategories(generatedAlias0.categoryName, count(generatedAlias1.categoryName)) from au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias0, au.com.houseware.server.ejb.entity.CategorySubcategories as generatedAlias1 where ( generatedAlias0.categoryName=:param0 ) and ( generatedAlias0.lft between generatedAlias1.lft and generatedAlias1.rgt ) group by generatedAlias0.categoryName]
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
    at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
    at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:261)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:306)
    What is wrong with my criteriaQuery?
    Any suggestion is very much appreciated.
    Thanks
    Sam
    Edited by: 785102 on Mar 26, 2011 7:44 PM

    Hello,
    Thank you for your response.
    If I remove CategorySubcateogires, netbeans complained:
    incompatible types
    required: javax.persistence.criteria.CriteriaQuery<au.com.houseware.server.ejb.entity.CategorySubcategories>
    found: javax.persistence.criteria.CriteriaQuery<java.lang.Object>
    When I removed all CategorySubcategories type and replaced it with Object like this:
    public Collection<Object> findDepthOfSubtreeBy_categoryName(String categoryName) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object> c = cb.createQuery();
    Root<CategorySubcategories> node = c.from( CategorySubcategories.class );
    Root<CategorySubcategories> parent = c.from( CategorySubcategories.class );
    Predicate p1 = cb.equal(node.get("categoryName"), categoryName);
    Order nodeLft = cb.asc(node.get("lft"));
    c.multiselect(node.get("categoryName"), cb.count(parent.get("categoryName")))
    .where(p1)
    .groupBy(node.get("categoryName"))
    .orderBy(nodeLft);
    return em.createQuery(c).getResultList();
    test main():
    Collection<Object> list = ccFacade.findDepthOfSubtreeBy_categoryName("Houseware");
    for (Iterator<Object> iter = list.iterator(); iter.hasNext();) {
    CategorySubcategories cc = (CategorySubcategories) iter.next();
    System.out.println(" name : "+cc.getCategoryName());
    On execution, it thrown exception:
    [Ljava.lang.Object; cannot be cast to au.com.houseware.server.ejb.entity.CategorySubcategories
    Thanks a lot
    Sam                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How  to write  a  query  for this output

    I have a string ' if i know good acting , I am a hero '
    now if 'hero' is present in the string it will return ' i am hero' else
    'you are hero'
    How to write a sql query to return the same .

    SQL> select (case
    2 when '&a' like '%hero%' then 'I am hero'
    3 ELSE 'u r hero'
    4 end) output from dual;
    Enter value for a: if i know good acting , I am a hero
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'if i know good acting , I am a hero ' like '%hero%' then 'I am hero'
    OUTPUT
    I am hero
    SQL> /
    Enter value for a: jkhkh
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'jkhkh' like '%hero%' then 'I am hero'
    OUTPUT
    u r hero
    Hope this helps.

  • How to write a query for this data??

    In this table i have column dob which is DATE type,for example 12-jan-89 I want output like this
       Year              Day
    12-jan-89         Thusrs_day
    12-jan-90          Friday
    upto
    12-jan-14        sunday

    krishnagopi wrote:
    No not like that ,I want up to 2014 year
    Ok, so lets say you have table like this
    SQL> create table my_table(dob date);
    Table created.
    SQL> insert into my_table (dob) values( to_date('12-jan-1989', 'dd-mon-yyyy'));
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from my_table;
    DOB
    12-JAN-89
    You can write a query like this
    select dob + (level -1) dob
          , to_char(dob + (level -1), 'fmDay') day_
       from my_table
    connect
         by level <= (dob + interval '25' year) - dob + 1;

  • How to write a Query for the mentioned scenario.

    Hi All,
    Table A
    ID|| Start_Date||End_date||Rate
    1||01-Jan-2011||31-Mar-2011||0.8
    1||01-Apr-2011||31-Jun-2011||0.9
    I have a table like above. I want to write a query to display the result as below.
    ID|| Start_Date||Rate
    1||01-Jan-2011||0.8
    1||01-Feb-2011||0.8
    1||01-Mar-2011||0.8
    1||01-Apr-2011||0.9
    1||01-May-2011||0.9
    1||01-Jun-2011||0.9
    Kindly help.
    Thanks!
    GJ

    Try to read link mentioned by SB. It will make you more interactive to share your problems. And immediate reply too from experts.
    Check your solution below.
    SQL> ed
    Wrote file afiedt.buf
      1  WITH data1 AS
      2  (
      3  SELECT 1 id, TO_DATE('01-Jan-2011' , 'DD-Mon-YYYY') stdt,TO_DATE('31-Mar-2011' , 'DD-Mon-YYYY') endt, 0.8 rate FROM dual
      4  UNION ALL
      5  SELECT 1 id, TO_DATE('01-Apr-2011' , 'DD-Mon-YYYY') stdt,TO_DATE('30-Jun-2011' , 'DD-Mon-YYYY') endt, 0.9 rate FROM dual
      6  )
      7  SELECT id, ADD_MONTHS(stdt, level -1) st_dt, rate FROM data1
      8  CONNECT BY  level <= ROUND(MONTHS_BETWEEN(endt,stdt))
      9  AND rate= prior rate  /* stick to current line */
    10* AND prior sys_guid() IS NOT NULL  /* used to terminate the connect by loop */
    SQL> /
            ID ST_DT           RATE
             1 01-JAN-11         .8
             1 01-FEB-11         .8
             1 01-MAR-11         .8
             1 01-APR-11         .9
             1 01-MAY-11         .9
             1 01-JUN-11         .9
    6 rows selected.Thanks!
    Ashutosh
    Edited by: Ashu_Neo on Oct 8, 2012 11:57 AM

  • How to write the query using Index

    Hi All,
    I have to fetch the records from Database table using Index, how can i write the query using Index. Can any body plz send me the sample code.
    Help Me,
    Balu.

    Hi,
    See the below Example.
    select * from vbak up to 100 rows
    into table t_vbak
    where vbeln > v_vbeln.
    sort t_vbak by vbeln descending.
    read table t_vbak index 1.
    Regards,
    Ram
    Pls reward points if helpful.

  • How to write select query for all the user tables in database

    Can any one tell me how to select the columns from all the user tables in a database
    Here I had 3columns as input...
    1.phone no
    2.memberid
    3.sub no.
    I have to select call time,record,agn from all the tables in a database...all database tables have the same column names but some may have additional columns..
    Eg: select call time, record,agn from ah_t_table where phone no= 6186759765,memberid=j34563298
    Query has to execute not only for this table but for all user tables in the database..all tables will start with ah_t
    I am trying for this query since 30days...
    Help me please....any kind of help is appreciated.....

    Hi,
    user13113704 wrote:
    ... i need to include the symbol (') for the numbers(values) to get selected..
    eg: phone no= '6284056879'To include a single-quote in a string literal, use 2 or them in a row, as shown below.
    Starting in Oracle 10, you can also use Q-notation:
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements003.htm#i42617
    ...and also can you tell me how to execute the output of this script. What front end are you using? If it's SQL*Plus, then you can SPOOL the query to a file, and then execute that file, like this:
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    -- Run preliminary query to generate main query
    SPOOL     c:\my_sql_dir\all_ah_t.sql
    SELECT       'select call time, record, agn from '
    ||       owner
    ||       '.'
    ||       table_name
    ||       ' where phone_no = ''6186759765'' and memberid = j34563298'
    ||       CASE
               WHEN ROW_NUMBER () OVER ( ORDER BY  owner          DESC
                              ,        table_name      DESC
                              ) = 1
               THEN  ';'
               ELSE  ' UNION ALL'
           END     AS txt
    FROM       all_tables
    WHERE       SUBSTR (table_name, 1, 4)     = 'AH_T'
    ORDER BY  owner
    ,       table_name
    SPOOL     OFF
    -- Restore SQL*Plus features that interfere with raw output (if desired)
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    -- Run main query:
    @c:\my_sql_dir\all_ah_t.sql
    so that i form a temporary view for this script as a table(or store the result in a temp table) and my problem will be solved..Sorry, I don't understand. What is a "temporary view"?

Maybe you are looking for

  • Search not working properly in Artist or Genre tabs?

    Hi - I upgraded to iTunes 11.1.1 on Mountain Lion (MacBook from about the end of 2010, beginning of 2011) a day or two ago from the app store, and I've just discovered a problem I can't find a solution to. When in the Artist or Genre tabs and using t

  • Syncing iPod - please help

    When syncing my iPod I get the following message ..... Songs on the iPod "User's iPod" cannot be synced because all of the playlistst selected for syncing no longer exist. I've reset my iPod & reinstalled iTunes, but I still get the message. I guess

  • Recently my default program for opening any program changed to opening a safari browser for Dropbox. How do I set it back to iBooks?

    On both my iPad (which had Dropbox) and my wife's (which does not) any file we click to open the current default is to open a safari browser and attempt to sign into Dropbox. I want to restore iBooks as my default but can't find any info on how. Any

  • FM to create a new item in Purchase Order

    Hi Experts, I am using BAPI_PO_CREATE to create PO's from frontend. Now I want to create a new item in same PO which i have created earlier, the way we can do in me21n. I think i cant do this through BAPI_PO_CREATE FM. Can anybody pls help me regardi

  • National Language Support

    Hi all, I use JDeveloper3.2 and Oracle 8.1.7 with ZHS16CGB character set.Hit errors while compile the application,it said 'This version of JDK does not support GBK character set',what does it mean? Any boday have experience for multibytes characters