Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field

Hello,
I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
Table structures are mentioned below:
OP:
Name                             Null                    Type        
OP_NBR                    NOT NULL      NUMBER(4)    (Primary Key)
OP_DESC                                        VARCHAR2(50)
OP_PAYLOD_XML                           CLOB       
GM:
Name                          Null                   Type        
GM_NBR                  NOT NULL       NUMBER(4)    (Primary Key)
GM_DESC                                       VARCHAR2(40)
OP_NBR               NOT NULL          NUMBER(4)    (Foreign Key)
GM_PAYLOD_XML                          CLOB   
DM:
Name                          Null                    Type        
DM_NBR                  NOT NULL         NUMBER(4)    (Primary Key)
DM_DESC                                         VARCHAR2(40)
GM_NBR                  NOT NULL         NUMBER(4)    (Foreign Key)
DM_PAYLOD_XML                            CLOB       
DE:
Name                          Null                    Type        
DE_NBR                     NOT NULL           NUMBER(4)    (Primary Key)
DE_DESC                   NOT NULL           VARCHAR2(40)
DM_NBR                    NOT NULL           NUMBER(4)    (Foreign Key)
DE_PAYLOD_XML                                CLOB    
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SELECT
j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
FROM
DE g, DM h, GM i, OP j
WHERE
h.dm_nbr = g.dm_nbr(+) and
i.gm_nbr = h.gm_nbr(+) and
j.op_nbr = i.op_nbr(+)
+++++++++++++++++++++++++++++++++++++++++++++++++++++
I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
Current O/P:
<resultSet>
     <Record1>
          <OP_PAYLOD_XML1>
          <GM_PAYLOD_XML1>
          <DM_PAYLOD_XML1>
          <DE_PAYLOD_XML1>
     </Record1>
     <Record2>
          <OP_PAYLOD_XML2>
          <GM_PAYLOD_XML2>
          <DM_PAYLOD_XML2>
          <DE_PAYLOD_XML2>
     </Record2>
     <RecordN>
          <OP_PAYLOD_XMLN>
          <GM_PAYLOD_XMLN>
          <DM_PAYLOD_XMLN>
          <DE_PAYLOD_XMLN>
     </RecordN>
</resultSet>
Now i want to change my SQL query so that i get following output structure:
<resultSet>
     <Record>
          <OP_PAYLOD_XML1>
          <GM_PAYLOD_XML1>
          <GM_PAYLOD_XML2> .......
          <GM_PAYLOD_XMLN>
          <DM_PAYLOD_XML1>
          <DM_PAYLOD_XML2> .......
          <DM_PAYLOD_XMLN>
          <DE_PAYLOD_XML1>
          <DE_PAYLOD_XML2> .......
          <DE_PAYLOD_XMLN>
     </Record>
     <Record>
          <OP_PAYLOD_XML2>
          <GM_PAYLOD_XML1'>
          <GM_PAYLOD_XML2'> .......
          <GM_PAYLOD_XMLN'>
          <DM_PAYLOD_XML1'>
          <DM_PAYLOD_XML2'> .......
          <DM_PAYLOD_XMLN'>
          <DE_PAYLOD_XML1'>
          <DE_PAYLOD_XML2'> .......
          <DE_PAYLOD_XMLN'>
     </Record>
<resultSet>
Appreciate your help in this regard!

Hi,
A few questions :
How's your first query supposed to give you an XML output like you show ?
Is there something you're not telling us?
What's the content of, for example, <OP_PAYLOD_XML1> ?
I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
What's the db version BTW?

Similar Messages

  • Fetch last record from database table

    hi,
    how to fetch last record from database table.
    plz reply earliest.
    Regards,
    Jyotsna
    Moderator message - Please search before asking - post locked
    Edited by: Rob Burbank on Dec 11, 2009 9:44 AM

    abhi,
    just imagine the table to be BSEG or FAGLFLEXA... then what would be performance of the code ?
    any ways,
    jyotsna, first check if you have a pattern to follow like if the primary key field have a increasing number range or it would be great if you find a date field which stores the inserted date or some thing..
    you can select max or that field or order by descending using select single.
    or get all data.. sort in descending order.(again you need some criteria like date).
    read the first entry. using read itab index 1

  • Need help in writing a select query to pull required data from 3 tables.

    Hi,
    I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.
    The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider
    the role from EmpRoles .
    Sample Script:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1),(2),(3)
    Insert into #EmpRoles values (1,'Role1'),(2,'Role1'),(2,'Role2'),(3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for
    remaining ID's need to fetch from EmpRoles .
    My Final Output of select query should be like below.
    EmpID Role
    1 Role1
    2 Role2
    3 Role1
    Please help.
    Mohan

    Mohan,
    Can you check if this answers your requirement:
    Create Table #EmpIDs
    (EmplID int )
    Create Table #EmpRoles
    (EMPID int,Designation varchar(50))
    Create Table #LatestRoles
    EmpID int,
    Designation varchar(50)
    Insert into #EmpIDs values (1)
    Insert into #EmpIDs values (2)
    Insert into #EmpIDs values (3)
    Insert into #EmpRoles values (1,'Role1')
    Insert into #EmpRoles values (2,'Role2')
    Insert into #EmpRoles values (2,'Role1')
    Insert into #EmpRoles values (3,'Role1')
    Insert into #LatestRoles values (2,'Role2')
    --Method 1
    select e.EmplID,MIN(ISNULL(l.Designation,r.Designation)) as Designation
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    left join #latestRoles l on e.emplID=l.EmpID
    group by e.EmplID
    --Method 2
    ;with cte
    as
    select distinct e.EmplID,r.Designation,count(*) over(partition by e.emplID) cnt
    from #empids e
    left join #emproles r on e.emplID=r.EmpID
    select emplID,Designation
    from cte
    where cnt=1
    UNION ALL
    select a.EmplID,l.Designation
    from
    (select distinct EmplID from cte where cnt>1) a
    join #Latestroles l on a.EmplID=l.EmpID
    order by emplID
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • Need help for top n query

    Hi,
    I want to show top 3 salary records from emp table and I am using below query in oracle * plus. However I am getting an error saying, "FROM keyword not found where expected". I am not getting what mistake I am doing while writing this query. Can someone plz advice?
    Query:
    Select top 3 sal from emp;
    Thanks in advance.

    Hi,
    In Oracle, there is no TOP keyword. The usual way to do a top-N query in Oracle is to use an analytic function, such as RANK:
    WITH     got_r_num     AS
         SELECT     sal
         ,     ename, empno, ...     -- whatever columns you want
         ,     RANK () OVER (ORDER BY sal DESC)    AS r_num
         FROM     scott.emp
    SELECT       sal
    ,       ename, empno, ...     -- if wanted
    ,       r_num                -- if wanted
    FROM       got_r_num
    WHERE       r_num     <= 3
    ORDER BY  sal
    ;Depending on how you want to handle ties, ypu may want to add tie-breaking columns to the end of the analytic ORDER BY clause, and/or use ROW_NUMBER instead of RANK.

  • Sql Except query to Display mismatched records along with Table names

    Hi
    I am using below query to display mismatch records between two tables
    SELECT * FROM table1
    EXCEPT
    SELECT * FROM table2
    UNION
    SELECT * FROM table2
    EXCEPT
    SELECT * FROM table1
    This displays mismatched records like below
    Sunil  1000  india
    Sunil 1500  india
    I would like to display even the table names in the result For ex;
    Sunil  1000  india  Table1
    Sunil 1500  india   Table2
    Can you please help us in this regard.

    cnk_gr's query should work for you. 
    One change that I would make is to use UNION ALL, not UNION.  UNION eliminates duplicate rows, which means SQL has to do additional work (sort the result and then check for duplicates). 
    So if you can have duplicates and don't want them in your result, then you would use UNION.  And if you can have duplicates and you want the duplicates in the result, you would use UNION ALL.  But in cases like this, where you know you cannot have
    duplicates (because column 1 contains 'TABLE1' for every row in the first half and column 1 contains 'TABLE2' for every row returned from the second half of the query), you should always use UNION ALL.  It will be more efficient.
    Tom

  • Issue with fetching a record from IHPA table with PARNR value as condition

    Hi All,
    I am trying to fetch a particular record from IHPA table where i am giving the OBJNR number, PARVW and PARNR as customer no. , But I am not getting any record  but if i will give OBJNR and PARVW it will generate a record with having same PARNR value.
    Example :
    case 1st :-
    when i am passing following values in IHPA table,
    OBJNR  = IE000000000010070910
    PRAVW = BP                 
    PARNR  = 620000562   
    it is not generating any record  
    case 2nd:-
    But if i will pass  
    OBJNR  = IE000000000010070910
    PRAVW = BP
    it will generate a record?(one row) which will include PARNR as same 620000562 along with other value.
    Q1 -  Why it's not generating in case 1st,
    Q2 - How I will resolve this issue ? as i have to link some table as EQUI -
    IHPA -
    VCKUN
    VCNUM ?
          I have written a code for this to join :
         SELECT A~EQUNR
           B~PARVW
           C~CCNUM
           D~CCNUM
           FROM EQUI AS A JOIN IHPA AS B ON AOBJNR = BOBJNR
           INNER JOIN VCKUN AS C ON BPARNR = CKUNNR
           INNER JOIN VCNUM AS D ON CCCNUM = DCCNUM
           APPENDING CORRESPONDING FIELDS OF TABLE IT_OBSO
           WHERE A~EQUNR IN S_EQN.
                 AND PARVW  = 'BP'.
          But it is not generating any record but when i am commenting the PARVW i am getting the mixed record of PARVW as (BP,SP,SH)
    Let me know if any more clarification required.
    Highly appreciate your help
    Thanks & Regards
    Shaw

    Hi Santosh,
    Thanks for your quick response.
    But I am Sorry, I already checked with putting Zero before PARNR.
    The issue is still as it is.
    Thanks
    Shaw

  • How to fetch corresponding records from 2 tables using ADF Toplink & EJB

    Hi,
    I am unable to fetch records from 2 tables, which has a foregin key.Used the custom query in toplink, But the output is the cartition of the first table draged and the first row of the second table.The output required should be in the form of ADF Table. I am able to find the output in JSF data table.
    Two tables:
    Table name:Solutions
    sol_id varchar2(PK)
    sol_name varchar2
    Table name:Solution_details
    sol_id varchar2(FK)
    common_asum_id varchar2(PK)
    common_detail varchar2
    Output Required:
    sol_id,sol_name,common_asum_id,common_detail
    Custom query:
    SELECT * FROM solutions a
    ,solution_details b
    WHERE a.sol_id=b.sol_id

    Hi,
    I am unable to fetch records from 2 tables, which has a foregin key.Used the custom query in toplink, But the output is the cartition of the first table draged and the first row of the second table.The output required should be in the form of ADF Table. I am able to find the output in JSF data table.
    Two tables:
    Table name:Solutions
    sol_id varchar2(PK)
    sol_name varchar2
    Table name:Solution_details
    sol_id varchar2(FK)
    common_asum_id varchar2(PK)
    common_detail varchar2
    Output Required:
    sol_id,sol_name,common_asum_id,common_detail
    Custom query:
    SELECT * FROM solutions a
    ,solution_details b
    WHERE a.sol_id=b.sol_id

  • Need help for SQL Query last 5 mins Records.

    I need the data between the last five minutes from a table which contains Timeid Column and data type is date.
    select sysdate,(sysdate-((mod(extract(minutes from systimestamp),5)+5)/24/60)-((extract(second from systimestamp))/24/60/60)) Start_date,
    (sysdate-((mod(extract(minutes from systimestamp),5))/24/60)-((extract(second from systimestamp))/24/60/60)) End_Date;
    Suppose now the current time is 01:20:00PM then the output should be from
    Current Date & Time Start Date & Time End Date & Time
    10/18/2007 01:20:00 10/18/2007 01:10:01 10/18/2007 01:15:00
    Suppose now the current time is 01:20:01 then the output should be from
    Current Date & Time Start Date & Time End Date & Time
    10/18/2007 01:20:01 10/18/2007 01:15:01 10/18/2007 01:20:00
    The output i am getting where as i need the output shown above.
    Current Date & Time Start Date & Time End Date & Time
    10/18/2007 01:20:01 10/18/2007 01:14:59 10/18/2007 01:19:59

    SQL> select sysdate,
      2       sysdate -
      3           (decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
      4            mod(to_number(to_char(sysdate,'sssss')),300))+300)/(24*60*60 )
      5                     st_time,
      6         sysdate -
      7           decode(mod(to_number(to_char(sysdate,'sssss')),300),0,300,
      8            mod(to_number(to_char(sysdate,'sssss')),300))/(24*60*60 )
      9                         end_time
    10  from dual;
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:39:46 18-oct-2007 16:30:00 18-oct-2007 16:35:00
    SQL> /
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:39:59 18-oct-2007 16:30:00 18-oct-2007 16:35:00
    SQL> /
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:40:00 18-oct-2007 16:30:00 18-oct-2007 16:35:00
    SQL> /
    SYSDATE              ST_TIME              END_TIME
    18-oct-2007 16:40:01 18-oct-2007 16:35:00 18-oct-2007 16:40:00                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Need help for sql statement

    Hi,
    Need help to write sql statement.
    create table t_dt ( dt_start date, dt_end date, amount number);
    insert into t_dt values('1-Jan-10','10-Feb-10',12);
    insert into t_dt values('11-Feb-10','10-Mar-10',10);
    insert into t_dt values('11-Mar-10','20-Apr-10',8);
    insert into t_dt values('21-Apr-10','28-Jun-10',10);
    insert into t_dt values('29-Jun-10','20-Sep-10',10);
    insert into t_dt values('21-Sep-10','10-Oct-10',10);
    insert into t_dt values('11-Oct-10','31-Dec-10',8);
    insert into t_dt values('1-Jan-11','10-Feb-11',8);
    insert into t_dt values('11-Feb-11','10-Mar-11',7);
    insert into t_dt values('11-Mar-11','20-Apr-11',6);
    insert into t_dt values('21-Apr-11','28-Jun-11',6);
    insert into t_dt values('29-Jun-11','20-Sep-11',6);
    insert into t_dt values('21-Sep-11','10-Oct-11',4);
    insert into t_dt values('11-Oct-11','31-Dec-11',8);
    Result should be like below..
    dt_start     dt_end     Amount
    1-Jan-10     10-Feb-10     12
    11-Feb-10     10-Mar-10     10
    11-Mar-10     20-Apr-10     8
    21-Apr-10     10-Oct-10     10
    11-Oct-10     10-Feb-11     8
    11-Feb-11     10-Mar-11     7
    11-Mar-11     20-Sep-11     6
    21-Sep-11     10-Oct-11     4
    11-Oct-11     31-Dec-11     8
    Just to explain the example, take a row with start date as 21-Apr-10 in the above insert statements, since it has the same amount for next two rows (i.e. with start date '29-Jun-10' and '21-Sep-10') these 3 rows should be converted to represent only 1 row in the result and the start date and end date should be changed per the result shown above.
    Thanks.

    Hello
    I think this gives yuo what you need....
    SELECT
        MIN(dt_start),
        MAX(dt_end),
        amount
    FROM
        (   SELECT
                dt_start,
                dt_end,
                MAX(marker) OVER(ORDER BY dt_start) marker,
                amount
            FROM
                    Select
                        dt_start,
                        dt_end,
                        amount,
                        CASE
                            WHEN LAG(amount) OVER(ORDER BY dt_start) <> amount THEN
                                ROW_NUMBER() OVER(ORDER BY dt_start)
                        END marker
                    from t_dt
    GROUP BY
         amount,
         marker
    order by     
         MIN(dt_start)
    MIN(DT_START)        MAX(DT_END)              AMOUNT
    01-JAN-2010 00:00:00 10-FEB-2010 00:00:00         12
    11-FEB-2010 00:00:00 10-MAR-2010 00:00:00         10
    11-MAR-2010 00:00:00 20-APR-2010 00:00:00          8
    21-APR-2010 00:00:00 10-OCT-2010 00:00:00         10
    11-OCT-2010 00:00:00 10-FEB-2011 00:00:00          8
    11-FEB-2011 00:00:00 10-MAR-2011 00:00:00          7
    11-MAR-2011 00:00:00 20-SEP-2011 00:00:00          6
    21-SEP-2011 00:00:00 10-OCT-2011 00:00:00          4
    11-OCT-2011 00:00:00 31-DEC-2011 00:00:00          8
    9 rows selected.HTH
    David
    Edited by: Bravid on Feb 23, 2012 12:08 PM
    Beaten to it by Frank! :-)

  • Need help in SQL Select

    Hi All,
    I'm using the below script in conc.pgm to get some data
    Prompt ROllNO, DEPT, Amount, Store;
    SELECT ' '
    || ROLL_NO
    || ', '
    || DEPT
    || ', '
    || Amount
    ||', '
    || Store
    FROM XXX;
    And the output looks like this,
    ROll NO, DEPT, Amount, Store
    101,     ABC, 500,     XXX
    102,     ABC, -600,     YYY
    103,     ABC,     800,     ZZZ
    If you see in the second row, as the amount is negative, it is taking one extra space to accomodate the sign. Because of this, the other columns are affected.
    Now when i want an output someting like,
    ROll NO, DEPT, Amount, Store
    101,     ABC, 500,     XXX
    102,     ABC, -600,     YYY
    103,     ABC, 800,     ZZZ
    Means, i want the data to be aligned properly even if the selected column has more width.
    Any changes i need to do to the Query?
    Kindly provide some pointers
    Regards,
    Mohan

    Hi,
    The problem is with your data. For this type of query you will have to fix the length of every column..let say
    Dep Code is having values like 12,123,1234
    So, for this create your query like this...
    SELECT LPAD(DEP_CODE,(SELECT MAX(LENGTH(DEPT_CODE)) FROM XXX),' ') FROM XXXthrough this statement you can get the your desired result. use the same strategy for all columns by changing the column name.
    -Ammad

  • Need help for SQL Queries Tunning

    hi all,
    we have a procedure for search consumers, which using sql queries like:
    SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
    TRIM (connaddress) AS connaddress,
    TRIM (CATEGORY) AS CATEGORY, TRIM (landmark) AS landmark,
    SUBSTR (accno, 1, 3) AS subdivisionname
    FROM consumermaster
    WHERE LOWER (accno) LIKE
    LOWER ('%' || NVL (caccno, '#noval#') || '%')
    OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
    OR LOWER (connaddress) LIKE
    LOWER ('%' || NVL (cadd, '#noval#') || '%')
    OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
    OR accno = (SELECT accno
    FROM requestregistration
    WHERE requestid = creqid)
    UNION
    SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
    TRIM (connaddress) AS connaddress, TRIM (CATEGORY)
    AS CATEGORY,
    TRIM (landmark) AS landmark,
    SUBSTR (accno, 1, 3) AS subdivisionname
    FROM scodetails
    WHERE LOWER (accno) LIKE
    LOWER ('%' || NVL (caccno, '#noval#') || '%')
    OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
    OR LOWER (connaddress) LIKE
    LOWER ('%' || NVL (cadd, '#noval#') || '%')
    OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
    OR accno = (SELECT accno
    FROM requestregistration
    WHERE requestid = creqid);
    it's ok for small tables but now data increase .......
    searching method is very slow
    now i want to tune this query for better performance
    please sugg me best method
    Thanks in advance
    Regards
    vij..

    The link given by Asif should get you on the right track for tuning this query.
    I just formatted your SQL:
    SELECT Trim(NAME)        AS NAME,
           Trim(accno)       AS accno,
           Trim(connaddress) AS connaddress,
           Trim(category)    AS category,
           Trim(landmark)    AS landmark,
           Substr(accno,1,3) AS subdivisionname
    FROM   consumermaster
    WHERE  Lower(accno) LIKE Lower('%'
                                   ||Nvl(caccno,'#noval#')
                                   ||'%')
            OR Lower(NAME) LIKE Lower('%'
                                      ||Nvl(cname,'#noval#')
                                      ||'%')
            OR Lower(connaddress) LIKE Lower('%'
                                             ||Nvl(cadd,'#noval#')
                                             ||'%')
            OR phone LIKE '%'
                          ||Nvl(cphone,'#noval#')
                          ||'%'
            OR accno = (SELECT accno
                        FROM   requestregistration
                        WHERE  requestid = creqid)
    UNION
    SELECT Trim(NAME)        AS NAME,
           Trim(accno)       AS accno,
           Trim(connaddress) AS connaddress,
           Trim(category)    AS category,
           Trim(landmark)    AS landmark,
           Substr(accno,1,3) AS subdivisionname
    FROM   scodetails
    WHERE  Lower(accno) LIKE Lower('%'
                                   ||Nvl(caccno,'#noval#')
                                   ||'%')
            OR Lower(NAME) LIKE Lower('%'
                                      ||Nvl(cname,'#noval#')
                                      ||'%')
            OR Lower(connaddress) LIKE Lower('%'
                                             ||Nvl(cadd,'#noval#')
                                             ||'%')
            OR phone LIKE '%'
                          ||Nvl(cphone,'#noval#')
                          ||'%'
            OR accno = (SELECT accno
                        FROM   requestregistration
                        WHERE  requestid = creqid); You are using some function on almost each and every column in the where clause. Try getting rid of them as they are hindering the use of indexes, if any, on any of the columns.
    Also the guidelines in the link provided are the best starting point.

  • NEED HELP!! creating a method to search records from a data.dat file

    i am having a lot of trouble trying to create a method for searching records from a data.dat file as a contacts application i am using (for) and (if) together and getting the same error messages saying a ")" is needed when it doesn't and illegal start of expression can anyone help! on letting me know how you create search methods! thanks

    public static void search_records()
              System.out.println("Please Enter a Surname (* for all):");
              user_surname = data_input.next();
              System.out.println("Please Enter a firstname (* for all):");
              user_firstname = data_input.next();
              for (int i = 0; i < number_of_records; i++)
                   if(user_surname.compareTo(lastName) || user_surname.compareTo(*));
                             if(user_firstname.compareTo(firstName[i]) || user_firstname.compareTo(*));
                                  system.out.print("Result:",number_of_records);

  • To fetch ALTERNATE records from a table. (EVEN NUMBERED)

    suppose i having tABle employee columns empid,empname ,emplocation it having 20 rows and  i want to fetch 10 records which are even how to write query
    jitendra

    it was interview question
    Then you ask back to the interview: what do you mean with even rows? In a relational database there is no inherit number for a row. In fact a table is by definition an unordered set. Of course, we can extract only the even empid:s, but there is no guarantee
    that there is exactly ten of them. Chance could have it that all empids are odd.
    If the interviewer insists you can say that we can always run a query with row_number, but that frankly does not make any sense.
    If nothing else, this sort of response may reveal what sort of interviewer you are talking to. Is is exactly as clueless as the question suggest? Or is he purposely asking you a stupid question to see if you are smart enough to call his bluff?
    I don't know about interviews in general, but if I were interviewing people, I would certainly be impressed by someone who has the guts to object and come with sound objections. That is exactly the kind of people I want to work with.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to fetch last record from the table to display in screen painter?

    Hi Gurus,
                  I have a requirement where i have to fetch the last record value in the table.
    I have a screen where the TEXT name is REQUEST and I/P field name is REQ and SAVE push button.
    In this I/P field automatically 1 should display when i excecute the program and when i save this, the request number should turn to 2 that is dynamically..once agin save then 3 and so on....and this 1, 2, 3 will be storeing in table.
    I have succeeded till generating the values dynamically and saving in the table like 1 is displayed and when i click save it is changeing to 2..but the problem is when i am coming out of program and logon again the request number is again displaying as 1 rather it has to start with 4 because already 3 request are there in the table.
    My code is...
    Table zsave.
    data declarations....
    data req type i.
    req = 0.
    req = zsave-req.
    PROCESS BEFORE OUTPUT
    req = 0.
    select req into table fun_st from zsave.
    req = zsave-req.
    zsave-req = req.
    req = zsave-req + 1.
    PAI
    req = zsave-req + 1.
    zsave-req = req.
    when 'save'.
    wa_funst-req = zsave-req.
    Please can you provide me with the solution....answer will be rewared.
    THKS

    Can you tell me, when updaing the ZSAVE table with the counter value are you modifying the exisiting value or inserting the value as new record?
    From the code in your first post, i see that you are extracting records into internal table but when you are moving to variable REQ, you are moving from table work area which is blank, so everytime when you execute it may be starting as 0.
    Hope below code can help you understand on handling your requirement
    Global Declaration:
    >DATA: l_req TYPE i. 
    PBO:
      SELECT MAX( req ) INTO l_req FROM zsave.
      l_req = l_req + 1.
    PAI:
      DATA: wa TYPE zsave.
      CASE ucomm.
      WHEN 'SAVE'.
        wa-req = l_req.
        INSERT zsave FROM wa.
      ENDCASE.

Maybe you are looking for