Count queries and hierarchical

Hi Oracle SQL gurus,

Need your help in getting the counts of children for each parent - relationship to child using a hierarchical query.

BANNER
Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
AMT for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL VERSION 10.2.0.1.0 - PRODUCTION


Set of data to the top:

SELECT 1 AS PROJECT,-1 AS PARENT_ID, CHILD_ID OF DOUBLE 1
UNION
SELECT 1, 1, 2 DOUBLE
UNION
SELECT 1, 2, 3, THE DOUBLE
UNION
SELECT 1, 3, 4 OF THE DOUBLE
UNION
SELECT 2, -1, 5 DOUBLE
UNION
SELECT 3, -1, DOUBLE 6
UNION
SELECT THE 3, 6, 7 DOUBLE

Expected results:

SELECT 1 AS project, -1 AS PARENT_ID, CHILD_ID AS, 4 as EXPECTED_ROW_COUNT FROM DUAL 1
UNION
SELECT 1, 1, 2, 3 DOUBLE
UNION
SELECT 1, 2, 3, 2 OF THE DOUBLE
UNION
SELECT 1, 3, 4, 1 DOUBLE
UNION
SELECT 2, -1, 5, 1 DOUBLE
UNION
SELECT 6-1, 2, 3 DOUBLE
UNION
SELECT 3, 6, 7, 1 FROM DUAL;


Help, please.

Thank you in advance.

Hello

Here's one way:

SELECT       project_id, parent_id, child_id
,        COUNT (*)     AS expected_row_count
FROM       table_x
CONNECT BY     child_id     = PRIOR parent_id
GROUP BY  project_id, parent_id, child_id
;

Tags: Database

Similar Questions

  • What is the difference between write queries and written per second in vCOPs?

    I had on my farm performance problem, when I try to understand by vCOPs I noticed there are two similar measures write queries and writes per second.

    Do you know what is the different between the two measures?

    IO reqs vs real E/s is written. Reqs will be usually higher and includes administrative scsi commands. Written per second is closer to PAHO are / s.

  • Legacy and hierarchical queries

    Hi all

    Using the RDBMS 11.2.0.3, I would like to know if there was a way to "inherit" a parent row values when you use a hierarchical query.

    For example, with these values:

    CREATE TABLE foohh (
     id NUMBER,
     parent NUMBER,
     name VARCHAR2(64),
     continent VARCHAR2(32)
    );
    
    INSERT INTO foohh VALUES ( 1, null, 'United States', 'AMERICA' ) ;
    INSERT INTO foohh VALUES ( 2, 1, 'California', null ) ;
    INSERT INTO foohh VALUES ( 3, 2, 'San Francisco', null ) ;
    INSERT INTO foohh VALUES ( 4, 3, 'Golden Gate', null ) ;
    INSERT INTO foohh VALUES ( 5, null, 'China', 'ASIA' ) ;
    INSERT INTO foohh VALUES ( 6, 5, 'Beijing', null ) ;
    INSERT INTO foohh VALUES ( 7, 6, 'Great Wall', null ) ;
    
    

    I would like to be able to view the continent of all lines.

    The following query returns the leaves, but I don't see their continent:

    SELECT
     id
     ,connect_by_root(parent) parent
     ,sys_connect_by_path(name, '-->') path
     ,nvl( continent, 'unknown' ) continent
    FROM foohh
    WHERE
     connect_by_root(parent) is null
     and connect_by_isleaf=1
    CONNECT BY PRIOR id=parent
    ;
    
    

    CONTINENT OF PARENT ID PATH
    ---------- ---------- ------------------------------------------------------------ ------------------------------
    4-> United States-> California-> San Francisco-> Golden Gate unknown
    7-> China-> Beijing-> great unknown wall

    Is there a clever way to do this?

    Thank you

    Anthony

    Include below in him SELECT query.

    Continent CONNECT_BY_ROOT

  • Synchronization of AO and output counter, arming and triggering the sequence of events

    Hi all

    I'm trying to synchronize a counter (used as a digital pulse) and analogue of a custom waveform output read from the file on a USB-6211. The goal is to always have these running until I hit 'STOP' and to be able to change the position of the pulse relative to each other. I created a VI by combining and modifying the Cont.Gen.Wfm.Int - Clk.Non - Regen.VI and the Continous.VI Gen dig Pulse Train and I'm now able to produce the two signals to the desired frequency, but I can't seem to get the "Initial period" to work correctly. The values that I come home do not seem to match what is happening LeRiz, and the spacing seems to vary from run to run (within each series is constant). In a previous post, Alfred has suggested:

    "Trigger counter outputs out of the trigger to start AO and adjusting the setting 'Initial period' should give you what you are looking for."  Don't forget to start the tasks of meter in the software before the tasks of the AO (if they are armed and ready to go before the start AO is sent). »

    (link here)

    I tried to use the controls and the propertynodes (perhaps incorrectly), but it doesn't seem to make a difference.

    I think what happens is that my arms and firing sequence is not done correctly. I read on as much information as I could about the outbreak and armament, but I don't know that I understand correctly. Most of the examples I found using an external trigger or perform analog input tasks finished. Does anyone have a suggestion on how to start my two tasks in the proper order? Is something else is wrong here?

    Thank you

    Gabe

    P.S. I have attached the VI and a sample waveform read.

    Hi Gabe,

    This is a cleaned of the VI version that should work (you need not adjust the initial deadline on the right fly?).  Instead of reading a file, I made just a simple square wave of 50% to be used for the test.

    Best regards

  • I lost my counter top and I have to go traore manager starts computor

    I have to go through the Manager to open and I lost my counter top

    Hello

    Click Start, type regedit and hit or, from the Task Manager, click on "new task" and type here and click ok. Click on continue in the UAC prompt, expand the branches to:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

    Click the Winlogon key, and then in the right pane locate the rope of the shell. Double click it, replace it content with only:

    Explorer.exe

    Click ok, and then close the registry editor and restart the system. Good luck, Rick Rogers, aka "Crazy" - Microsoft MVP http://mvp.support.microsoft.com Windows help - www.rickrogers.org

  • LEVEL and hierarchical issue

    Hello

    I have a request as follows

    [code]

    Agendasub_orderparent_orderStartDateQty.
    ABC10110031/03/2015100
    ABD10310231/03/2015120
    ABD10410204/01/2015230
    XYZ10610531/03/2015110

    [/ code]

    I'm trying in this output... I tried with LEVEL and Connect by before, but I'm not able to get the result like this

    [code

    AgendaOrderlevel
    ABC1001
    ABC1012
    ABD1021
    ABD1032
    ABD1042
    XYZ1051
    XYZ1062

    [/ code]

    Thank you very much in advance

    You can not use connect by bypassing a hierarchical structure.

    What you get is an output like the one you want without using you connect to.

    with mydata as

    (

    Select the item "ABC", sub_order 101, 100 parent_order, to_date (31 March 2015 ', ' dd/mm/yyyy') startdate, Qty 100 of union double all the

    Select the item 'ABD' sub_order 103, 102 parent_order, to_date (31 March 2015 ', ' dd/mm/yyyy') startdate, 120 qty of union double all the

    Select the item 'ABD' sub_order 104, 102 parent_order, to_date (4 January 2015 ', ' dd/mm/yyyy') startdate, Qty 230 of union double all the

    Select the item "XYZ", sub_order 106, 105 parent_order, to_date (31 March 2015 ', ' dd/mm/yyyy') startdate, Qty 110 double

    )

    Select item, sub_order DSB, lvl 2

    of mydata

    Union

    Select the item, parent_order, 1 lvl

    of mydata

    order by DSB;

    POINT ORD LVL

    ---- ---------- ----------

    ABC 1 100

    ABC 2 101

    102 1 ABD

    103 2 ABD

    104 2 ABD

    105 1 XYZ

    XYZ 2 106

    7 selected lines.

    Kind regards.

    Al

  • mutation in the triggers table problem (need to COUNT (col) and MAX (col) of table shot)

    I was looking for the solution and find many examples, but I do not know what is the best in my option and don't understand everything.

    I realized that can't do a SELECT query in the table where trigger is triggered. But I have need SELECT COUNT (col), then MAX (id) of this table, update some statistical info...
    And also need to row id update, so I can't do trigger of table instead of relaxation of the line.


    So this is my TRIGGER:

    create or replace

    update_stat relaxation

    AFTER UPDATE ON TABLE1 TO EACH LINE

    DECLARE

    juice FLOAT;

    all the NUMBER;

    end NUMBER;

    BEGIN

    IF (: old.ended <>: new.ended) THEN

    SELECT COUNT (id) FROM end FROM table1 WHERE fk_table2 = new.fk_table2 AND finished = 1;  -Error in the table of mutation

    SELECT COUNT (id) FROM everything FROM table1 WHERE fk_table2 = new.fk_table2; -Error in the table of mutation

    Juice: = ((end /all) * 100);

    UPDATE table2 SET suc = success WHERE id =:new.fk_table2;

    END IF;

    END;

    I also tried with

    pragma autonomous_transaction;

     

    trigger body....AND

     

     

    commit;

    But don't working right when insert more records.

    Thanks, Urban

    Data and structure of the example table

    SQL> create table table2
      2  (
      3     id        integer
      4   , success   number
      5   , constraint table2_pk primary key (id)
      6  );
    
    Table created.
    
    SQL> create table table1
      2  (
      3     id        integer
      4   , id_t2     integer
      5   , ended     integer
      6   , constraint table1_pk primary key (id)
      7   , constraint table1_fk_id_t2 foreign key (id_t2) references table2
      8  );
    
    Table created.
    
    SQL> insert into table2(id, success) values (1, 0);
    
    1 row created.
    
    SQL> insert into table2(id, success) values (2, 0);
    
    1 row created.
    
    SQL> insert into table1
      2  (
      3     id
      4   , id_t2
      5   , ended
      6  )
      7  select level
      8       , ceil(level/10)
      9       , 0
     10    from dual
     11  connect by level <= 20;
    20 rows created.
    
    SQL> commit;
    
    Commit complete.
    

    Create objects to the suite

    create or replace type update_stat_obj as object (id integer, id_t2 integer, ended integer)
    /
    create or replace type update_stat_tbl as table of update_stat_obj
    /
    create or replace package update_stat_pkg
    as
       g_table_1 update_stat_tbl;
       procedure load(p_id integer, p_id_t2 integer, p_ended integer);
       procedure updt;
    end;
    /
    show err
    create or replace package body update_stat_pkg
    as
       procedure load(p_id integer, p_id_t2 integer, p_ended integer)
       is
       begin
          if g_table_1 is null then
            g_table_1 := update_stat_tbl();
          end if;
    
          g_table_1.extend;
          g_table_1(g_table_1.count) := update_stat_obj(p_id, p_id_t2, p_ended);
       end;
       procedure updt
       is
       begin
           merge into table2 t2
           using (
                  select t1.id_t2
                       , (count(t2.id)/count(t1.id))*100 success
                    from table1 t1
                    left
                    join table(g_table_1) t2
                      on t1.id    = t2.id
                     and t2.ended = 1
                   group
                      by t1.id_t2
                 ) t1
              on (t2.id = t1.id_t2)
            when matched then
                update set t2.success = t1.success;
    
           g_table_1 := null;
       end;
    end;
    /
    show err
    create or replace trigger update_stat_row_trig after update on table1 for each row
    begin
        if (:old.ended <> :new.ended)
        then
           update_stat_pkg.load(:new.id, :new.id_t2, :new.ended);
        end if;
    end;
    /
    show err
    create or replace trigger update_stat_trig after update on table1
    begin
        update_stat_pkg.updt;
    end;
    /
    show err
    

    Now look for the UPDATE.

    SQL> select * from table1;
    
            ID      ID_T2      ENDED
    ---------- ---------- ----------
             1          1          0
             2          1          0
             3          1          0
             4          1          0
             5          1          0
             6          1          0
             7          1          0
             8          1          0
             9          1          0
            10          1          0
            11          2          0
            12          2          0
            13          2          0
            14          2          0
            15          2          0
            16          2          0
            17          2          0
            18          2          0
            19          2          0
            20          2          0
    
    20 rows selected.
    
    SQL> select * from table2;
    
            ID    SUCCESS
    ---------- ----------
             1          0
             2          0
    
    SQL> update table1 set ended = 1 where id between 1 and 7 or id between 11 and 19;
    
    16 rows updated.
    
    SQL> select * from table2;
    
            ID    SUCCESS
    ---------- ----------
             1         70
             2         90
    
    SQL> select * from table1;
    
            ID      ID_T2      ENDED
    ---------- ---------- ----------
             1          1          1
             2          1          1
             3          1          1
             4          1          1
             5          1          1
             6          1          1
             7          1          1
             8          1          0
             9          1          0
            10          1          0
            11          2          1
            12          2          1
            13          2          1
            14          2          1
            15          2          1
            16          2          1
            17          2          1
            18          2          1
            19          2          1
            20          2          0
    
    20 rows selected.
    
  • items counter webapp and link for details see

    I have two questions about WebItem object:

    1. is it possible to have a counter for the elements of the Web application, as first element has number 1 and so on and have this number in two Details view?

    2. can I have a link to the other point of view of retail, so his binder to the following detail view no. 2 and back section, an overview of the issue?


    Dennis

    Hey there,

    1 counter module web app - http://docs.businesscatalyst.com/dev-assets/reference#! / module-reference/web-apps/module_w ebappscount.html

    By article, you have {tag_counter} - the Developer Reference

    2 as not.

  • One-way replication using queries and mapping DML - error

    Environment: Unique Windows physical system and Oracle 11 g R2 DB of EA. Two schemas with the structure of the different tables. This is a home office staff.
    The order of the day: runs DML replication of 2 tables to another single table with use of query and chips

    Disclaimer: I have read the guide e17791.pdf Admin and checked the forum before asking this question here.

    My excerpt:
    EXTRACT srcextm
    USERID gguser, PASSWORD gguser
    --DDL
    TRANLOGOPTIONS EXCLUDEUSER gguser
    RMTHOST localhost, MGRPORT 7809
    RMTTRAIL G:\app\gg32\dirdat\mt
    TABLE source.*,
    SQLEXEC (ID query2col, QUERY "select a.sno as sno, a.name as name, b.phone as phone from source.test a, source.contact_no b where a.sno=1 and a.sno=b.sno"),
    TOKENS (TK_SNO           = @GETVAL(query2col.sno),
            TK_NAME      = @GETVAL(query2col.name),
            TK_PHONE       = @GETVAL(query2col.phone));
    Replicat:
    REPLICAT srcrepm
    SOURCEDEFS G:\app\gg32\dirsql\sourcedefs.sql
    --DDLERROR DEFAULT IGNORE
    USERID gguser, PASSWORD gguser
    MAP source.*, TARGET target.directory,
    colmap(USEDEFAULTS,
    SNO= @Token("TK_SNO"),
    NAME= @Token("TK_NAME"),
    PHONE= @Token("TK_PHONE"));
    Replicat report:
    ***********************************************************************
                     Oracle GoldenGate Delivery for Oracle
          Version 11.2.1.0.1 OGGCORE_11.2.1.0.1_PLATFORMS_120423.0230
            Windows (optimized), Oracle 11g on Apr 23 2012 06:24:05
     
    Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
    
    
                        Starting at 2012-10-15 10:00:34
    ***********************************************************************
    
    Operating System Version:
    Microsoft Windows 7 , on x64
    Version 6.1 (Build 7600: )
    
    Process id: 8932
    
    Description: 
    
    ***********************************************************************
    **            Running with the following parameters                  **
    ***********************************************************************
    
    2012-10-15 10:00:34  INFO    OGG-03035  Operating system character set identified as windows-1252. Locale: en_US, LC_ALL:.
    REPLICAT srcrepm
    
    SOURCEDEFS G:\app\gg32\dirsql\sourcedefs.sql
    
    --DDLERROR DEFAULT IGNORE
    
    USERID gguser, PASSWORD ******
    
    MAP source.*, TARGET target.directory,
    
    colmap(USEDEFAULTS,
    
    SNO= @Token("TK_SNO"),
    
    NAME= @Token("TK_NAME"),
    
    PHONE= @Token("TK_PHONE"));
    
    
    2012-10-15 10:00:34  INFO    OGG-01815  Virtual Memory Facilities for: COM
        anon alloc: MapViewOfFile  anon free: UnmapViewOfFile
        file alloc: MapViewOfFile  file free: UnmapViewOfFile
        target directories:
        G:\app\gg32\dirtmp.
    
    CACHEMGR virtual memory values (may have been adjusted)
    CACHESIZE:                              512M
    CACHEPAGEOUTSIZE (normal):                4M
    PROCESS VM AVAIL FROM OS (min):           1G
    CACHESIZEMAX (strict force to disk):    881M
    
    Database Version:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    
    Database Language and Character Set:
    NLS_LANG         = ".WE8MSWIN1252" 
    NLS_LANGUAGE     = "AMERICAN" 
    NLS_TERRITORY    = "AMERICA" 
    NLS_CHARACTERSET = "WE8MSWIN1252" 
    
    ***********************************************************************
    **                     Run Time Messages                             **
    ***********************************************************************
    
    Opened trail file G:\app\gg32\dirdat\mt000000 at 2012-10-15 10:00:34
    
    Wildcard MAP resolved (entry source.*):
      MAP "SOURCE"."TEST", TARGET target.directory, colmap(USEDEFAULTS, SNO= @Token("TK_SNO"), NAME= @Token("TK_NAME"), PHONE= @Token("TK_PHONE"));
    Using the following default columns with matching names:
      SNO=SNO, NAME=NAME
    Using the following key columns for target table TARGET.DIRECTORY: SNO.
    
    
    
    2012-10-15 10:00:34  WARNING OGG-01004  Aborted grouped transaction on 'TARGET.DIRECTORY', Database error 1403 (OCI Error ORA-01403: no data found, SQL <UPDATE "TARGET"."DIRECTORY" SET "NAME" = :a1,"PHONE" = :a2 WHERE "SNO" = :b0>).
    
    2012-10-15 10:00:34  WARNING OGG-01003  Repositioning to rba 984 in seqno 0.
    
    2012-10-15 10:00:34  WARNING OGG-01154  SQL error 1403 mapping SOURCE.TEST to TARGET.DIRECTORY OCI Error ORA-01403: no data found, *SQL <UPDATE "TARGET"."DIRECTORY" SET "NAME" = :a1,"PHONE" = :a2 WHERE "SNO" = :b0>*.
    
    2012-10-15 10:00:34  WARNING OGG-01003  Repositioning to rba 984 in seqno 0.
    
    Source Context :
      SourceModule            : [er.errors]
      SourceID                : [er/errors.cpp]
      SourceFunction          : [take_rep_err_action]
      SourceLine              : [623]
    
    2012-10-15 10:00:34  ERROR   *OGG-01296  Error mapping from SOURCE.TEST to TARGET.DIRECTORY.*
    
    ***********************************************************************
    *                   ** Run Time Statistics **                         *
    ***********************************************************************
    
    Last record for the last committed transaction is the following: 
    ___________________________________________________________________
    Trail name :  G:\app\gg32\dirdat\mt000000
    Hdr-Ind    :     E  (x45)     Partition  :     .  (x04) 
    UndoFlag   :     .  (x00)     BeforeAfter:     A  (x41) 
    RecLength  :    77 (x004d)    IO Time    : 2012-10-15 09:23:18.000000  
    IOType     :    15  (x0f)     OrigNode   :   255  (xff)
    TransInd   :     .  (x03)     FormatType :     R  (x52)
    SyskeyLen  :     0  (x00)     Incomplete :     .  (x00)
    AuditRBA   :          7       AuditPos   : 31137808
    Continued  :     N  (x00)     RecCount   :     1  (x01)
    
    2012-10-15 09:23:18.000000 FieldComp          Len    77 RBA 984
    Name: SOURCE.TEST
    ___________________________________________________________________
    
    Reading G:\app\gg32\dirdat\mt000000, current RBA 984, 0 records
    
    Report at 2012-10-15 10:00:34 (activity since 2012-10-15 10:00:34)
    
    From Table SOURCE.TEST to TARGET.DIRECTORY:
           #                   inserts:         0
           #                   updates:         0
           #                   deletes:         0
           #                  discards:         1
    
    
    Last log location read:
         FILE:      G:\app\gg32\dirdat\mt000000
         SEQNO:     0
         RBA:       984
         TIMESTAMP: 2012-10-15 09:23:18.000000
         EOF:       NO
         READERR:   0
    
    
    2012-10-15 10:00:34  ERROR   OGG-01668  PROCESS ABENDING.
    Note: I left out the statistics.

    DB data table:
    select * from source.test;
    SNO                    NAME            UPDATED                   EMAIL                          
    ---------------------- --------------- ------------------------- ------------------------------ 
    3                      Dickens            15-OCT-12 12.20.50.614000000 AM NA                             
    1                      Madhu      14-OCT-12 10.52.05.213000000 PM NA                             
    2                      Tom             14-OCT-12 10.52.05.213000000 PM NA                             
    
    3 rows selected
    Select * from source.contact_no;
    SNO                    PHONE      
    ---------------------- ---------- 
    1                      9888888885 
    2                      9888888886 
    
    2 rows selected
    Select * from target.directory;
    SNO                    NAME            PHONE      
    ---------------------- --------------- ---------- 
    
    0 rows selected
    At startup, the evening only replicate with the error above.

    My question is:
    Why is an update performed at Target.Directory table with the WHERE clause used in the SELECT query to my SNIPPET, which in turn, was intended for the SOURCE. TEST and SOURCE. CONTACT tables?

    Published by: MadhuGopanna on October 14, 2012 23:25: fixed select query. Same recurring error.

    "to replicate (exlisitly give source.test as a source)-
    Question: If I mention only source.test as a source, would have extracted ignore changes made to source.contact_no?

    Stating that -

    MAP source.*, TARGET target.directory
    

    sandbox say GG to you that you have what it takes to replicate all tables in the source schema in target.directory. -So, it's nonsense.

    "to extract (add section TABLEEXCLUDE to exclude the replication source.contact_no) -"
    Question: I want to reproduce the combination of test and contact_no of source data in the target.directory table. In this regard the TABLEEXCLUDE of source.contact_no will provide the desired result?

    TABLEEXCLUDE clause do not exclude the possibility of using the table in queries in SQLEXEC or anywhere else. He just exclude the table replication if you use wildcard characters.
    For example -.

    TABLE user.*;
    TABLE user.TEST;
    

    each user of schema table would be replicated except user. TEST.

    I think it is the right way to say what you want-

    EXTRACT ext1
    --connection to database--
    USERID ogg, PASSWORD xxxx
    --hostname and port for trail--
    --rmthost db-dev-2, mgrport 7809
    --path and name for trail--
    --rmttrail /u01/app/oracle/product/11.1.1.12ogg/dirdat/lt
    EXTTRAIL /u01/app/oracle/product/11.1.1.12ogg/dirdat/ss
    SEQUENCE test.*
    --DDL support
    DDL INCLUDE MAPPED OBJNAME test.*
    --DML
    TABLE source.TEST, SQLEXEC (ID query2col, QUERY "select b.phone as phone from source.test a, source.contact_no b where a.sno=:sno_params and a.sno=b.sno", PARAMS (sno_params = SNO)) TOKENS (TK_PHONE = @GETVAL(query2col.phone));
    TABLEEXCLUDE source.CONTACT_NO;
    
    --Replicat group --
    REPLICAT REP2
    --source and target definitions
    --ASSUMETARGETDEFS
    SOURCEDEFS /u01/app/oracle/product/11.1.1.1.2ogg411g/dirdef/sourcedef
    --target database login --
    USERID ogg, PASSWORD xxxx
    --file for dicarded transaction --
    DISCARDFILE /u01/app/oracle/product/11.1.1.1.2ogg411g/discard/rep1_discard.txt, APPEND, MEGABYTES 10
    --ddl support
    DDL
    --Specify table mapping ---
    MAP source.TEST, TARGET target.DIRECTORY, COLMAP (USEDEFAULTS, PHONE = @TOKEN ("TK_PHONE"));
    DDLERROR 24344 DISCARD;
    

    Just tested - works fine.

    Published by: Artem Khisamiev on 15.10.2012 08:00

    Published by: Artem Khisamiev on 18.10.2012 05:58

  • Queries and remote databases

    We support 3 databases(A,B,C) different society with the same exact structure for each of them and they all use the same
    request. How can I ask a common table (but each in its own location from database) to all three? Each data base of the company has an Employee table, I want to be able to dynamically retrieve records from this table using the employee login id. Ex:
    Select * from employee where id = '44553';

    Create view all_company_employees as
    Select * from employees
    Union
    Select * from employees@company2_db
    Union
    Select * from employees@company3_db;

    Then you can write queries such as:
    Select * from all_company_employees where emp_id = 10101;

    The 'emp_id = 10101' predicate (or whatever your query predicate supplies) should be automatically pushed on all remote queries, so if there is an index on emp_id, to each of the remote tables, it should be properly used.

    Hope that helps,

    -Mark

  • How to get the total line count COUNT (*) SELECT and put on a page?

    Hello

    I use JDeveloper 10.1.3.4. I need get the total number of rows in a table and display it on a page and the problem in doing so. At the sqlplus prompt the row count simply would be, for example:
       select count(*) from BILL;
    I wonder if having this simple number must be so complicated and if there is more simple, better ways. Here's how I do it and the problem encountered.

    1. the name of the page to display the number is summary.jspx. It has a grain of support that "summed" as the managed bean name in faces - config.xml, and the name of the bean class is "summary." The component output on the page is:
    <h:outputText value="#{summary.totalStudentsCount}"
                  binding="#{summary.outputText5}" id="outputText5"/>
    2. in summary the bean code is:
        private Number totalStudentsCount;
        public static int NUMBER = Types.NUMERIC;
    
        public void setTotalStudentsCount(Number totalStudentsCount) {
            this.totalStudentsCount = totalStudentsCount;
        }
    
        public Number getTotalStudentsCount() {
            ZBLCModuleImpl zblcam = getZBLCModuleImpl();
            LoggedInStudentImpl studentTable = (LoggedInStudentImpl)zblcam.getLoggedInStudent();
            String sql = "select count(lsap_uid) from BILL";
            studentTable.setQuery(sql);
            return (Number)CallStoredFunction(NUMBER, "get_total_students(?)", new Object[] {});
        }
    
        private ZBLCModuleImpl getZBLCModuleImpl() {
            FacesContext fc = FacesContext.getCurrentInstance();
            ValueBinding vb = fc.getApplication().createValueBinding("#{data}");
            BindingContext bc = (BindingContext)vb.getValue(fc);
            DCDataControl dc = bc.findDataControl("ZBLCModuleDataControl");
            ApplicationModule am = (ApplicationModule)dc.getDataProvider();
            return (ZBLCModuleImpl)am;        
        }
    
        protected Object CallStoredFunction(int sqlReturnType, String stmt, Object[] bindVars) {
            CallableStatement st = null;
            ZBLCModuleImpl zblcam = getZBLCModuleImpl();
            try {
                st = zblcam.getDBTransaction().createCallableStatement("begin ? := " + stmt + "; end", 0);
                st.registerOutParameter(1, sqlReturnType);
                if (bindVars != null) {
                    for (int z = 0; z < bindVars.length; z++) {
                        st.setObject(z + 2, bindVars[z]);
                    }
                }
                st.executeUpdate();
                return st.getObject(1);
            }
            catch (SQLException e) {
                throw new JboException(e);
            }
            finally {
                if (st != null) {
                    try {
                        st.close();
                    }
                    catch (SQLException e) {
                        throw new JboException(e);
                    }
                }
            }
        }
    The idea of calling a stored function usnig as a "helper" method is 25.5.3 in the Developer's guide, which is closest to you in my need. It's for the functions with the one IN argument; but in my case, the function is not any argument IN. That's why, when you call the helper method CallStoredFunction(), I gave an empty as the last argument and amazing array that caused the problem:
    return (Number)CallStoredFunction(NUMBER, "get_total_students(?)", new Object[] {});
    3. the registered function has been tested and works fine at the sqlplus prompt:
    create or replace function get_total_students
       return NUMBER
    AS
       v_student_count NUMBER;
    BEGIN
       select count(ldap_uid)
       into v_student_count
       from bill;
       return v_student_count;
    END;
    4. when the summary.jspx page is run, the browser is full of error messages, the first long line is here (I have split several online for ease of reading):
    javax.faces.el.EvaluationException: 
      javax.faces.el.EvaluationException: 
        Error getting property 'totalStudentsCount' from bean of type 
        zblc.viewcontroller.backing.staff.Summary: oracle.jbo.JboException: 
          JBO-29000: Unexpected exception caught: 
            java.sql.SQLException, msg=Missing IN or OUT parameter at index:: 2
    Thus,.
    (1) what is the problem? What is this parameter IN or OUT of {color: red} index: 2 {color} consult? It has to do with the empty array as the last argument in the call to the helper method?
    (2) this approach is an overdose, and are there more simple and better ways?

    Thank you very much for help!


    Newman

    Hello

    Is there a specific reason why you don't simply create read only object to display with some count (*) as OFCASES from MYTABLE and then just drag and drop the attribute ofcases in page?

    Kind regards

    Branislav

  • What is the most efficient SQL to identify the best 5 count indictment and the rest of the Group?

    Hi all

    I expect advice about the best way to solve the following (without use of subqueries and decode etc.):

    We have a person table that includes the nationality column... we want to identify the top 5 (County) nationalities and the remaining sum is considered to be "the other". We would then use this result to create a pie for the organization chart.

    Thanks in advance for your time.

    Kind regards
    Yahya

    Or for example

    SQL> select   object_type, sum (cnt) cnt
        from   (select   case when rownum <= 5 then object_type else 'OTHER' end object_type,
                         cnt
                  from   (  select   count ( * ) cnt, object_type
                              from   all_objects
                          group by   object_type
                          order by   count ( * ) desc))
    group by   object_type
    order by   2 desc
    /
    OBJECT_TYPE                CNT
    ------------------- ----------
    SYNONYM                  26932
    JAVA CLASS               22203
    OTHER                    10357
    VIEW                      5064
    INDEX                     4826
    TABLE                     3232
    
    6 rows selected.
    

    Published by: michaels2 on July 1st, 2009 19:49

  • counties-iMatch and - play

    Hello

    Recent subscribe to iMatch, I am happy that I can now access my entire library of all devices.

    One thing that disappoints songs played on my devices does not update the number of game on the library on my mac as before after a sync.

    Information is shared between the devices.

    They is a solution for this?

    Works as expected here, although it is a few unpublished rules of how many, or which parts of a song should be played before the County is advanced.

    Confirm that iTunes > Preferences > sharing > the option on the update verified account game devices and computers.

  • WMP freezes, playback and time counter freeze and after a few seconds it will start from the point where it stopped.

    Original title: WMP 11 continues to stop audio playback

    I use WMP 11 for months with no reading problems but since yesterday evening he continues to stop for about 20 seconds every five minutes or so. When she did this, WMP freezes - meter reading and time to gel and I get the hourglass - and then after 20 seconds or more, the trail starts from where it stops. What is happening on all the tracks I did not play a single. I tried 20 audio files (mp3 all) through a dozen different albums. In addition, the gap between tracks seem longer than usual. I feel that it is looking for the data and playback stops because the time it takes to find the data is longer than the amount of data he has for playback? Either way, my files are stored on an external drive, and I'm now ask to update WMP for 'monitor folders' once again.

    I also downloaded a new copy of WMP 11 but this has not fixed the problem.

    I ran Fix It from Microsoft, but it has not to report any issue so I'm stumped. Any help appreciated thanks.

    Laptop Dell Inspiron 1300
    Windows XP SP 3
    WMP 11 - updates enabled
    Active Windows updates
    MSE firewall on / updates enabled

    Registry fixers never used because they can damage the file system!

    Thank you, Anoop - I notice that it is 7 - t - it too much work for XP? I'll take a look, although I found closure and restart toured (as far as the burning problem goes). Thanks for your help.

  • BlackBerry smartphone BLACBERRY 8700: e-mail - mail unopened count increases and can not be reset to zero (0)

    For reasons I do not understand that my Blackberry began to show a false accounts of unread mail. With all the read mail now shows 5 to electronic mail notification icon screen, started with 1 first, then 2, now 5. I tried to find a reset for this function but can't find it. Can anyone help solve this mystery?

    Recognizing

    KMH

    First try to reset the device by removing the battery for 30 seconds and then replace it. After the device finishes restarting check the new message indicator. Navigate through your list of messages, click on the menu button, choose view saved Messages. Make sure that no unread messages are there.

Maybe you are looking for

  • Optical USB mouse problem with Portege R100 on windows XP

    We have three laptops Toshiba Portege R100 currently giving problems with mouse optical usb from Toshiba. When starting the laptop, that the mouse is not recognized by windows. Before and after will be identified in the mouse will not respond while B

  • Y510P dvd player not working not not after update Win 10

    Just realized that my dvd drive does not read DVD because I upgraded to win 10. He does not even recognize DVD, me showing only a file desktop.ini instead. It plays CDs fine and it burns DVD as peripheral storage, but it * may * be only burn as a CD,

  • boosters of WiFi and time Capsules

    I want to increase my wifi signal, and I'm getting conflicting advice. I use my Time Capsule as my source wifi. I see a numebr of extenders of wifi on Amazon, but it works best with TC? Are these devices plug - and p; Ay? Thank you.

  • HP Officejet Pro 8600 Plus: cartridge problem 8600

    Message seemed to change all cartridges - I changed two a couple of days, so they need not all change - black was about due for a change, so I took them all out - replaced black... had the same message... Replaced all - same message now also "one or

  • WAP54G access point cannot connect to more than one PC at a time

    Hello I'm a newbie in the entire wireless router installation process. I have a WAP54G AP. I managed to enter the configuration page and rename my router and set a WPA2-Personl password. The issue I'm facing is that when my roommate and I try to conn