Build the query in PLSQL to return well formed XML with multiple records

Hello

It's very urgent. I am creating a PLSQL query who must retrieve all records in the table of "tbl_Emp" oracle database in a well-formed xml format. The format is given below

* < employees xmlns = "http://App.Schemas.Employees" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" > *.
* < employee > *.
* < name > < / name >. *
* < Last_Name > < / Last_Name > *.
* < / employee > *.
* < employee > *.
* < name > < / name >. *
* < Last_Name > < / Last_Name > *.
* < / employee > *.
*...*
* < / employees > *.

To retrieve data in above format, I tried to create a query for a long time as below

SELECT XMLElement ('employees',
XMLAttributes ('http://App.Schemas.Employees' AS 'xmlns',
(* "http://www.w3.org/2001/XMLSchema-instance" AS "xmlns: xsi"), *.
XMLElement ("employee", XMLForest (First_Name, Last_Name)))
AS 'RESULT '.
OF tbl_Emp;

But it does not give me the desired output. It creates the < Employees > tag with each individual record which I didn't need. I need tag < Employees > the root tag and the tag < employee > repeat and wrap each individual record. Please help me in that it's very urgent. Thank you.

Hello

Remember that nothing is 'urgent' here, and repeating it will probably produce the opposite effect.

If you need a quick answer, provide all necessary details, in the first place:
-version of db
-test with sample data and DDL cases

That being said, it's easy, it takes group using XMLAgg:

SELECT XMLElement("Employees"
       , XMLAttributes(
           'http://App.Schemas.Employees' AS "xmlns"
         , 'http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi"
         )
       , XMLAgg(
           XMLElement("Employee"
           , XMLForest(
               e.first_name as "First_Name"
             , e.last_name  as "Last_Name"
             )
           )
         )
       ) AS "RESULT"
FROM hr.employees e
;

Tags: Oracle Development

Similar Questions

  • Build the query to select date with status

    Hi guys,.

    Grateful if you can advise me on how to build the query on below scenario:

    Table A

    Date

    11.44.39.000000000 12-OCT-14 AM ASIA/SINGAPORE

    11.44.35.000000000 16-SEP-14 AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE

    The result of the query:

    Date                                                                                            Status

    11.44.39.000000000 12-OCT-14 AM ASIA / SINGAPORE inactive

    11.44.35.000000000 16-SEP-14 active AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE inactive

    Basically, the logic, I wanted is

    Active principles: today date or max (date) < sysdate

    Otherwise will be inactive

    And there is 1 active date in time.

    Thanks in advance

    Hello

    2753165 wrote:

    Hi guys,.

    Grateful if you can advise me on how to build the query on below scenario:

    Table A

    Date

    11.44.39.000000000 12-OCT-14 AM ASIA/SINGAPORE

    11.44.35.000000000 16-SEP-14 AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE

    The result of the query:

    Date                                                                                            Status

    11.44.39.000000000 12-OCT-14 AM ASIA / SINGAPORE inactive

    11.44.35.000000000 16-SEP-14 active AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE inactive

    Basically, the logic, I wanted is

    Active principles: today date or max (date)<>

    Otherwise will be inactive

    And there is 1 active date in time.

    Thanks in advance

    Sorry, we don't know what you want.

    Are you saying that 1 row (maximum) can be assigned status = 'Active' and if 2 or more lines are eligible, the last of them will be called 'Active'?

    If so:

    CASE

    WHEN tmstmp<=>

    OR ROW_NUMBER () OVER (PARTITION BY CASE

    WHEN tmstmp<=>

    THEN "could be."

    ANOTHER 'No Way'

    END

    ORDER BY tmstmp DESC

    )  = 1

    THEN "active."

    ELSE 'inactive '.

    END

    If you would care to post CREATE TABLE and instructions INSERT for some samples, so I could test it.

    DATE is not a very good name for a column, especially if the column is a TIMESTAMP, not a DATE.  I called the TMSTMP instead of the DATE column.

  • procedure that will dynamically build the query data and table Medallion

    Hi people,

    I write a procedure that dynamically build the query data and insert in the table "dq_summary".
    enforcement procedure with success and data not inserted into the table 'dq_summary '.

    I have thin problem in code attached below
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOR rep IN cur_di_attr
          LOOP
            dbms_output.put_line ('d: ');   
            
            BEGIN
              EXECUTE IMMEDIATE 'SELECT table_name FROM ' || sum_tab || ' WHERE id = ' || rep.attribute_id INTO rep_tab;
              dbms_output.put_line ('rep_tab: '||rep_tab);
              run_query := run_query || ' ' || rep_tab || ' WHERE ' || nvl(wh_cond, '1 = 1');
              EXECUTE IMMEDIATE run_query INTO end_rslt;
            
              EXECUTE IMMEDIATE 'UPDATE dq_summary SET ' || prop || '_' || p_code || ' = ' || end_rslt || ' WHERE attribute_id = ' || rep.attribute_id;
              dbms_output.put_line ('e: ');      
              dbms_output.put_line ('rep_tab: '||rep_tab);
              dbms_output.put_line ('end_rslt: '||end_rslt);
              dbms_output.put_line ('f: '); 
            EXCEPTION
              WHEN no_data_found THEN
                rep_tab := '';
                sum_tab := '';
            END;  
          
          END LOOP;    
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    but in the procedure below must be run several times
    create or replace
    PROCEDURE DQ_REPORT_PROC
    AS
      prop                              di_proposition.pro_name%type;
      col_var                           VARCHAR2(100);
      p_code                            dq_parameter.para_code%type;
      sum_tab                           di_proposition.summary_table%type;
      run_query                         dq_parameter.run_query%type;
      wh_cond                           dq_parameter.where_cond%type;
      end_rslt                          VARCHAR2(20);
      rep_tab                           VARCHAR2(50);
      v_error_msg                       VARCHAR2(200);   
      v_error_code                      VARCHAR2(200);  
      v_object_name                     VARCHAR2(50)                          DEFAULT 'DQ_REPORT_PROC';
      v_iss_no                          VARCHAR2(20)                          DEFAULT NULL;
      CURSOR cur_di_prop IS 
        SELECT upper(replace(replace(pro_name, ' '),'-')) pro_name
          FROM di_proposition;
      
      CURSOR cur_di_para IS
        SELECT upper(para_code) para_code, run_query, where_cond
          FROM dq_parameter;
      
      CURSOR cur_di_attr IS 
        SELECT attribute_id
          FROM dq_summary;
    BEGIN
      
      DELETE FROM dq_summary;
    
      INSERT INTO dq_summary (attribute_id, entity_name, attribute_name, data_champ) 
        SELECT a.attribute_id, b.entity_name, a.attribute_name, a.data_champ
          FROM di_attribute_master a, di_entity_master b
         WHERE a.entity_id = b.entity_id;
    
      FOR c_prop IN cur_di_prop
      LOOP
        prop := c_prop.pro_name;
        
        BEGIN
          SELECT distinct SUBSTR(column_name, 1, INSTR(column_name, '_')-1), summary_table
            INTO col_var, sum_tab
            FROM user_tab_cols a, di_proposition b
           WHERE a.table_name = 'DQ_SUMMARY'
             AND upper(replace(replace(b.pro_name, ' '),'-')) = prop
             AND SUBSTR(a.column_name, 1, INSTR(a.column_name, '_')-1) = upper(replace(replace(b.pro_name, ' '),'-'))
             AND upper(b.status) = 'Y';
             
             dbms_output.put_line ('col_var: '||col_var);
             dbms_output.put_line ('sum_tab: '||sum_tab);
             
        EXCEPTION
          WHEN no_data_found THEN
            col_var := '';
            sum_tab := '';
        END;
    
        dbms_output.put_line ('a: ');
    
        FOR para IN cur_di_para
        LOOP
         dbms_output.put_line ('b: ');
          p_code := para.para_code;
          run_query := para.run_query;
          wh_cond := para.where_cond;
          dbms_output.put_line ('c: ');
          FOR rep IN cur_di_attr
          LOOP
            dbms_output.put_line ('d: ');   
            
            BEGIN
              EXECUTE IMMEDIATE 'SELECT table_name FROM ' || sum_tab || ' WHERE id = ' || rep.attribute_id INTO rep_tab;
              dbms_output.put_line ('rep_tab: '||rep_tab);
              run_query := run_query || ' ' || rep_tab || ' WHERE ' || nvl(wh_cond, '1 = 1');
              EXECUTE IMMEDIATE run_query INTO end_rslt;
            
              EXECUTE IMMEDIATE 'UPDATE dq_summary SET ' || prop || '_' || p_code || ' = ' || end_rslt || ' WHERE attribute_id = ' || rep.attribute_id;
              dbms_output.put_line ('e: ');      
              dbms_output.put_line ('rep_tab: '||rep_tab);
              dbms_output.put_line ('end_rslt: '||end_rslt);
              dbms_output.put_line ('f: '); 
            EXCEPTION
              WHEN no_data_found THEN
                rep_tab := '';
                sum_tab := '';
            END;  
          
          END LOOP;    
        END LOOP;
      END LOOP; 
      COMMIT;   
    EXCEPTION
          WHEN OTHERS THEN
             v_error_msg   := SQLERRM;
             v_error_code  := SQLCODE;  
             TRACKER_LOG_EXECEPTION(v_iss_no, v_object_name, CURRENT_TIMESTAMP, v_error_msg, v_error_code);
          COMMIT;        
      
    END DQ_REPORT_PROC;
    Published by: BluShadow on February 7, 2012 12:04
    addition of {noformat}
    {noformat} tags.  Please read {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    903830 wrote:

    I write a procedure that dynamically build the query data and insert in the table "dq_summary".
    enforcement procedure with success and data not inserted into the table 'dq_summary '.

    I'm sorry. But there is no kind of say that way. The code is undesirable. The approach is wrong. This will not happen. This will cause the fragmentation of memory in the shared Pool. This will lead to another session being impossible to analyze the sliders because of the fragmented memory.

    Not only that. The underlying data model is questionable.

    All this seems a candidate perfect as an example of how NOT to design and code and use Oracle.

  • How to build the query SQL for indexes work based on data - dict.?

    Hello

    I want to build the index 'create' - statement to all indexes have worked-based on the data dictionary.

    For example:
    create indexes tab1.ind1
    on tab1 (lower (col3), lower (col1), col2, col4)
    Tablespace "index."

    I know I'll find all needed information views all_indexes, all_ind_columns and all_ind_expressions. During the generation of the create statement for the index of the order of the indexed columns must be correct (the order of the indexed column can be achieved using the "position_colonne" column of seen all_ind_columns and all_ind_expressions). But what would be the best way to provide all the necessary information in the right order?
    One way would be a PLSQL procedure that puts it all together - but is it possible to use a single SQL statement?

    Any help will be appreciated.

    Rgds
    JH

    You can try using DBMS_METADATA. GET_DDL:

    SQL> show user;
    USER is "TEST"
    SQL> drop table t;
    
    Table dropped.
    
    SQL> create table t(x varchar2(10));
    
    Table created.
    
    SQL> create index i on t(upper(x));
    
    Index created.
    
    SQL> select dbms_metadata.get_ddl('INDEX','I','TEST') from dual;
    
    DBMS_METADATA.GET_DDL('INDEX','I','TEST')
    --------------------------------------------------------------------------------
    
      CREATE INDEX "TEST"."I" ON "TEST"."T" (UPPER("X"))
      PCTFREE 10 INITRANS 2 MAXTRANS 255
      STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
      PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
      TABLESPACE "USERS"
    
  • Need help to build the query

    Hello

    I got the info from a table named X.

    Col1 Col2 Col3 Col4
    IT01 20 01 X
    IT01 20 50 X
    IT01 30 01 X
    IT01 30 50 X

    If the value of "X" all 4 combinations of Col2 and Col3, Col4 the result should be displayed as

    Col1, Col4
    IT01 X

    If the actual values are as
    Col1 Col2 Col3 Col4
    IT01 20 01 X
    IT01 20 50 X
    IT01 30 01 X
    30 50 IT01 Y

    The result should be displayed as

    Col1, Col4
    IT01 Y

    How will generate the query for this?

    Thank you
    Thomas Titus

    Published by: Titus Thomas on April 20, 2010 14:48

    Try this:

    with test_tab as (select 'ITO1' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 30 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 30 Col2, 50 Col3, 'Y' Col4 from dual)
    --- end of mimicking your data; use SQL below:
    select col1, max(col4) col4
    from   test_tab
    group by col1;
    
    COL1 COL4
    ---- ----
    ITO2 Y
    ITO1 X   
    
  • Not well-formed XML from CF?

    I worked through the training from the Source Flex2 book (trapper, Boles, Talbot, etc.). In Lesson 17, this is to access the objects on the server side.

    A piece of code accesses a CF model, which brings in an XML file:
    -----
    < mx:HTTPService id = "prodByCatRPC".
    ' URL =' http://localhost/flexGrocer/xml/categorizedProducts.cfm '
    result = "prodByCategoryHandler (Event)" "
    resultFormat = "e4x" / >
    -----
    The CF file of the book plate has the following:
    ----
    < name cfheader = "Expires" value = "#now ()" # "/ >"

    < cfxml variable 'x' = >
    < cfinclude template = "categorizedProducts.xml" >
    < / cfxml >

    < cfset xmlObject = ToString (xProducts) >

    < cfcontent type = "text/xml" / >
    #variables.xmlObject # < cfoutput > < / cfoutput >
    -----
    Using the Flex file, I get a Runtime message that seems to indicate that the XML is not well-formed. (Here's a bit of the message, not sure that I understand it!) :

    [CPP faultString = error "" error #1088: the markup in the document following the root element must be well formed. "faultCode =" Client.CouldNotDecode"faultDetail ="null"]

    I'm ASSUMING that the CF page does not return the xml as you wish, because if I simply change the flex http service call in the xml file that the CF page is notably, the flex application runs as scheduled and without errors:
    ----
    ' URL =' http://localhost/flexGrocer/xml/categorizedProducts.xml '
    ----

    (something in the mech detachment made the statement url above messed, but you probably get what I mean)

    I'm a CF developer and have not used the exact method of the book to get the generated XML from CF, I did so successfully for Spry and other things.
    I tried some ot the things I had to do to get the CF generated XML to work in Spry with this flex, but nothing helped. Tried to add a reset = "true" with the tag cfcontent; " tried to wrap the cfcontent to output; added cfprocessing tags to suppresswhitespace.

    Appreciate all the thoughts/help on how to solve this problem. In addition, if others agree that the problem is with the XML that is generated rather than anything else.

    Thank you
    Keith

    After experimenting with several, I found the problem: didn't set the parameters of CF to NOT see the debug output. Make this setting, makes everything work fine.

    Oh, the little things that cause big problems!

    Keith

  • Need help to build the query/pl-sql block to get the query result and the name of column from DB table in the form of key-value pairs.

    Hi Experts,

    I have a DB table has columns of more than 50.

    I question this table, it should only return one line at any time. as sqldeveloper below image.

    here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.

    Eg:     Key                         -  Value

    TASK_EVENT_ID - 1765

    EVENT_TYPE - ASR_UPDATE

    ... etc until all of the columns in my table.

    Experts please comment on that point, appreciate your help on this.

    Thank you

    -Vincent.

    Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)

    create or replace procedure (task_expired)

    v_store_id in full,

    v_task_action_id in full,

    v_job_id in full

    )

    as

    -[SNIP code...]

    v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123';  -Your SQL here!

    v_v_val VARCHAR2 (4000);

    v_n_val NUMBER;

    v_d_val DATE;

    v_ret NUMBER;

    c NUMBER;

    d NUMBER;

    col_cnt INTEGER.

    f BOOLEAN;

    rec_tab DBMS_SQL. DESC_TAB;

    col_num NUMBER;

    vAsString VARCHAR2 (4000);

    BEGIN

    -[SNIP code...]

    Message_properties. CORRELATION: = "EDF_EVENT";

    MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();

    Msg.set_string_property ('queueName', ' shipping/csi_cth');

    Msg.set_string_property ('MODE', 'CR8');

    c: = DBMS_SQL. OPEN_CURSOR;

    DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);

    d: = DBMS_SQL. Execute (c);

    DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);

    1.col_cnt J

    LOOP

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val);      -Number

    WHEN 12 CAN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val);      -Date

    ON THE OTHER

    DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000);   -Else treat as varchar2

    END CASE;

    END LOOP;

    LOOP

    v_ret: = DBMS_SQL. FETCH_ROWS (c);

    WHEN OUTPUT v_ret = 0;

    1.col_cnt J

    LOOP

    -Fetch each column to the correct data type based on coltype

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);

    vAsString: = to_char (v_n_val);

    WHEN 12 CAN

    DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);

    vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');

    ON THE OTHER

    DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);

    vAsString: = v_v_val;

    END CASE;

    Msg.set_string_property (rec_tab (j) .col_name, vAsString);

    END LOOP;

    END LOOP;

    DBMS_SQL. CLOSE_CURSOR (c);

    DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',

    Enqueue_options => Enqueue_options,

    Message_properties => Message_properties,

    Payload-online msg,

    Msgid => Message_handle);

    dbms_output.put_line ('00 Msgid =' |) Message_handle);

    dbms_output.put_line('===Done=');

    -[SNIP code...]

    END;

    /

  • Need help to build the query to group the lines

    Hello all, hope someone can help me with this. I am working in Oracle 11 g PL/SQL 11.2.0.2.0.

    I have the following query, which does exactly what I need, but I have been invited to consolidate the results in a specific way and I can't do that. First of all the existing request:
    SELECT facility_id
    ,facility_type
    ,COUNT (CASE WHEN component_type = 'ATTACH2NDPARTY' THEN 1 END) AS ATTACH2NDPARTY
    ,COUNT (CASE WHEN component_type = 'ATTACH3RDPARTY' THEN 1 END) AS ATTACH3RDPARTY
    ,COUNT (CASE WHEN component_type = 'BREAKERGT' THEN 1 END) AS BREAKERGT
    ,COUNT (CASE WHEN component_type = 'BREAKERUSS' THEN 1 END) AS BREAKERUSS
    ,COUNT (CASE WHEN component_type = 'CAPACIFORMER' THEN 1 END) AS CAPACIFORMER
    ,COUNT (CASE WHEN component_type = 'CAPACITOR' THEN 1 END) AS CAPACITOR
    ,COUNT (CASE WHEN component_type = 'CEFIBEROPTIC' THEN 1 END) AS CEFIBEROPTIC
    ,COUNT (CASE WHEN component_type = 'ELASTIDISCONN' THEN 1 END) AS ELASTIDISCONN
    ,COUNT (CASE WHEN component_type = 'NETWORKPROTECT' THEN 1 END) AS NETWORKPROTECT
    ,COUNT (CASE WHEN component_type = 'POLE' THEN 1 END) AS POLE
    ,COUNT (CASE WHEN component_type = 'REACTOR' THEN 1 END) AS REACTOR
    ,COUNT (CASE WHEN component_type = 'RECLOSER3PUPOIL' THEN 1 END) AS RECLOSER3PUPOIL
    ,COUNT (CASE WHEN component_type = 'RECLOSERTSUP' THEN 1 END) AS RECLOSERTSUP
    ,COUNT (CASE WHEN component_type = 'RECLSR3PCNTRL3A' THEN 1 END) AS RECLSR3PCNTRL3A
    ,COUNT (CASE WHEN component_type = 'RECLSR3PCNTRLNT' THEN 1 END) AS RECLSR3PCNTRLNT
    ,COUNT (CASE WHEN component_type = 'RECLSRTSCNTRL' THEN 1 END) AS RECLSRTSCNTRL
    ,COUNT (CASE WHEN component_type = 'RECTIFIERUSS' THEN 1 END) AS RECTIFIERUSS
    ,COUNT (CASE WHEN component_type = 'REGULATORJOINT' THEN 1 END) AS REGULATORJOINT
    ,COUNT (CASE WHEN component_type = 'REGULATOROH' THEN 1 END) AS REGULATOROH
    ,COUNT (CASE WHEN component_type = 'REGULATORUSS' THEN 1 END) AS REGULATORUSS
    ,COUNT (CASE WHEN component_type = 'RMS' THEN 1 END) AS RMS
    ,COUNT (CASE WHEN component_type = 'SPLICEPRIMARY' THEN 1 END) AS SPLICEPRIMARY
    ,COUNT (CASE WHEN component_type = 'STREETLIGHT' THEN 1 END) AS STREETLIGHT
    ,COUNT (CASE WHEN component_type = 'SWITCHSCADA' THEN 1 END) AS SWITCHSCADA
    ,COUNT (CASE WHEN component_type = 'TAPCHANGER' THEN 1 END) AS TAPCHANGER
    ,COUNT (CASE WHEN component_type = 'TRAFFICSIGNAL' THEN 1 END) AS TRAFFICSIGNAL
    ,COUNT (CASE WHEN component_type = 'TRANSF480' THEN 1 END) AS TRANSF480
    ,COUNT (CASE WHEN component_type = 'TRANSFGROUND' THEN 1 END) AS TRANSFGROUND
    ,COUNT (CASE WHEN component_type = 'TRANSFISOLATION' THEN 1 END) AS TRANSFISOLATION
    ,COUNT (CASE WHEN component_type = 'TRANSFOH' THEN 1 END) AS TRANSFOH
    ,COUNT (CASE WHEN component_type = 'TRANSFUG' THEN 1 END) AS TRANSFUG
    ,COUNT (CASE WHEN component_type = 'TRANSFURD' THEN 1 END) AS TRANSFURD
    ,COUNT (CASE WHEN component_type = 'TRANSFUSS' THEN 1 END) AS TRANSFUSS
    FROM (SELECT fy.id AS facility_id
          ,fy.external_facility_id
          ,fy.flty_facility_type as facility_type
          ,cp.cpty_component_type as component_type
          FROM facilities fy
          LEFT OUTER JOIN components cp
          ON cp.facility_id= fy.id
          ORDER BY fy.id DESC)
    GROUP BY facility_id, facility_type
    I was asked to do, is to display a number of facility_type who have each of the combinations of the 'DEAL' 33 areas. Installation types are strings. So an expected result would look something like:

    FACILITY_TYPE | ATTACH2NDPARTY | ATTACH3RDPARTY | BREAKERGT | ... TRANSFUSS | COUNTY
    MANHOLE X X 10
    MANHOLE X X 22
    POLE X X 5

    and so on. Because there are 33 BUSINESS areas and therefore 33! possible combinations, I was thinking about a sort of loop would achieve the desired result, but I'm stuck and could really use a shot in the arm. Any help will be appreciated and obtained points! Thanks in advance.
    select
     facility_type
    ,ATTACH2NDPARTY
    ,ATTACH3NDPARTY
    -- and so on
    , count(*) cnt
    from (
    --your query
    SELECT facility_id
    ,facility_type
    ,COUNT (CASE WHEN component_type = 'ATTACH2NDPARTY' THEN 1 END) AS ATTACH2NDPARTY
    ,COUNT (CASE WHEN component_type = 'ATTACH3RDPARTY' THEN 1 END) AS ATTACH3RDPARTY
    ,COUNT (CASE WHEN component_type = 'BREAKERGT' THEN 1 END) AS BREAKERGT
    ...
    )
    group by
     facility_type
    ,ATTACH2NDPARTY
    ,ATTACH3NDPARTY
    -- and so on like in projection
    
  • Help build the query

    In order to explain my problem, I'll give my data first and then explain what I am trying to accomplish.

    Oracle: 10g

    Table = tb.xInfo
    NAME       STYLE    YEAR    AMOUNT    SEC_ID
    BOB          BLUE      1995         6              1
    BOB          BLUE      1996         8              1 
    BOB          BLUE      1997         7              1
    CHRIS        RED        1995        4              1
    CHRIS        PURPLE   1996        8              1
    CHRIS        RED         1997       5              1
    DAN          YELLOW   1995      9               1
    DAN          YELLOW   1996      4               1
    DAN          YELLOW   1997      1               1
    "So what I try to do based on the above data is: summarize all specific amounts, exit it years in years like 1995-1997 column" and all styles of there in the column style, with Chris, I want out of his STYLE values separated by a comma.

    Desired result set
    NAME       STYLE            YEAR             AMOUNT 
    BOB         BLUE              1995-1997           21
    CHRIS      RED, PURPLE    1995-1997           17
    DAN        YELLOW           1995-1997           14
    This is the code I tried but did not have much success:
    select name, 
             (CASE
                      WHEN count(style) = 2 THEN
                            STYLE || ', ' || STYLE
                      ELSE
                            STYLE
             END) as style,
             '1995-1997' AS YEAR
             SUM(AMOUNT) as amount
    from
               (
               select name, 
                          style, 
                          year, 
                          amount
               from  
                           tb.xInfo
               where year in (1995,1996,1997)
               and     sec_id = 1
               and name
               )
    Group by name, style, amount
    The above doesn't seem to work.

    Hello

    Here is an example of SYS_CONNECT_BY_PATH, using the example of data published by Mwooldridge:

    WITH     got_style_num     AS
    (
         SELECT DISTINCT
              name
         ,     style
         ,     SUM (amount)  OVER ( PARTITION BY  name)     AS total_amount
         ,     DENSE_RANK () OVER ( PARTITION BY  name
                                   ORDER BY          style
                           )                    AS style_num
         FROM    msw_test
         WHERE     year     IN (1995, 1996, 1997)
         AND     sec_id     = 1
    )
    SELECT  name
    ,     LTRIM ( SYS_CONNECT_BY_PATH (style, ', ')
               , ', '
               )               AS styles
    ,     '1995-1997'          AS years
    ,     total_amount
    FROM     got_style_num
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     style_num     = 1
    CONNECT BY     style_num     = PRIOR style_num + 1
         AND     name          = PRIOR name
    ;
    

    Create dynamically the years column, as did Mwooldrige, is a good idea. To modify the above query, use the MIN and MAX functions analytical in the subquery got_style_num.
    Alternatively, you can use the SYS_CONNECT_BY_PATH to generate a string like ' 1995, 1996, 1997. This could be very useful if some names, it was missing a few years; then you might get results like ' 1995, 1997' or '1995' dynamically.

    The above query lists the styles alphabetically. In the sample data you posted, you RED prior to VIOLET. If it's important, explains what order you want.

  • How to return a single LINE with Multiple value separated by a colon in a SQL query

    Hello

    I have a SQL, as shown.
    select deptno
      from dept
    I want to mofidfy this query, so that it should return me departments with colon delimeted list in a ROW.
    10:20:30:40.......
    Thank you
    Deepak
  • Impossible to uncheck "extend the desktop on this monitor option" when you work with multiple monitors.

    Title: Cancellation of the DESKTOP EXTENSION

    I am wanting to "uncheck" the 'extend the desktop to this monitor "... It's 'grey '.  How can I fix?

    Hi Goldie01,

    I understand that you are haivng problem with the connection of multiple monitors. I'll be happy to help you with this problem.
     
    (1) have you tried to connect the monitor directly on the CPU and check?
    (2) have you made changes on the computer before this problem?
     
    Method 1: I suggest you run the Microsoft FIXIT from the link and if it helps.
    Hardware devices do not work or are not detected in Windows
     
    Method 2: I also suggest you follow the steps to configure and change the display on multiple monitors of links and check if that helps.
     
    For reference:
     
    Method 3: Also, I suggest you to update the graphics card drivers and check if it helps.
     
    I hope it helps. If you have problems in the future, please let us know. We will be happy to help you.
  • How can I change the pdf file cannot be modified, but hold down the scroll button for the form fields with multiple lines?

    I need all the information to display so I need the scroll key to work, but it is not editable.

    Thanks for the help!

    Tania

    You can define a field with strike and validate to prevent the user from changing the value of the field. First, set the field to multiline and 'Scroll long text' and the default value for the text to display in the field. Then add a custom script to strike which is:

    Custom keystroke script

    Event.RC = false;

    and to be complete, the validation script customized according to:

    Custom validation script

    If (event.value! == event.target.defaultValue) event.rc = false;

    These scripts will prevent the value to be changed, at least in Acrobat and Reader if JavaScript is enabled.

  • You try to recover the editValue of a selection from a list box with multiple selections

    I have a requirement to display the text and the value of a list of multiple choice box, but as soon as there are several selections, the value displayed is the rawValue.

    My code is something like this:

    verifSubTaskDescID.addItem (this.editValue);

    verifSubTaskDesc.addItem (this.rawValue);

    If 'this' which is an area of list ['a', 'first'] ['b', 'second'] is set to a or b it works perfectly, showing 'a' in the code and the 'first' in the Desc as follows:

    a first

    OR

    second b

    but when I select both this list looks like this:

    First Prime

    second second

    Any ideas on how to preserve the letters without making the code too complex or difficult to maintain?

    Thank you!!!

    JavaScript appears to be similar:

    var r = "";
    for (var i = 0; i < this.dataNode.nodes.length; i += 1) {
              r += this.dataNode.nodes.item(i).value + " " + this.getDisplayItem(i) + "\n";
    }
    
    Textfield1.rawValue = r;
    
  • Build the string separated by commas in query with Expression box sub

    Oracle 10g on Windows XP

    Consider the following query:

    Select batch_id, tr state_tag_seq where request_type in (select case WHEN PX = 'RETURN' AND 'TRANSFER' |) «, » || "PUBLIC TRANSIT"
    WHEN PX = "RFT" THEN "TRANSIT".
    ELSE 'Invalid '.
    END
    OF THE DOUBLE
    ) ;


    In this case, PX is accepted to execution of the user interface.

    I'm having no rows returned (all valid lines matching in DB) for the following case assessment

    WHEN PX = 'RETURN' THEN 'TRANSFER '. «, » ||' Transit "(PX when is evaluated to 'RETURN')

    The application works well when it px IS estimated to be "PCR" (as the evaluated expression is just a string ('TRANSIT') single, not separated by commas, as in the other case)

    Hiow do rewrite this query, if it gives a correct result? In other words, I actually build the query string slot, which is assessed by the external when query clause.

    I think it might be a specific way to use quotes in my case expression, but I'm reaching an impasse. Any help is appreciated.

    Thank you
    SR

    You can try

    select batch_id, state_tag_seq
      from tr
     where request_type member of case
                             when px = 'RETURN'
                             then
                              sys.dbms_debug_vc2coll (
                               'TRANSFER',
                               'TRANSIT'
                              )
                             when px = 'RFT'
                             then
                              sys.dbms_debug_vc2coll ('TRANSIT')
                             else
                              sys.dbms_debug_vc2coll ('Invalid')
                             end
    
  • When you perform the query from the query, it assumes that the field is numeric

    I have a query that has 30 some files inside from an AS400 file. Now, when I do a query on the query, he thinks one of the columns is a numeric field, even if it is not. Now I do the same thing with another query (with the same file and fields, just different data) and it works fine.

    This is the error I get: the 73 "d" value cannot be converted to a number

    This column looks like this for example
    75
    75
    71
    71
    75
    73
    75
    63%
    etc. (the 73D is the only one in this column)

    Now in the query of queries I question not even this field (there are about 10 fields in the query, and I want the results of one) and then I get the above error. Any ideas?

    Thanks in advance,
    CJ

    CJ wrote:
    > I have a query that has 30 some files inside from an AS400 file. Now when I do

    you create the original query? If so, create the AND define the data types:

    newQ = QueryNew ("user, lastLogin, manager", "varChar, time, bit");

    > a query on the query, he thinks one of the columns is a digital, same field
    > if it's not. Now do the same thing with another application (with the same file
    (> and fields, just different data) and it works fine.
    >
    > This is the error I get: the 73 "d" value cannot be converted to a
    > number
    >
    > This column looks like this for example
    > 75

    CF will build the query result based on the first line of data (if you are not
    define the data types in the original query), which resembles digital data.

    > 73D

    Thus, when it hits this row it will fail.

    If you do not use the data in that column, and then not put it back. Otherwise, use it.
    Method CAST dan suggested.

Maybe you are looking for

  • Cannot shut down Windows XP properly.

    I have a portable satellite 1110. I am facing a problem then the closure of the system. When I try to stop the system hangs on the blue screen saying "closing windows. I have to manually shut down the system.Any help on this would be appreciated.

  • Will expects G4 most camera update compromised quality for performance?

    Admins are speaking of this upcoming update. Will this affect the quality of the photos and videos much? I mean tweaking the camera can translate into a poor stabilization of the videos. Is this possible?

  • What is Zeooptimizer, received a call from them on viruses

    I was contacted by phone (unknown name, unknown number) of the India to report to me that my computer had many, many of the viruses. This person had control over my computer and wanted that I relicence my computer for $149.00 per year or $199.00 for

  • Why have I not code 12 on ide controlier

    Hello world Just to let you know that I am new to this forum thing, because I don't know enough about software issues or how to solve a problem with my PC, I leave this to you guys. I just want to say too, I'm sure that I'll make mistakes here so now

  • mapped to the server drives

    I have a new windows 7 pc pro and you want to connect to a server writers. The server is Windows server 2012 R2 I can connect only to readers of server by IP address. If I try to connect using the server name, I get an error 0 x 80070035. The other P