Using extract and existnodes in a SQL query

I have created a table having one column of datatype xmltype in oracle 9i and inserted 2 rows. When I try to execute the select query having extract and existsnode it is giving me ORA-00904: invalid column name.
CREATE TABLE xml_tab ( xmlval sys.xmltype);
INSERT INTO xml_tab VALUES (
sys.xmltype.createxml('<?xml version="1.0"?>
<EMP>
<EMPNO>221</EMPNO>
<ENAME>John</ENAME>
</EMP>'));
INSERT INTO xml_tab VALUES (
sys.xmltype.createxml('<?xml version="1.0"?>
<PO>
<PONO>331</PONO>
<PONAME>PO_1</PONAME>
</PO>'));
SELECT e.xmlval.extract('//EMPNO/text()').getNumVal() AS empno
FROM xml_tab
WHERE e.xmlval.existsnode('/EMP/EMPNO') = 1;

Correct forum for extract() and existsnode() SQL functions is /Products/Database/XML DB.. Please post there

Similar Messages

  • Using multiple 'and' conditions in a SQL query

    Is it possible to reduce the SQL required to query using multiple 'and' conditions, e.g. I have a query like the following:
    select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
    from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
    where stat.apy_apn_id = apps.rgn_apt_id
    and apps.rgn_apt_id = appt.rgn_apt_id
    and stat.application_completed is null
    and stat.application_started_date > '01-MAY-11'
    and stat.amount_paid is null
    and stat.personal_details = 'C'
    and stat.further_details = 'C'
    and stat.education = 'C'
    and stat.employment = 'C'
    and stat.personal_statement = 'C'
    and stat.choices = 'C'
    and stat.reference = 'C'
    and stat.student_finance = 'C'
    Is there a way, to reduce all the multiple 'and' queries, to be read from say one line? If you know what I mean.......

    Ah, Ok this looks nice, thanks very much. It doesn't quite run as is because the stat.amount_paid query value is 'is null', while the others are 'C'. I tried amending the relevant line to various versions of the following:-
    in (select 'is null' 'C','C','C','C','C','C','C','C' from dual)
    which doesn't work.
    I can get the following to work so I am assuming that the it is not possible to use different query values within the brackets of the 'in (select....' statement?
    select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
    from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
    where stat.apy_apn_id = apps.rgn_apt_id
    and apps.rgn_apt_id = appt.rgn_apt_id
    and stat.application_completed is null
    and stat.application_started_date > '01-MAY-11'
    and stat.amount_paid is null
    and (stat.personal_details, stat.further_details, stat.education,
    stat.employment, stat.personal_statement, stat.choices, stat.reference, stat.student_finance)
    in (select 'C','C','C','C','C','C','C','C' from dual)
    Thanks for everybodys help - the suggested alternatives seem so much more elegant

  • How does Index fragmentation and statistics affect the sql query performance

    Hi,
    How does Index fragmentation and statistics affect the sql query performance
    Thanks
    Shashikala
    Shashikala

    How does Index fragmentation and statistics affect the sql query performance
    Very simple answer, outdated statistics will lead optimizer to create bad plans which in turn will require more resources and this will impact performance. If index is fragmented ( mainly clustered index,holds true for Non clustred as well) time spent in finding
    the value will be more as query would have to search fragmented index to look for data, additional spaces will increase search time.
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    My TechNet Wiki Articles

  • When to use SELECT and END SELECT in the query.

    hi all,
    When to use SELECT and END SELECT in the query.
    regads,
    Venkata Suresh Penke.

    Hi Suresh..
    When do we need to use SELECT .. ENDSELECT
    Usually we will never use SELECT .. ENDSELECT as it gives very poor performance.
    But whenever we read a single Record we will use it as an alternative for SELECT SINGLE in some scenarios.
    Eg: When the Full primary key is not specified in the WHERE clause.
    SELECT * FROM MARC INTO WA_MARC UP TO 1 ROWS WHERE MATNR = P_MATNR.
    ENDSELECT.
    And other scenario is when we perform AGGREGATE OPERATIONS.when the Result is only one row.
    SELECT SUM( LABST ) FROM MARD INTO V_LABST UP TO 1 ROWS
    WHERE MATNR = P_MATNR.
    ENDSELECT.
    Note: In The Above scenario we cannot use SELECT SINGLE..
    <b>REWARD IF HELPFUL.</b>

  • Problem using alias field names in a sql query

    Hello,
    I have a question regarding a simple Oracle database SQL query writeup:
    In the following (badly written but properly working) SQL query:
    Query 1:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    (soe.field5 - (soe.field2 + soe.field3)) as field6,
    (select comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 1:
    I am re writing the code (soe.field2 + soe.field3) to get the alias field4 or column name field4 that I have created on the fly in the previously for use with the following fields. Can't I rewrite the query as follows. There is something simple missing!
    Query 2:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6, <<< field4 does not work here
    (select
    comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select
    soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 2:
    Similar to the above problem, I was thinking to get a field parValue out of the CompTable table and re-use many times rather than the code shown in Query 1:
    Query 3:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6,
    soe.field7* (select comp.parValue from CompTable comp) as parValue1,
    soe.field8 - (parValue1*soe.field7+ soe.field9) as field10      <<<< parvalue1 does not work here
    parValue1*soe.field9 as TaxCondition               <<<< parvalue1 does not work here
    from
    SomeTable soe
    See that the query becomes so simple, but the above query does not work. There is something fundamentally wrong in my usage of the alias field names in creating other fields. The Query1 seems to be the only working option but its very slow as I am redoing and re-writing the whole code again and again to get the parValue field out of the CompTable table for use to create many other fields.
    I will appreciate if you can guide me in the right direction on this issue.
    Thanks and Regards
    Rama

    SELECT tmp.contract_no, tmp.Actual, tmp.Actual - tmp.NbHours
    FROM ( SELECT t.contract_no, sum(l.hrs) AS Actual, (c.labour_hours * c.labour_progress_per) / 100 AS NbHours
    FROM TASK_DELEGATION t
    INNER JOIN COST_CODE c
    ON t.cost_code = c.cost_code AND t.contract_no = c.contract_no AND t.is_inactive=0
    INNER JOIN Labour.dbo.LABOURALLOT l
    ON l.contractNo = c.contract_no AND l.costcode = c.cost_code AND l.pm = 'N'
    GROUP BY t.contract_no, c.labour_hours, c.labour_progress_per
    ) tmp

  • Using/calling  a parameter in the SQL Query!

    Hi
    How do I use or call a parameter from the parameterform in my SQL query in Reports ??
    Thanks in advange *S
    /Stig :-)

    If you have user parameters of P_BEGINDATE and P_ENDDATE, in your query you would reference them by the following:
    FROM auditlog
    WHERE (eventtimestamp between :P_BEGINDATE and :P_ENDDATE
    or :P_BEGINDATE IS NULL)
    If you are using the report through Oracle Applications Concurrent Manager make sure the Token (when setting up parameters for the concurrent program)matches the user parameter exactly.
    - Rob

  • Chart Query and Failed to parse SQL query

    Hi,
    first of all, this is not a question. It is a reminder for me and maybe for someone with the same problem.
    I just fell over this for the 123124 time.
    I have a 3D Chart Query
    select sum(order_ok) value,
          count(*) maximum_value
    from      v_dialer_campaign
    where campaign_uuid = :P300_CAMPAIGN_IDSaving fails with
    "1 error has occurred Failed to parse SQL query!" ...
    Saving the query without validation works, but does not show any result in the chart.
    v_dialer_campaign is a view selecting from a view in a mssql db over database link and HS.
    running the select in sqlplus or toad works.
    Without any trace on freetds/unixodb/hs side, i would have not found the following line:
    [FreeTDS][SQL Server]The data types nvarchar and text are incompatible in the equal to operator.[FreeTDS][SQL Server]Statement(s) could not be prepared.
    Solution:
    with q as (select :P300_CAMPAIGN_ID val from dual)
    select     sum(order_ok) value,
         count(*) maximum_value
    from     v_dialer_campaign
    where     campaign_uuid in ( select val from q)Maybe the error output when validating the query should be included in the APEX error message.
    Same solution applies for dynamic LOV's reading from HS using a where clause.

    I tried your first query on Apex 3.2 and it created a nice dial chart.
    Is there any ORA-xxxxx error along with the "failed to parse SQL query" message? Did you double check column & table name spelling?
    P.S. The second query is invalid (a superfluous comma after the second column).

  • Returning operation, table and column from a sql query

    Hi,
    I am working on Oracle 10g and i have to do achieve something like this.
    i have to create procedure or functions which will accept a SQL query and will return following :
    1).  Operation like 'SELECT', 'INSERT', 'UPDATE', 'DELETE' etc.
    2).  Column names
    3).  Table involved.
    One way to achieve this would be through hard parsing of string which might be time consuming. So do we have any in-built oracle package or function for the same job ?
    Regards,
    Vikas Kumar

    Check for DBMS_SQL package and DESCRIBE_COLUMNS procedure in that package.
    You might need a combination of this package and Hard parsing of the input string.
    For operation you can trim any space and brackets using TRIM function and then you can extrcat first 6 characters using SUBSTR for Operation.
    I have not worked or used DBMS_SQL so wont be able to help you much on this.
    Here is the link for DBMS_SQL
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#i1026120
    Regards
    Arun

  • AD: Extracting to Shapefile based on SQL query

    We have written a command-line tool, SpatialExtractor, that takes an SQL query and produces an ESRI Shapefile.
    If this is valuable to you, please download an evaluation version from our website, www.geometry.com.au. The full version is (approx) US$570.
    We welcome any feedback or comments.
    regards,
    Andrew Betlehem
    Geometry
    www.geometry.com.au

    Hi,
    just non click able graph in ADF 10g using BI Graph: http://www.freewebalbum.com/blogs/faces/bjanko/blogs.jsp?blog=bjanko20070629162305
    regards,
    Branislav

  • Using lag and rank in the same query

    Hi
    I am trying to find out the difference in time between peoples memberships and also the order that these memberships are taken out in. So far I have added in a rank statement to work out the order the memberships were created in, but now want to look at the difference between the dates returned. The SQL I used is:
    SELECT owner_party_id,
    mem_number,
    support_id,
    mem_start_date,
    RANK() OVER (PARTITION BY owner_party_id ORDER BY mem_start_date ASC) MEMBERSHIP_SEQUENCE
    FROM membership_all
    WHERE version_type = 'CUR'
    AND owner_party_id IN ('65051', '65051', '65348', '65348', '65607', '65607', '65607')
    to get:
    "OWNER_PARTY_ID"|"MEM_NUMBER"|"SUPPORT_ID"|"MEM_START_DATE"|"MEMBERSHIP_SEQUENCE"
    65051|318874751|8014747|01-MAR-10|1
    65051|412311060|21502883|15-AUG-12|2
    65348|308672459|3526913|01-MAY-10|1
    65348|409951130|20950524|18-JUN-12|2
    65607|315830192|7510133|17-MAY-10|1
    65607|406448110|20024246|16-MAR-12|2
    65607|409738130|20903556|14-JUN-12|3
    Now I would like to calculate the difference between the start dates of each of the owner_party_id groups, so to get something like this:
    OWNER_PARTY_ID|MEM_NUMBER     |SUPPORT_ID|MEM_START_DATE     |MEMBERSHIP_SEQUENCE|Diff
    65051|318874751|8014747|01-Mar-10|1|     
    65051|412311060|21502883|15-Aug-12|2|898
    65348|308672459|3526913|01-May-10|1     
    65348|409951130|20950524|18-Jun-12|2|779
    65607|315830192|7510133|17-May-10|1     
    65607|406448110|20024246|16-Mar-12|2|669
    65607|409738130|20903556|14-Jun-12|3|90
    I think that I need to use the Lag function in, but I am not too sure if it can be linkited to look at the data within a grouping of owner party id, as it would make no sense to calculate the difference in dates for two different owner party ids.
    Any advice much appreciated.
    Thanks
    Edited by: 992871 on 09-Mar-2013 23:34

    Couple notes:
    1. You wrote you want to get order that these memberships are taken out in, however, both your and Etbin's queries calculate order within each owner_party_id and not across all members. If you want to get rank and difference in time regardless of member's owner_party_id remove PARTITION BY caluse.
    2. You might want to use DENSE_RANK and not RANK depending how you want to display rank. If two people joined at the same time and were second in rank, analytic RANK will be:
    RANK
    1
    2
    2
    4
    5
    .while DENSE_RANK:
    DENSE_RANK
    1
    2
    2
    3
    4
    .SY.

  • Using WHERE command in property loader SQL query

    Hello All,
    Hopefully this will be a fairly straight forward question.
    I am attempting to use Property Loader to read in test limits from a SQL database. There are many types of models that need to be tested, each having a unique set of limits. I want to be able to retrieve the appropriate limits for the model of product under test.
    To do this I have the product model number available in a FileGlobal. The database contains a table with the test limit information with an identifying 'ModelNumber_Number' column.
    I have written the following SQL query achieve this:
    "SELECT *  FROM TESTLIMITS WHERE ModelNumber_Number=+ FileGlobals.ModelNumber"
    However, this is where I am confused. I'm not sure on the syntax for accessing a variable in the SQL command. I receive the following error:
    The multi-part identifier "FileGlobals.ModelNumber" could not be bound.
    Can someone please provide guidence on how to do this?
    Many thanks,
    Cam.
    Solved!
    Go to Solution.

    Thank you very much for your reply.
    Upon changing the query to as you suggest, I am presented with the following:
    Error In SQL Statement Expression. "SELECT *  FROM TESTLIMITS WHERE ModelNumber_Number = " + FileGlobals.ModelNumber
    Specified value does not have the expected type.
    The type of FileGlobals.ModelNumber is a numeric represented as a double precision 64 bit signed integer.
    The database column is also of type int 64.
    Can you suggest a solution?
    Many thanks.

  • Can give me examples and explantions on Using COPY and NOCOPY in pl-sql

    Can give me examples and explantions on Using COPY and NOCOPY in pl-sql

    If you use COPY then parameter is copied into procedure/function internal
    spae, so You can't modify parameter.
    If you use NOCOPY then parameter is not copied into procedure/function
    internal spae, so You can modify parameter.NOCOPY modifier serves the same purpose as "copy by value" and "copy by reference" concept (like in C++).
    Then you NOCOPY parameter you pass it's pointer in memory but not pass it's value into the stack.
    You can modify the value of this parameter in both cases. The essential difference is for NOCOPY not only the pointer copies much faster then the object itself but the semantic of exception processing is voilated because when the exception raises Oracle can't restore the initial state of parameter (because all changes where made using the memory pointer but not usual stack copie of parameter):
    SQL> create or replace package my_pkg
      2  is
      3   type t is table of number index by binary_integer;
      4   t1 t;
      5   procedure no_copy (a in out nocopy t);
      6   procedure with_copy(a in out t);
      7  end;
      8  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3 
      4   my_exc exception;
      5 
      6   procedure no_copy (a in out nocopy t)
      7   is
      8   begin
      9    for j in 1..10 loop
    10     a(j) := 1;
    11    end loop;
    12    raise my_exc;
    13   end;
    14 
    15   procedure with_copy (a in out t)
    16   is
    17   begin
    18    for j in 1..10 loop
    19     a(j) := 1;
    20    end loop;
    21    raise my_exc;
    22   end;
    23  
    24  end;
    25  /
    Package body created.
    SQL> declare
      2    t1 my_pkg.t;
      3  begin
      4    dbms_output.put_line('Count before ' || t1.count);
      5    begin
      6      my_pkg.no_copy(t1);
      7    exception
      8      when others then
      9        null;
    10    end;
    11    dbms_output.put_line('Count after ' || t1.count);
    12  end;
    13  /
    Count before 0
    Count after 10
    PL/SQL procedure successfully completed.
    SQL> declare
      2    t1 my_pkg.t;
      3  begin
      4    dbms_output.put_line('Count before ' || t1.count);
      5    begin
      6      my_pkg.with_copy(t1);
      7    exception
      8      when others then
      9        null;
    10    end;
    11    dbms_output.put_line('Count after ' || t1.count);
    12  end;
    13  /
    Count before 0
    Count after 0
    PL/SQL procedure successfully completed.Rgds.

  • Using a Variable to create the SQL Query

    I need to create a "dynamic" Update query. I want to store
    the meet of the command in a variable and then reference the
    variable in in query.
    Example:
    <cfquery name="fred" datasource="mydb">
    update db_table_name set
    pbname = 'Fred Flintstone',
    pbnumber = '555-555-1234'
    pbage = 25
    where recnum = 24
    </cfquery>
    I would like use code this:
    <cfset upst = "pbname = 'Fred Flintstone', pbnumber =
    '555-555-1234', pbage = 25">
    <cfquery name="fred" datasource="mydb">
    update db_table_name set
    #upst#
    where recnum = 24
    </cfquery>
    When I run this, I get the following error message:
    Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error
    (missing operator) in query expression ''Fred Flintstone''.
    The SQL line is:
    update db_table_name set pbname = ''Fred Flintstone'',
    pbnumber = ''555-555-1234'', pbage = 25 where recnum = 24
    I know its hard to see, but the '' are 2 ' not 1 " . I have
    no idea why Coldfusion (or maybe the ODBC driver??) is placing the
    2nd ' in the command which causes the errors.
    Can anyone shed some light on this topic?
    While this is a simple example, my application is far more
    complex. I have over 50 fields in the udpate and depending on
    changes to the form values, I may need to update all the fields,
    some of the fields or NONE of the fields.
    I can use <cfif> to test if any fields have changed and
    if so, include them in the update command, but if NONE of the
    fields have changed, I would have an empty update command and
    therefore get an error. I want to avoid having to test for changes
    twice (once to determine if I am doing the update and twice to
    perform the update).
    Thanks,
    Mike.

    cf automatically escapes the single quotes, so you need to
    preserve them
    <cfquery name="fred" datasource="mydb">
    update db_table_name set
    #PreserveSingleQuotes(upst)#
    where recnum = 24
    </cfquery>
    Ken

  • Using the LIKE keyword in a SQL query

    Does anyone have an example using the Database Connectivity Execute Query vi and the LIKE keyword? I would like to do something like:
    SELECT TestNum, TestType FROM tests WHERE DeviceType ='Paul_AF125_Ver1' AND DeviceID = 'Test1' AND (TestType LIKE "Cyclic Voltammetry*")
    It works fine if I say LIKE "Cyclic Voltammetry" (without the *) but if I put the * in there, I get no records.
    I'm using Microsofts SQL Server Desktop Engine (comes with Access).
    Thanks,
    Paul

    Paul-
    Thank you for contacting National Instruments. I don't have an example program, but I did find some information for you.
    LIKE - similar to.
    Using the LIKE command, you can use the wildcard symbol %. To find names starting with J : names LIKE 'J%'; Ending in s ? name LIKE '%S'; You can use more than one % charactor too : names LIKE '%sam%'; Also, LIKE is not case sensitive.
    What you have written, may work if you change the wildcard syntax from * to %.
    -Erik

  • Why would white space and line breaks in sql query increase runtime

    Using 11.2.0.3.0 on unix sprac server, 8 cpus 32 cores 12TB storage. We have 16 batch servers doing inserts and ~100 users doing mostly queries.
    We have a wierd issue,  we have a long query that takes 30 seconds to run 1st time then 10-20 secs every other time. Based on knowledge of DB we expected it to take a lot less.  Then a developer reformatted it by taking removing extra white space and line breaks.  all of sudden query takes 6 secs first time and 0.8 every other time.  we tripled checked to ensure they are identical and that only difference is white space and line breaks.  We tried it with SQLDeveloper, TOAD, SQLPLUS, from out desktops, appserver. we could reproduce it every time, with white space 10-20 secs without it 0.8 secs.  Query is 200 lines long with white space 30 without it.
    Why would having white space make such a dramatic difference?  because the query is longer eventhough its identical?  We checked parsing times, etc, no difference.  Is there some network setting, oracle parameter, sqlnet setting?  We spent hours looking on google and found nother
    Slow:
      SELECT grt_student.student_id                                                                                                                                                                                                 
    AS student_id,
      grt_student.last_name                                                                                                                                                                                                       
    AS last_name,
      grt_student.first_name                                                                                                                                                                                                      
    AS first_name,
      grt_buyerinstance.buyerinstance_id                                                                                                                                                                                            
    AS buyerinstance_id,
      grt_buyerinstance.buyerfamily_id                                                                                                                                                                                              
    AS buyerfamily_id,
      grt_buyer.buyerfamily_acronym                                                                                                                                                                                                 
    AS buyerfamily_acronym,
      grt_reporting_utls_pkg.convert_gmrt_battery(grt_buyerinstance.buyerfamily_id,grt_buyer.battery)                                                                                                                                
    AS battery,
    fast:
    SELECT grt_student.student_id 
    AS student_id,  grt_student.last_name
    AS last_name, grt_student.first_name   AS first_name,  grt_buyerinstance.buyerinstance_id   AS buyerinstance_id,  grt_buyerinstance.buyerfamily_id
    AS buyerfamily_id,
      grt_buyer.buyerfamily_acronym  AS buyerfamily_acronym,  grt_reporting_utls_pkg.convert_gmrt_battery(grt_buyerinstance.buyerfamily_id,grt_buyer.battery)   AS battery,

    Do you have some sort of horrific network connection between the client and the database such that it would take 8.5 seconds to transmit a few kb of SQL to the server?  That seems most unlikely.
    How are you determining the query plan?  Are you absolutely sure that both SQL statements have the same plan_hash_value when they are actually executed (not just when you generate a query plan without executing it)?  What are the differences in wait events when you execute the two?
    The sql_id will change when you add or remove whitespace.  There are various methods of modifying query plans that are tied to a sql_id.  My wager would be that you have a profile/ outline/ etc. that is not there for the reformatted one which is causing a query plan difference.  My next guess is that you have an accepted plan for the old statement, you haven't set up a process to let the plan evolve, and the reformatted statement starts with the plan that the old statement would get if you allowed the plan to evolve.
    Justin

Maybe you are looking for