Best way to check boolean value

Hi!
I have a schema defining an XML element with a boolean attribute. The document related to this schema use true/false literal boolean values, eg:
<myelement myattribute="false"/>....<myelement myattribute="true"/>
The data is stored in binary xml storage.
I query the db on the boolean attribute with an xpath condition like this:
..../myelement[@myattribute=false()]
Querying the db with this method:
SELECT XMLQuery('....' returning content) from dual
all works as expected.
Instead, using:
SELECT XMLQuery('....' ' PASSING OBJECT_VALUE RETURNING CONTENT)
FROM "myxmltable"
WHERE XMLExists('....' PASSING OBJECT_VALUE);
I get the error: ORA-31038: Invalid hexBinary value: "false"
To get the second query method working, I have to change the xpath condition, forcing a string comparison:
..../myelement[string(@myattribute)="false"]
Can someone explain me this behaviour? What is the best way to check a boolean value? I'd like to write the same xquery working in both methods!
Thank you.
Bye
Mirko

Hi Geoff
here the schema:
<xs:schema xmlns:tns="http://OracleTest" xmlns:xdb="http://xmlns.oracle.com/xdb" elementFormDefault="qualified" targetNamespace="http://OracleTest" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="MyComplexType">
<xs:sequence>
<xs:element minOccurs="0" name="FirstChild">
<xs:complexType>
<xs:attribute name="A" type="xs:string" />
<xs:attribute name="B" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="SecondChild">
<xs:complexType>
<xs:attribute name="S" type="xs:string" />
<xs:attribute name="B" type="xs:boolean" />
<xs:attribute name="I" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="ThirdChild">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ThirdChildA">
<xs:complexType>
<xs:attribute name="A" type="xs:string" />
<xs:attribute name="B" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="ThirdChildB">
<xs:complexType>
<xs:attribute name="C" type="xs:string" />
<xs:attribute name="D" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="ID" type="xs:string" />
</xs:complexType>
<xs:element xdb:defaultTable="MyElement" name="MyElement" type="tns:MyComplexType" />
</xs:schema>
and here two sample XML documents:
<tns:MyElement ID="ID1" xmlns:tns="http://OracleTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://OracleTest http://OracleTest.xsd">
<tns:FirstChild A="a" B="b" />
<tns:SecondChild S="s" B="true" I="1" />
<tns:ThirdChild>
<tns:ThirdChildA A="aa" B="bb" />
<tns:ThirdChildB C="cc" D="dd" />
</tns:ThirdChild>
</tns:MyElement>
<tns:MyElement ID="ID2" xmlns:tns="http://OracleTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://OracleTest http://OracleTest.xsd">
<tns:FirstChild A="aa" B="bb" />
<tns:SecondChild S="ss" B="false" I="2" />
<tns:ThirdChild>
<tns:ThirdChildA A="aaaa" B="bbbb" />
<tns:ThirdChildB C="cccc" D="dddd" />
</tns:ThirdChild>
</tns:MyElement>
I registered the schema using Enterprise Manager. The "Show SQL" function returned this script:
BEGIN
DBMS_XMLSCHEMA.REGISTERSCHEMA(
schemaurl => 'http://OracleTest.xsd',
schemadoc => sys.UriFactory.getUri('/Testing/test.xsd'),
local => FALSE,
gentypes => FALSE,
genbean => FALSE,
gentables => TRUE,
force => FALSE,
owner => 'EMILIAROMAGNABUY',
OPTIONS => DBMS_XMLSCHEMA.REGISTER_BINARYXML);
END;
This is my test script:
-- This works fine: returns only the requested row.
SELECT XMLQuery('declare default element namespace "http://OracleTest"; collection("/Testing")/MyElement/SecondChild[@B=true()]' returning content) from dual;
-- This raises the error = SQL Error: ORA-31038: Invalid hexBinary value: "true"
select xmlquery('declare default element namespace "http://OracleTest"; /MyElement/SecondChild[@B=true()]' passing object_value returning content).getclobval() from "MyElement";
-- This doesn't work correctly: returns the requested row and two empty rows ?!? I don't like this cast, anyway.
select xmlquery('declare default element namespace "http://OracleTest"; /MyElement/SecondChild[string(@B)="true"]' passing object_value returning content).getclobval() from "MyElement";
Thank you
Mirko

Similar Messages

  • Best way to extract XML value wiith an xpath

    Hello,
    I wonder what is the best way to extract text value from XmlType with an xpath.
    I need to insert a row inside a table where the row's data come from xpath extractions of an XmlType. I do a lot of (approximative 20) :
    EXTRACTVALUE(var.myxmltype , '/an/xpath/to/extract/elem1').
    EXTRACTVALUE(var.myxmltype , '/an/xpath/to/extract/elemI').
    EXTRACTVALUE(var.myxmltype , '/an/xpath/to/extract/elem20').
    inside the insert statement
    Is this way is the best or is there a more optimal way ?
    For example extracting the node '/an/xpath/to/extract/' and sarting from this node extracting "elem1", ... , "elemI", "elemN" children.
    Thanks for your help,
    Regards,
    Nicolas

    Hi Nicolas,
    The answer depends on your actual storage method (binary, OR, CLOB?), and db version.
    You can try XMLTable, it might be better in this case :
    SELECT x.elem1, x.elem2, ... , x.elem20
    FROM your_table t
       , XMLTable(
          '/an/xpath/to/extract'
          passing t.myxmltype
          columns elem1  varchar2(30) path 'elem1'
                , elem2  varchar2(30) path 'elem2'
                , elem20 varchar2(30) path 'elem20'
         ) x
    ;

  • Best way to get the values of local variables

    What is currently the best way to get the values of local variables. I know it is not currently possible to set watchpoints on local variables, but what are the best workarounds?

    You have to use StackFrame methods, eg, visibleVariables and getValues. To get a StackFrame for a thread, that thread has to be suspended, eg, by a BreakpointEvent.

  • Best way to change TreeMap value?

    Hello,
    I am wondering what is the best way to change a value in a TreeMap? I have retrieved a value by .get on the key i.e.
    String aString = (TreeMap) aTreeMap.get(aKey);but would now like to change aString and ?.put? it back into the map?
    How would I do this?
    Thank you,
    Poot.

    but would now like to change aString and ?.put? it
    back into the map?Do I just have to keep a note on the (key,value) - especially key - change the value and then .put(key,value) back in? Though I'll need to remove the initial pairing if I do this since TreeMap won't allow duplicate keys!
    There must be an easier way as this.
    Thank you for your reply,
    Regards,
    Poot.

  • Best way to check whether the database is demo or sys?

    Hi Gurus,
    Whats the best way to check whether the installed peoplesoft database is a demo or a sys?
    Thanks for the help?
    Regards,
    Anoop

    There is nothing set by default.
    However, if it has been configured properly by the administrator after db creation, through the menu Peopletools>Utilities>Administration>Peopletools Options, the following query should return the type of the database :
    select systemtype from psoptions;Otherwise the following could help to understand what database you are on.
    From HRMS9.1 DMO database :
    SQL> select count(*) from ps_employees;
          2792From HRMS9.1 SYS database :
    SQL> select count(*) from ps_employees;
      COUNT(*)
             0Nicolas.

  • Best Way to Check for same Word in string?

    If I have an array of words, would the best way to check for the same word be to use 2 for loops?

    Huh?
    Sounds like homework...
    What is a word? Presumably a String.
    For equality of Strings you use...
        String s1 = ....
        String s2 =....
        if (s1 == s2) { equal depending on null case
        else if ((s1 != null) && (s1.equals(s2))) { equal }
    For the case of checking one array to another....
          while items in array1
                 get itema from array1
                      while items in array2
                           get itemb array2
                                  is itemb equal (see above) to itema
                                         yes - then do something

  • I am getting pop ups on safari and firefox lately and am worried i may have malware or something now on my computer doing this. What is the best way to check this out for sure and remove it?

    I am getting pop ups on safari and firefox lately and am worried I may have malware or something now on my computer doing this. What is the best way to check this out for sure and remove it?

    Please review the options below to determine which method is best to remove the Adware installed on your computer.
    The Easy, safe, effective method:
    http://www.adwaremedic.com/index.php
    If you are comfortable doing manual file removals use the somewhat more difficult method:
    http://support.apple.com/en-us/HT203987
    Also read the articles below to be more prepared for the next time there is an issue on your computer.
    https://discussions.apple.com/docs/DOC-7471
    https://discussions.apple.com/docs/DOC-8071
    http://www.thesafemac.com/tech-support-scam-pop-ups/

  • What's the best way to check whether a user is logged in or not?

    I have a question about basic session handling.
    I'm running Tomcat 5.0.30 and have a web application where users can register with a username and password, and then log into a "member site".
    What is the best way of making sure that a user actually has logged in or not?
    What I've done in previous applications I've made is that I've just put a simple variable into the users session after he has successfully entered his password (i.e. Boolean loggedIn=true). Then I just test if this flag is true to grant him access to the member site. Is that a smart way of doing it?
    Are there any libraries I can use which handles sessions for me in a secure way?
    All comments and suggestions are appreciated!

    Maintain a flag using session attributes it to one when the user is logs in set it to value.... and change set it zero or invalidate that session... when the user is logged out...
    use something like this while user had logged in
    session.setAttribute("flag",<unique_number>);
    for checking whether the user had logged in or not...
    if(Integer.parseInt(session.getAttribute("flag").toString())=!<unique_number>){
    out.println("The session had expired");
    out.close();
    }

  • What is the best way to implement default values stored in a DB table?

    [JHeadstart 10.1.3 build 78]
    [JDeveloper 10.1.3 SU4]
    We are struggling on how to best implement default values that are stored in a DB table. What we have is a database table with (CODE_TYPE, TABLE_NAME, COLUMN_NAME, DEFAULT_VALUE) as columns. This way the application administrator can administer default values himself/herself. Now we need to find the best way to set these table supplied default values in new rows. Globally we are aware of two ways:
    - override create() method on VO
    - probably create a View Object on top of the database table with default values (we are capable of transposing the table and return exactly one row with a column for each default value) and use JHeadstarts item property 'Default Value'.
    We prefer the latter, since this is more declarative, however we struggle with the EL expression needed to indicate the default value.
    If we have a VO named "DefaultValues" with a SELECT on a view on top of our database table (transposed) returning exactly one row, let us say:
    SELECT orglanguage, orgtype, orgstatus [...]
    FROM v_default_values
    --> returning exactly one row
    and we want an EL expression on an item that needs the value from orglanguage. What will the EL expression be? Something like:
    #{data.DefaultValuesPageDef.currentrow.orglanguage.inputValue}? We tried several things but they do not work. A static default value works, but every EL expression so far does not. We know that using "data" can be dangerous, but thought JHeadstart takes care of preparing the other Page Definitions, so it might be possible when you use JHeadstart.
    Or is overriding the create() method the preferred way? Or do we have to look at a Managed Bean for our default values that we refer to from EL (let us say MyAppDefaultValuesBean) and in that case: how do you associate a Managed Bean with a VO?
    Any help would be appreciated. Apart from these default values, things are going rather well in this first J2EE/JHS project for us!
    Toine

    Steven,
    Thanks for the reply. Unfortunately whatever we try, we cannot get it to work. We started looking at the second option (since we do need default values also in table lay-out new rows). We created a DefaultValues ViewObject, added it to the Application Module, added an EL expressiona to the Default Display Value property (replacing your ending ")" with a "}" offcourse ;-)), ran the JAG so that a page definition was generated for DefaultValues and we managed to get it prepared when loading for example the Organisation's jspx page. However no default value appears in a new row (not in Form, not in Table layout).
    I then created a quick application on top of the HR schema, added a DefaultValues ViewObject using one calculated attribute (set Salary fixed to 1000), added the EL expression to the Salary Default Display Value property in the Employees Group, made sure the DefaultValuesPageDef is prepared by adding it to the parameter section and I see it getting prepared. I also see a managed Bean is created in the Employees-bean.xml.
    In the Embedded OC4J log we see:
    16:01:01 DEBUG (JhsPageLifecycle) -executing onCreate
    16:01:01 DEBUG (JhsPageLifecycle) -CreateEmployeesDefaultValues bean found, applying default values to new row
    2006-08-02 16:01:01.825 WARNING [ADFc] Warning: No Method onCreateEmployees and no actionBinding CreateEmployees found.
    Is it this warning we should be worried about? Since no default value is created.
    The managed bean (Employees-beans.xml) looks like:
    <?xml version="1.0" encoding="windows-1252"?>
    <!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config xmlns="http://java.sun.com/JSF/Configuration">
    <managed-bean>
    <managed-bean-name>CreateEmployeesDefaultValues</managed-bean-name>
    <managed-bean-class>oracle.jheadstart.controller.jsf.bean.DefaultValuesBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>iteratorBinding</property-name>
    <value>#{bindings.EmployeesIterator}</value>
    </managed-property>
    <managed-property>
    <property-name>defaultValues</property-name>
    <map-entries>
    <map-entry>
    <key>Salary</key>
    <value>#{data.DefaultValuesPageDef.DefaultValuesIterator.currentRow.Salary}</value>
    </map-entry>
    </map-entries>
    </managed-property>
    <managed-property>
    <property-name>actionResult</property-name>
    <value>CreateEmployees</value>
    </managed-property>
    </managed-bean>
    <managed-bean>
    <managed-bean-name>searchEmployees</managed-bean-name>
    <managed-bean-class>oracle.jheadstart.controller.jsf.bean.JhsSearchBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>bindings</property-name>
    <value>#{data.EmployeesPageDef}</value>
    </managed-property>
    <managed-property>
    <property-name>searchBinding</property-name>
    <value>#{data.EmployeesPageDef.advancedSearchEmployees}</value>
    </managed-property>
    <managed-property>
    <property-name>searchAttribute</property-name>
    <value>EmployeeId</value>
    </managed-property>
    <managed-property>
    <property-name>dataCollection</property-name>
    <value>EmployeesView1</value>
    </managed-property>
    <managed-property>
    <property-name>autoquery</property-name>
    <value>true</value>
    </managed-property>
    </managed-bean>
    <managed-bean>
    <managed-bean-name>EmployeesCollectionModel</managed-bean-name>
    <managed-bean-class>oracle.jheadstart.controller.jsf.bean.JhsCollectionModel</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>jhsPageLifecycle</property-name>
    <value>#{jhsPageLifecycle}</value>
    </managed-property>
    <managed-property>
    <property-name>bindings</property-name>
    <value>#{bindings}</value>
    </managed-property>
    <managed-property>
    <property-name>rangeBinding</property-name>
    <value>#{bindings.EmployeesTable}</value>
    </managed-property>
    <managed-property>
    <property-name>defaultValues</property-name>
    <value>#{CreateEmployeesDefaultValues.defaultValues}</value>
    </managed-property>
    </managed-bean>
    </faces-config>
    This is the DefaultValues.xml:
    <?xml version='1.0' encoding='windows-1252' ?>
    <!DOCTYPE ViewObject SYSTEM "jbo_03_01.dtd">
    <ViewObject
    Name="DefaultValues"
    BindingStyle="OracleName"
    CustomQuery="true"
    ComponentClass="hr.model.DefaultValuesImpl"
    UseGlueCode="false" >
    <DesignTime>
    <Attr Name="_version" Value="10.1.3.36.73" />
    <Attr Name="_codeGenFlag2" Value="Access|Coll|VarAccess" />
    </DesignTime>
    <ViewAttribute
    Name="Salary"
    IsUpdateable="false"
    IsPersistent="false"
    Precision="255"
    Type="java.lang.String"
    ColumnType="VARCHAR2"
    AliasName="SALARY"
    Expression="1000"
    SQLType="VARCHAR" >
    </ViewAttribute>
    </ViewObject>
    The PageDef for Defaultvalues is like:
    <?xml version="1.0" encoding="UTF-8" ?>
    <pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
    version="10.1.3.36.73" id="DefaultValuesPageDef"
    Package="hr.view.pagedefs" EnableTokenValidation="false">
    <parameters/>
    <executables>
    <iterator id="DefaultValuesIterator"
    Binds="AppModuleDataControl.DefaultValues1"
    DataControl="AppModuleDataControl" RangeSize="10"/>
    </executables>
    <bindings>
    <attributeValues id="DefaultValuesSalary"
    IterBinding="DefaultValuesIterator">
    <AttrNames>
    <Item Value="Salary"/>
    </AttrNames>
    </attributeValues>
    <table id="DefaultValuesTable" IterBinding="DefaultValuesIterator">
    <AttrNames>
    <Item Value="Salary"/>
    </AttrNames>
    </table>
    <action id="FirstDefaultValues" IterBinding="DefaultValuesIterator"
    DataControl="AppModuleDataControl" RequiresUpdateModel="true"
    Action="12"/>
    <action id="PreviousDefaultValues" IterBinding="DefaultValuesIterator"
    DataControl="AppModuleDataControl" RequiresUpdateModel="true"
    Action="11"/>
    <action id="NextDefaultValues" IterBinding="DefaultValuesIterator"
    DataControl="AppModuleDataControl" RequiresUpdateModel="true"
    Action="10"/>
    <action id="LastDefaultValues" IterBinding="DefaultValuesIterator"
    DataControl="AppModuleDataControl" RequiresUpdateModel="true"
    Action="13"/>
    <methodAction RequiresUpdateModel="true" Action="999"
    id="advancedSearchDefaultValues"
    IterBinding="DefaultValuesIterator"
    DataControl="AppModuleDataControl"
    InstanceName="AppModuleDataControl.dataProvider"
    MethodName="advancedSearch"
    ReturnName="AppModuleDataControl.methodResults.AppModuleDataControl_dataProvider_advancedSearch_result"
    IsViewObjectMethod="false">
    <NamedData NDName="viewObjectUsage"
    NDValue="#{searchDefaultValues.dataCollection}"
    NDType="java.lang.String"/>
    <NamedData NDName="arguments" NDValue="#{searchDefaultValues.arguments}"
    NDType="java.util.ArrayList"/>
    <NamedData NDName="allConditionsMet"
    NDValue="#{searchDefaultValues.allConditionsMet}"
    NDType="java.lang.Boolean"/>
    </methodAction>
    <action id="setCurrentRowWithKeyDefaultValues"
    IterBinding="DefaultValuesIterator"
    InstanceName="AppModuleDataControl.DefaultValues1"
    DataControl="AppModuleDataControl" RequiresUpdateModel="false"
    Action="96">
    <NamedData NDName="rowKeyStr" NDValue="#{row.rowKeyStr}"
    NDType="java.lang.String"/>
    </action>
    <action id="CreateDefaultValues" IterBinding="DefaultValuesIterator"
    DataControl="AppModuleDataControl" RequiresUpdateModel="true"
    Action="40"/>
    <action id="DeleteDefaultValues" IterBinding="DefaultValuesIterator"
    DataControl="AppModuleDataControl" RequiresUpdateModel="false"
    Action="30"/>
    <action id="Commit" RequiresUpdateModel="true" Action="100"
    DataControl="AppModuleDataControl"/>
    <action id="Rollback" RequiresUpdateModel="false" Action="101"
    DataControl="AppModuleDataControl"/>
    </bindings>
    </pageDefinition>
    We do not understand what is wrong and why the default values do not get created in the new rows (and it is taking us far too much time). Any chance the EL expression is still wrong? It is a shame that any syntax errors in EL expressions are not visible in some logfile. It looks like when EL expressions are wrong, they are ignored instead of raising an error...
    Toine

  • Best way to use return values in a webservices

    Hi all,
    Scenario: We have three web services. What is the best way to do this acitivity or is it possible?
    webservice1
    webservice2
    webservice3
    Call invoke webservice1 & 2 (they need to their work do be done parallely and will return a value eg "string")and call webservices3 with input values as the returned value from webservice 1 & 2.
    Thanks,
    Shashi
    Edited by: Shashi_sr on Sep 17, 2010 1:46 PM

    Hi Shashi,
    The way to achieve your desired functionality is as follows:
    Create a flow activity, and within that flow activity, you will call web services (using an invoke activity) webservice1 and webservice2.
    After the flow activity, you will then use another invoke activity to call the 3rd webservice using the output given by the first 2 webservices.

  • Best way to distribute configuration values to subVIs

    I have a main VI with ~10 subVIs, all of which have a number of default constants embedded. I want to change my architecture so that all the constants are moved to a single ASCII text file which is not changed during program execution. I'm trying to decide the best way to do this:
    - Read the file every time a subvi is opened (this is frequent).
    - Use the "Read Key" function (this may be essentially the same).
    - Read the file once at the beginning of execution, and store the values in a cluster which is passed to each subVI.
    - Read the file once at the beginning of execution, and store the values in several clusters, passing only the needed values to a given subVI.
    - Read the file once at the beginning of execution, and store the values in a functional (LV2) global which is read by each subVI when it is called.
    I think all of these would work, but what would be the most efficient in terms of programming time, execution time, memory usage, and ease of future modification? I'm leaning toward the multiple clusters approach so that I'm not constantly reading a file each time a subVI opens.
    Thanks to all,
    James

    Consider using what I call a "manager" VI. Its purpose is to manage the file for you.
    You call it whever you want to know one of these parameters.
    It knows whether it's read the file yet or not. If not, it does so on first call.
    After that, it simply keeps all your values in its own memory (shift registers).
    When you call it, it simply gives you the value(s) out of its memory, either as a big cluster, or as separated values.
    That way, you only read the file once.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • [8i] Best way to replace "similar" values with one value...?

    Below is some sample data:
    Sorry for the large set / complex set of sample data, but there should be no need to go through it in detail =).
    2 things to keep in mind:
    1) This is an 8i db
    2) I cannot create any new tables within this db, though I can create views
    CREATE TABLE     ord_master
    (     part_nbr          CHAR(25)
    ,     ord_nbr          CHAR(10)
    ,     sub_ord_nbr     CHAR(3)
    ,     ord_type          CHAR(2)
    ,     ord_stat          CHAR(2)
    ,     date_closed     DATE
    -- please note, though none of the columns in ord_master are explicitly defined as NOT NULL,
    -- none of them are NULL in the db, and given how things are input into the table, I don't
    -- even think it's possible
    -- a unique order is described by ord_nbr, sub_ord_nbr.  there should only be one record in
    -- this table for a given unique combination of those columns, though they are not the p.k.
    -- NOTE: dates default to 12/31/1900, so in the table above, if an order is still open (thus,
    -- not closed), it's date_closed will be 12/31/1900.  It will only change once the order closes.
    INSERT INTO     ord_master
    VALUES     ('ABC-123','1','1','AA','CL',TO_DATE('05/01/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','1','2','AA','CL',TO_DATE('9/14/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','2','1','AA','CL',TO_DATE('12/03/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','3','1','AA','OP',TO_DATE('12/31/1900','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','4','1','AA','CL',TO_DATE('03/12/2004','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('XYZ-123','5','1','AA','CL',TO_DATE('03/12/2004','mm/dd/yyyy'));
    CREATE TABLE     op_detail
    (     ord_nbr          CHAR(10)
    ,     sub_ord_nbr     CHAR(3)
    ,     major_seq_nbr     CHAR(4)
    ,     wctr_id          CHAR(5)
    ,     oper_stat          CHAR(2)
    ,     plan_su_rsrc     NUMBER(5,2)
    ,     plan_run_rsrc     NUMBER(11,8)
    ,     plan_subc_amt     NUMBER(15,5)
    ,     act_su_rsrc     NUMBER(5,2)
    ,     act_run_rsrc     NUMBER(7,2)
    ,     act_subc_amt     NUMBER(15,2)
    ,     act_start_dt     DATE
    ,     dt_completed     DATE
    ,     qty_planned     NUMBER(13,4)
    ,     qty_recvd          NUMBER(13,4)
    ,     qty_complete     NUMBER(13,4)
    ,     qty_scrap          NUMBER(13,4)
    ,     qty_on_hold     NUMBER(13,4)
    -- similar to ord_master, thought none of the columns are explicitly defined as NOT NULL,
    -- none of the records have NULL values for any of these columns, and I don't think it's
    -- really possible with the way the system is
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0081', 'X516 ', 'CP', 0, 0, 0, 0, .2, 0, TO_DATE('02/03/2010', 'mm/dd/yyyy'), TO_DATE('02/03/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .87, 0, TO_DATE('04/06/2010', 'mm/dd/yyyy'), TO_DATE('04/06/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 159, TO_DATE('03/05/2010', 'mm/dd/yyyy'), TO_DATE('03/05/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0130', 'H211 ', 'CP', .5, .1, 0, .08, .63, 0, TO_DATE('02/10/2010', 'mm/dd/yyyy'), TO_DATE('02/10/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0120', 'H214 ', 'CP', .3, .05, 0, 0, .68, 0, TO_DATE('05/22/2009', 'mm/dd/yyyy'), TO_DATE('05/22/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0122', 'T203 ', 'CP', 2.5, 1, 0, .67, .3, 0, TO_DATE('05/28/2009', 'mm/dd/yyyy'), TO_DATE('05/28/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0130', 'H211 ', 'CL', .5, .1, 0, .67, .3, 0, TO_DATE('05/28/2009', 'mm/dd/yyyy'), TO_DATE('05/28/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 153.12, TO_DATE('06/10/2009', 'mm/dd/yyyy'), TO_DATE('06/10/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .08, 0, TO_DATE('06/17/2009', 'mm/dd/yyyy'), TO_DATE('06/17/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0081', 'X516 ', 'CL', 0, 0, 0, 0, 0, 0, TO_DATE('07/20/2009', 'mm/dd/yyyy'), TO_DATE('07/20/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0324', 'Y000 ', 'CL', .1, .2, 0, 0, 3.03, 0, TO_DATE('09/11/2009', 'mm/dd/yyyy'), TO_DATE('09/11/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 204.16, TO_DATE('08/11/2009', 'mm/dd/yyyy'), TO_DATE('08/11/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0130', 'H211 ','CP', .5, .1, 0, 1.97, 2.67, 0, TO_DATE('07/28/2009', 'mm/dd/yyyy'), TO_DATE('07/29/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 255.2, TO_DATE('11/06/2009', 'mm/dd/yyyy'), TO_DATE('11/06/2009', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0130', 'H212 ', 'CP', .5, .1, 0, .6, .03, 0, TO_DATE('10/21/2009', 'mm/dd/yyyy'), TO_DATE('10/21/2009', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0550', 'R501 ', 'WK', 1, 16, 0, 2.2, 12.4, 0, TO_DATE('05/19/2010', 'mm/dd/yyyy'), TO_DATE('12/31/1900', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0324', 'Y000 ', 'CL', .1, .2, 0, 0, .07, 0, TO_DATE('02/04/2010', 'mm/dd/yyyy'), TO_DATE('02/04/2010', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('4', '1', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .59, 0, TO_DATE('02/06/2004', 'mm/dd/yyyy'), TO_DATE('02/06/2004', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);This is the query I'm working with right now:
    SELECT     o.part_nbr               
    ,          s.major_seq_nbr          AS op_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END                         AS wctr
    ,          MIN(s.plan_su_rsrc)          AS min_plan_setup
    ,          AVG(s.plan_su_rsrc)          AS avg_plan_setup
    ,          MAX(s.plan_su_rsrc)          AS max_plan_setup
    ,          STDDEV(s.plan_su_rsrc)     AS sdev_plan_setup
    ,          MIN(s.plan_run_rsrc)     AS min_plan_run
    ,          AVG(s.plan_run_rsrc)     AS avg_plan_run
    ,          MAX(s.plan_run_rsrc)     AS max_plan_run
    ,          STDDEV(s.plan_run_rsrc)     AS sdev_plan_run
    ,          MIN(s.plan_subc_amt)     AS min_plan_subc
    ,          AVG(s.plan_subc_amt)     AS avg_plan_subc
    ,          MAX(s.plan_subc_amt)     AS max_plan_subc
    ,          STDDEV(s.plan_subc_amt)     AS sdev_plan_subc
    ,          MIN(s.act_su_rsrc)          AS min_act_setup
    ,          AVG(s.act_su_rsrc)          AS avg_act_setup
    ,          MAX(s.act_su_rsrc)          AS max_act_setup
    ,          STDDEV(s.act_su_rsrc)     AS sdev_act_setup
    ,          MIN(s.act_run_rsrc)          AS min_act_run
    ,          AVG(s.act_run_rsrc)          AS avg_act_run
    ,          MAX(s.act_run_rsrc)          AS max_act_run
    ,          STDDEV(s.act_run_rsrc)     AS sdev_act_run
    ,          MIN(s.act_subc_amt)          AS min_act_subc
    ,          AVG(s.act_subc_amt)          AS avg_act_subc
    ,          MAX(s.act_subc_amt)          AS max_act_subc
    ,          STDDEV(s.act_subc_amt)     AS sdev_act_subc     
    ,          MIN(s.act_start_dt)          AS min_start
    ,          MAX(s.act_start_dt)          AS max_start
    ,          MIN(s.dt_completed)          AS min_comp
    ,          MAX(s.dt_completed)          AS max_comp
    ,          MIN(s.qty_planned)          AS min_qty_plan
    ,          AVG(s.qty_planned)          AS avg_qty_plan
    ,          MAX(s.qty_planned)          AS max_qty_plan
    ,          STDDEV(s.qty_planned)     AS sdev_qty_plan
    ,          MIN(s.qty_recvd)          AS min_qty_recvd
    ,          AVG(s.qty_recvd)          AS avg_qty_recvd
    ,          MAX(s.qty_recvd)          AS max_qty_recvd
    ,          STDDEV(s.qty_recvd)          AS sdev_qty_recvd
    ,          MIN(s.qty_complete)          AS min_qty_comp
    ,          AVG(s.qty_complete)          AS avg_qty_comp
    ,          MAX(s.qty_complete)          AS max_qty_comp
    ,          STDDEV(s.qty_complete)     AS sdev_qty_comp
    ,          MIN(s.qty_scrap)          AS min_qty_scrap
    ,          AVG(s.qty_scrap)          AS avg_qty_scrap
    ,          MAX(s.qty_scrap)          AS max_qty_scrap
    ,          STDDEV(s.qty_scrap)          AS sdev_qty_scrap
    ,          MIN(s.qty_on_hold)          AS min_qty_hold
    ,          AVG(s.qty_on_hold)          AS avg_qty_hold
    ,          MAX(s.qty_on_hold)          AS max_qty_hold
    ,          STDDEV(s.qty_on_hold)     AS sdev_qty_hold
    ,          COUNT(*)                    AS rec_cnt
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END                         AS time_period
    FROM          ord_master o
    ,          op_detail     s
    ,          (     -- begin in-line view a, to get the min act_start_dt for each order
              SELECT     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ,          MIN     (
                             CASE
                                  WHEN     s1.act_start_dt     > TO_DATE('01/01/2000','mm/dd/yyyy')
                                  THEN     s1.act_start_dt
                             END
                             )          AS ord_min_start
              FROM          op_detail s1
              GROUP BY     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ) a     -- end in-line view a          
    WHERE     o.ord_nbr          = s.ord_nbr
    AND          o.sub_ord_nbr     = s.sub_ord_nbr
    AND          o.ord_nbr          = a.ord_nbr
    AND          o.sub_ord_nbr     = a.sub_ord_nbr
    AND          o.ord_type     = 'AA'
    AND          o.ord_stat     IN ('CL','OP')
    AND          s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ORDER BY     o.part_nbr
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ,          s.major_seq_nbrThis gives me a bunch of descriptive statistics on some data stored in the database, broken into groups by the time period.
    I have 7 sets of possible values for the column wctr_id that are groups of similar/same work centers, and should be treated as the same, assuming the ord_nbr, sub_ord_nbr, and major_seq_nbr are the same. In my example case statement above, anytime I find 'H211' or 'H212', I am replacing it with 'Z211', which is my new, unique identifier for any wctr in the group ('H211', 'H212'). I have 7 of these sorts of groups that need to be replaced by a new, unique identifier. Is my CASE statement (noted above) the best way to do this, or is there a better way? These groups of similar-to wctr_id's are not listed in a table anywhere.

    Hi,
    As always, thanks for posting the CREATE TABLE and INSERT statements; that's very helpful, and leads to faster, better solutions.
    Another thing that is helpful, and promotes faster, better solutions, is to simplify your problem.
    For example, you have to compute a lot of aggregates, but it looks like you already know how to do that. This problem only involves the CASE expressions, and how they interact with the GROUP BY clause. So just cut out most of the aggregate functions.
    Also, it looks like the intricacies of in-line view a have nothing to do with your current problem. For purposes of posting this problem, pretend that a is a regular view, so it doesn't clutter up the main query.
    I think your problem could be restated like this:
    You already have a query like this:
    CREATE OR REPLACE VIEW a
    AS
              SELECT     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ,          MIN     (
                             CASE
                                  WHEN     s1.act_start_dt     > TO_DATE('01/01/2000','mm/dd/yyyy')
                                  THEN     s1.act_start_dt
                             END
                             )          AS ord_min_start
              FROM          op_detail s1
              GROUP BY     s1.ord_nbr
              ,          s1.sub_ord_nbr
    SELECT     o.part_nbr               
    ,          s.major_seq_nbr          AS op_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END                         AS wctr
    ,          MIN(s.plan_su_rsrc)          AS min_plan_setup
              -- lots of other agtgregates go here in real query
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END                         AS time_period
    FROM          ord_master o
    ,          op_detail     s
    ,          a          -- in real query, a is an in-line view
    WHERE     o.ord_nbr          = s.ord_nbr
    AND          o.sub_ord_nbr     = s.sub_ord_nbr
    AND          o.ord_nbr          = a.ord_nbr
    AND          o.sub_ord_nbr     = a.sub_ord_nbr
    AND          o.ord_type     = 'AA'
    AND          o.ord_stat     IN ('CL','OP')
    AND          s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ORDER BY     o.part_nbr
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ,          s.major_seq_nbr
    ;that produces this output:
    `                       MIN_
                           PLAN_
    PART_NBR   OP_N WCTR   SETUP TIME_PERIOD
    ABC-123    0081 X516      .0 12 mos. back
    ABC-123    0130 Z211      .5 12 mos. back
    ABC-123    0170 X928      .0 12 mos. back
    ABC-123    0324 Y000      .1 12 mos. back
    ABC-123    0120 H214      .3 24 mos. back
    ABC-123    0122 T203     2.5 24 mos. back
    ABC-123    0130 Z211      .5 24 mos. back
    ABC-123    0170 X928      .0 24 mos. back
    ABC-123    0324 Y000      .1 24 mos. back
    ABC-123    0324 Y000      .1 37 mos. back +The output is correct; the problem is, can we get the same results without 2 copies of the wctr CASE expression, and 3 copies of the time_period CASE expression?
    Is that a fair description of the problem?
    For starters, you can use column aliases in the ORDER BY clause. Unfortunately, that's the only place where you can use column aliases in the same query where they are defined . You can compute them in a sib-query, and then use them in super-queries.
    In other words, wouldn't it be nice if we had a table just like op_detail, but with an additional column called wctr? Make a view: either a regular view (especially if wctr, computed the same way, will be used in several different queries) or an in-line view, as shown below.
    Wouldn't it be great if there was a table that was just like a, except that it had time_period alreay computed? Make a view: either a regular view or an in-line view, as shown below.
    SELECT     o.part_nbr
    ,     s.major_seq_nbr          AS op_nbr
    ,     s.wctr
    ,     MIN(s.plan_su_rsrc)          AS min_plan_setup
         -- lots of other agtgregates go here in real query
    ,     a2.time_period
    FROM     ord_master      o
    ,     (          -- Begin in-line view s, with data from op_detail
                 SELECT  op_detail.*      -- or list all columns needed in main query
              ,     CASE          -- replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                       WHEN     wctr_id        IN ('H211','H212')
                       THEN     'Z211'
                       ELSE     wctr_id
                   END                    AS wctr
              FROM     op_detail
         ) s          -- End in-line view s, with data from op_detail
    ,     (           -- Begin in-line view a2, to compute time_period
              SELECT  a.*
              ,     CASE
                       WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                           THEN     '12 mos. back'
                           WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                           THEN     '24 mos. back'
                           WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                           THEN     '36 mos. back'
                           ELSE '37 mos. back +'
                   END                         AS time_period
              FROM     a          -- in real query, a is an in-line view
         ) a2          -- End in-line view a2, to compute time_period
    WHERE     o.ord_nbr     = s.ord_nbr
    AND     o.sub_ord_nbr     = s.sub_ord_nbr
    AND     o.ord_nbr     = a2.ord_nbr
    AND     o.sub_ord_nbr     = a2.sub_ord_nbr
    AND     o.ord_type     = 'AA'
    AND     o.ord_stat     IN ('CL','OP')
    AND     s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          s.wctr
    ,          a2.time_period
    ORDER BY     o.part_nbr
    ,          a2.time_period
    ,          s.major_seq_nbr
    ;In your example, wctr is the same as wctr_id except for two values. If it was more complicated (e.g., if there were not just 2 values that need to be mapped to 'Z211', but also 3 values to were equivalent to 'Z987', and 1 that was to be treated like 'A012', and 5 that should appear as 'A666', and ...), then you could code all that in a humongeous CASE expression (a nested CASE expression, if it involves more that 128 branches), but it really belongs in a table, where you have the raw wctr_id (like 'H211') in one column, and its corresponding equivalent (such as 'Z211') in another. I know you said you can't create new tables; I'm just pointing this out so you can tell the people who won't let you create new tables that it's a bad idea, likely to cause errors and certain to waste time in the future.

  • Best way to store 36 values

    Hello,
    I need to store 6 types of values with combination of 6X8 values totally 288 value .
    For Example
    1[{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6}]
    2[{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6}]
    3[{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6}]
    4[{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6}]
    5[{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6}]
    6[{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6},{1,2,2,59,7,8,9,6}]
    How can i store these values in c# ?,which is the best way with respect to performance and security.
    And whether i can store these data's in separate class file and access at time of process which is a multi-threading process.
    If i asked any thing wrong sorry as i am new in these things.
    Thanks

    Try this
    List<List<List<int>>> input = new List<List<List<int>>>(){
    new List<List<int>>(){
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6}},
    new List<List<int>>(){
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6}},
    new List<List<int>>(){
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6}},
    new List<List<int>>(){
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6}},
    new List<List<int>>(){
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6}},
    new List<List<int>>(){
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},
    new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6},new List<int>(){1,2,2,59,7,8,9,6}}
    jdweng

  • Best way to select distinct values based on another column?

    I have a table with three columns: id (NUMBER), data_dt (DATE), and data_value (NUMBER).
    There is a primary key on id and data_dt.
    I want to select the record with the latest data_dt for each unique id.
    What is the best way to do this?
    I have three different methods, but there may be something I am missing.
    First:
    SELECT *
    FROM
      SELECT id, data_dt, data_value,
             FIRST_VALUE(data_dt)
             OVER (PARTITION BY id ORDER BY data_dt DESC) AS last_data_dt
      FROM the_table
    WHERE data_dt = last_data_dt;(I use ORDER BY...DESC instead of just ORDER BY so I don't need the ROWS BETWEEN clause)
    Second:
    SELECT t1.*
    FROM the_table t1
    JOIN
      SELECT id, MAX(data_dt) AS last_data_dt
      FROM the_table
      GROUP BY id
    ) t2 ON (t2.id = t1.id AND t2.data_dt = t1.data_dt);Third:
    SELECT t1.*
    FROM the_table t1
    WHERE t1.data_dt =
      SELECT MAX(t2.data_dt)
      FROM the_table t2
      WHERE t2.id = t1.id
    );-- Don

    Hi,
    There are more possible scenario's, for example:
    select t1.*
    from   the_table t1
    where not exists ( select null
                       from   the_table t2
                       and    t2.data_dt > t1.data_dt
    What is the best way to do this?Only you can tell:
    Test all scenario's, check the execution plans, set timing on and pick the best/fastest one ;-)
    If it's not clear, please post the execution plans here.

  • Best way to check the data

    I have a made some changes to an existing view. The change is adding a join and a new column from new table. I have created a version2 with all these changes. I want to make sure that same data exists in both the views. what is the best way to test the data.

    Bad wording, the query results could be:
    No rows selected. Same number of rows on both views and same data (considering view1 structure and view without the new column)
    At least one row selected. If the count(*) on both was different, rows returned will be at least the difference. If the count was the same, then every returned row means that there's no equivalent row on view2 and a data difference may exist in at least one of the fields, so You have to find the equivalent row on view2 to compare.
    On the query sintaxis, as view2 hava a new column and I guess it's not a constant value, You have to specify every column for the view1, and the same columns for view2, so new field isn't included and compared.

Maybe you are looking for