SQL query must count number of engaged, end, MEP per month

Hi all

Need Sql query with group by category and count of the PEM attached, terminated, current for every month for the year.

Create table per_all_people_f
(person_id varchar2(30),
original_date_of_hire date)

Create table per_all_assignments_f
(person_id varchar2(30),
employee_category varchar2(30))

create table per_periods_of_service
(person_id varchar2(30),
actual_termination_date date)

insert into per_all_people_f
values(1,to_date('01-FEB-2014','DD-MON-YYYY'));
/
insert into per_all_people_f
values(2,to_date('10-FEB-2014','DD-MON-YYYY'));
/
insert into per_all_people_f
values(3,to_date('10-dec-2013','DD-MON-YYYY'));
/
insert into per_all_people_f
values(4,to_date('10-MAR-2014','DD-MON-YYYY'));
/
insert into per_all_people_f
values(5,to_date('10-dec-2013','DD-MON-YYYY'));
/


insert into per_all_assignments_f
values(1,'ADMIN');
/
insert into per_all_assignments_f
values(2,'TECH');
/

insert into per_all_assignments_f
values(3,'TECH');
/
insert into per_all_assignments_f
values(4,'ADMIN');
/

insert into per_all_assignments_f
values(5,'ADMIN');
/

insert into per_periods_of_service
values(3,to_date('05-feb-2014','DD-MON-YYYY'));
/









Desired output.  "()" are to explain only.

Explanation of columns:

Hired_ADMIN = used category ADMIN

Term _Admin = employee fired from category ADMIN

Current_ADMIN = Total current employees in category ADMIN

Hired_TECH = used in category TECH

Term_TECH = employee fired in category TECH

Current_TECH = Total current employees in category TECH

                  

             
Month        Hired_ADMIN   Term_ADMIN     Current_ADMIN                        Hired_TECH    Term_TECH      Current_TECH


Jan-14          0             0                1                                   0            0                10 (example)
Feb-14         2              1                2                                   0            1                 9



Tried the queries below: but not able to get the desired output grouping...

I made different requests for In (Hired), Out (Terminated), need help for current employees by month and grouping as stated above the desired output.

1 request for employees



select in_month,in_month_name
         , count(decode(employee_category,'ADMIN', person_id)) ADMIN_IN
         --, count(decode(employee_category,'DOCT', person_id)) DOCT_IN
         --, count(decode(employee_category,'NURS', person_id)) NURS_IN
         , count(decode(employee_category, 'TECH', person_id)) TECH_IN
from
(
select distinct
papf.person_id,
paaf.employee_category,
       trunc(papf.original_date_of_hire, 'mm') in_month,
       decode(userenv('LANG'),'US',to_char(papf.original_date_of_hire, 'Month'),'AR',to_char(papf.original_date_of_hire, 'Month','nls_date_language=Egyptian'),'') in_month_name
      from per_all_people_f papf
      ,per_all_assignments_f paaf
      where papf.person_id = paaf.person_id
      and Papf.ORIGINAL_DATE_OF_HIRE between to_date('01-JAN-'||:P_YEAR) and to_date('31-dec-'||:P_YEAR)
      and paaf.employee_category is not null         
       )           
     group
      by in_month,in_month_name  
     ORDER BY  in_month



2. request for completed employees:

select out_month,out_month_name
         , count(decode(employee_category,'ADMIN', person_id)) ADMIN_OU
         --, count(decode(employee_category,'DOCT', person_id)) DOCT_OUT
         --, count(decode(employee_category,'NURS', person_id)) NURS_OUT
         , count(decode(employee_category, 'TECH', person_id)) TECH_OUT
from
(
select distinct
       papf.person_id,
       paaf.employee_category,
       trunc(actual_termination_date,'mm') out_month,
       decode(userenv('LANG'),'US',to_char(actual_termination_date, 'Month'),'AR',to_char(actual_termination_date, 'Month','nls_date_language=Egyptian'),'') out_month_name
      from per_all_people_f papf
      ,per_all_assignments_f paaf
      ,per_periods_of_service ppos
      where papf.person_id = paaf.person_id
      and ppos.person_id = papf.person_id
      and ppos.actual_termination_date between to_date('01-JAN-'||:P_YEAR) and to_date('31-dec-'||:P_YEAR)
      and paaf.employee_category is not null             
       )           
     group
      by out_month,out_month_name  
     ORDER BY  out_month



Pls suggest the sql query for current employees monthly and Hired of the EMP, Terminated the PEM group, according to the current EME Emp_Category.

Please suggest...

Thanks and greetings

Afzal.

Post edited by: 1002933

Try this:

set line 1000

WITH dt AS
        (SELECT TO_DATE ('01/' || LEVEL || '/' || &p_year, 'dd/mm/yyyy')
                   st_dt
           FROM DUAL
         CONNECT BY LEVEL <= 12)
SELECT mnth
      ,hired_admin
      ,term_admin
      ,hired_admin - term_admin current_admin
      ,hired_tech
      ,term_tech
      ,hired_tech - term_tech current_tech
  FROM (SELECT TO_CHAR (st_dt, 'mon-yy') mnth
              , (SELECT COUNT (*)
                   FROM per_all_people_f h, per_all_assignments_f c
                  WHERE h.person_id = c.person_id
                    AND c.employee_category = 'ADMIN'
                    AND h.original_date_of_hire BETWEEN st_dt
                                                    AND LAST_DAY (st_dt))
                  hired_admin
              , (SELECT COUNT (*)
                   FROM per_all_people_f h
                       ,per_all_assignments_f c
                       ,per_periods_of_service s
                  WHERE h.person_id = c.person_id
                    AND c.employee_category = 'ADMIN'
                    AND h.person_id = s.person_id
                    AND s.actual_termination_date BETWEEN st_dt
                                                      AND LAST_DAY (st_dt))
                  term_admin
              , (SELECT COUNT (*)
                   FROM per_all_people_f h, per_all_assignments_f c
                  WHERE h.person_id = c.person_id
                    AND c.employee_category = 'TECH'
                    AND h.original_date_of_hire BETWEEN st_dt
                                                    AND LAST_DAY (st_dt))
                  hired_tech
              , (SELECT COUNT (*)
                   FROM per_all_people_f h
                       ,per_all_assignments_f c
                       ,per_periods_of_service s
                  WHERE h.person_id = c.person_id
                    AND c.employee_category = 'TECH'
                    AND h.person_id = s.person_id
                    AND s.actual_termination_date BETWEEN st_dt
                                                      AND LAST_DAY (st_dt))
                  term_tech
          FROM dt);

Output:

Enter the value of p_year: 2014

old 1: WITH dt AS (SELECT TO_DATE ('01 /' |)) LEVEL | '/' || & p_year, ' dd/mm/yyyy') st_dt

new 1: WITH dt AS (SELECT TO_DATE ('01 /' |)) LEVEL | '/' || 2014, ' dd/mm/yyyy') st_dt

MNTH HIRED_ADMIN TERM_ADMIN CURRENT_ADMIN HIRED_TECH TERM_TECH CURRENT_TECH

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

Jan-14                    0          0             0          0          0            0

Feb-14                    1          0             1          1          1            0

Mar-14                    1          0             1          0          0            0

Apr-14                    0          0             0          0          0            0

May-14                    0          0             0          0          0            0

Jun-14                    0          0             0          0          0            0

Jul-14                    0          0             0          0          0            0

Aug-14                    0          0             0          0          0            0

Sep-14                    0          0             0          0          0            0

Oct-14                    0          0             0          0          0            0

Nov-14                    0          0             0          0          0            0

MNTH HIRED_ADMIN TERM_ADMIN CURRENT_ADMIN HIRED_TECH TERM_TECH CURRENT_TECH

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

Dec-14                    0          0             0          0          0            0

12 selected lines.

Tags: Database

Similar Questions

  • SQL Query - to find users with the end of the responsibilities

    Oracle Apps worm: 11.5.10.2

    Oracle DB - 9i

    How can I list users and access given to them for a distribution Specifies any responsibility end being dated at the level of responsibility

    Sakshi,

    Try this, hope will solve your problem,

    Select a.user_name, a.description, c.RESPONSIBILITY_NAME, b.START_DATE, b.end_date
    fnd_user a.,
    B FND_USER_RESP_GROUPS_DIRECT,
    c fnd_responsibility_vl
    where a.user_id = b.user_id
    and b.RESPONSIBILITY_ID = c.RESPONSIBILITY_ID
    and a.user_id = 'ENTER_USER_ID';

    Thank you
    Anchorage :)

  • SQL query: number of occurrence of cellData more thann a column of tabl

    I used table contains the sequence of lines.
    INSERT INTO employee VALUES (105, 'Srinath','vijay','Aeronautics', 27, 33000); 
    INSERT INTO employee VALUES (105, 'Kumble','Anil','Aeronautics', 27, 33000);
    INSERT INTO employee VALUES (105, 'Prabhakar','Manoj','Aeronautics', 27, 33000);
    INSERT INTO employee VALUES (105, 'Srinath','Jawagal','Aeronautics', 27, 33000);
    INSERT INTO employee VALUES (105, 'Jawagal','Srinath','Aeronautics', 27, 33000);
    INSERT INTO employee VALUES (105, 'Mishra','Anil','Aeronautics', 27, 33000);
    INSERT INTO employee VALUES (105, 'Kumble','Prabhakar','Aeronautics', 27, 33000);
    Select first_name separate firstName, count (1) on firstNameCount (partition name) of the employee;
    and I got the following result.
    (Srinath 2, Kumble 2, Prabhakar 1, Jawagal 1, Mishra 1)

    Now I want to examine the second and third column the two and want to number of occurrence of data in the table in these two columns
    (Srinath 3,Kumble 2,Prabhakar 2,Jawagal 2,Mishra 1,vijay 1,Anil 2,Manoj 1)
    As Srinath just 3 times, kumble 2 times, Prabhakar 2 Jawagal 2 times, Mishra 1 time, 1 time vijay times, Anil 2 times and Maury 1 times.

    What will be my sql query?

    Try this

    select name, count(name) over(partition by name) cnt
      from (select first_name from employee union all select last_name from employee)
    
  • How can I get a query to count a number of channels?

    I want the query to count, to me, how many holidays, there are in the USA in my table. But I'm not sure how to retrieve the result of a string or varchar2 data type. That's what I've tried so far.

    Select count (COUNTRYVIS) < < this column contains all the countries visited
    of "IT220_HOLIDAYDETAILS" < < this is the table where the column is
    where COUNTRYVIS = 'USA' < < this is the result, I want to count

    ORA-00904: 'USA': invalid identifier < < this is im error message get, is there a way to count the channels?

    Thanks in advance!

    This has nothing to do with the APEX. Please post any fundamental questions of SQL on the + {forum: id = 75} + forum.

    In any forum OTN, alll code must be posted wrapped in .

    ...\
    

    Tags as described in the FAQ:

    select count(COUNTRYVIS) -- this column contains all the countries visited
    from "IT220_HOLIDAYDETAILS" -- this is the table where the column is
    where COUNTRYVIS = "USA" -- this is the result i want it to count
    

    You seem to have trouble with the distinction between identifiers and literals text. Tip: Use the double quotes, other apostrophes.

    Note that quoted identifiers are usually not a good idea.

  • Get the count of the two different statuses in SQL query

    Hi Experts,
    ALTER TABLE EMP ADD STATUS INTEGER DEFAULT 1 NOT NULL;
    UPDATE EMP SET STATUS=2 WHERE EMPNO > 7700
    SELECT COUNT(*) OVER() TOTALRECORDS,EMP.DEPTNO,EMP.EMPNO FROM EMP,DEPT WHERE EMP.DEPTNO=EMP.DEPTNO
    The Select query will return the total number of the EMP, DEPT tables (the two status with 1 and 2).
    But I need to get the number of 1 and 2 separately.

    Is this possible with changes in an existing SQL query?

    Thank you
    Dharan V
    ALTER TABLE EMP ADD STATUS INTEGER DEFAULT 1 NOT NULL;
    UPDATE EMP SET STATUS=2 WHERE EMPNO > 7700
    SELECT COUNT(*) OVER() TOTALRECORDS,EMP.DEPTNO,EMP.EMPNO FROM EMP,DEPT WHERE EMP.DEPTNO=EMP.DEPTNO
    

    change this option like this

    SELECT COUNT(decode(status,1,1,null)) OVER() RECORDS_1,
           COUNT(decode(status,2,2,null)) over() RECORDS_2,
           EMP.DEPTNO,EMP.EMPNO
      FROM EMP,DEPT WHERE EMP.DEPTNO=EMP.DEPTNO
    
  • SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate

    Hello

    SQL query to find the total number of source based nonsource passangersbetween source and destination station and passenger station on the same chekindate.

    Please help on this script and let me know if you need more details.

    ---

    You use a SELECT statement.  Let me know if you need more details.

  • More than 1 SQL query with checkbox and error invalid number report

    Hi all

    I have two SQL query reports that each has an apex_item.checkbox and two processes for each report.  A report/process works very well.  It gives me an error of invalid number.

    In addition, another query SQL (editable report) gives me the following error when using the Multi line process, delete.

    ORA-06502: PL/SQL: digital or value error: character number conversion
    error ORA-06502: PL/SQL: digital or value error: character number conversion
    error
    Ok

    When I got a report from SQL query (with box and a process) and the query SQL (editable report) everything worked.  It stopped working when I added another SQL query report (with box and a process).

    A SQL query has the following in my query: apex_item.checkbox(3,email_id,'UNCHECKED') ""

    The other SQL query has the following: apex_item.checkbox(2,b.file_id,'UNCHECKED') ""

    Any help will be greatly appreciated,

    Sylvia

    Hi Reema,

    I've recreated the region and now it works!

    Thank you for this, looking at

    Sylvia

  • How to get the line number in the line itself in the Sql query?

    Hello
    I pick up some lines of a sql query. Is it possible to get line number in each line while all lines are read?

    Like this:

    RowNum data1 data2
    1 abc era
    2 NBH ioi

    Yes.

    ROWNUM

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/pseudocolumns009.htm#SQLRF00255

    select rownum, data1, data2
    from yourtable;
    
  • SDO_RELATE within PL/SQL query with rownum clause runs slowly on 12 c - works great on 10 g

    Hello

    I use the database 12.1.0.2 with a node 2 RAC on Windows.

    I am struck by a really weird performance problem with a particular query.  Bear with me while I try to explain...

    I have a chart with lines 30 sdo_geometry million, in 7 partitions with a local partitioned spatial index divided.  Called BIG_PARTITIONED_TABLE for this example.

    I query the table to search for one line with a geometry that is equal to the geometry of my request.  In this case I use sdo_relate with "mask = equal".  Instantly returns:

    SQL> select id, geometry
      2  from       BIG_PARTITIONED_TABLE o
      3  where      sdo_relate(o.geometry, sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      4     SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272)), 'mask=equal') = 'TRUE'
      5  and rownum = 1;
    
            ID
    ----------
    GEOMETRY(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
    -------------------------------------------------------------------------------
    2.5405E+12
    SDO_GEOMETRY(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272))
    
    Elapsed: 00:00:00.10
    
    

    But if I put the same query in PL/SQL, so it takes 21 seconds:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:21.13
    
    

    If I remove the "rownum = 1", then it returns instantly:

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_relate(o.geometry, l_window_geom, 'mask=equal') = 'TRUE';
    13
    14  end;
    15  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.03
    
    

    If using sdo_equal instead of sdo_relate and keep the "rownum = 1", then it returns instantly.

    SQL> declare
      2     l_id number;
      3     l_geom sdo_geometry;
      4     l_window_geom sdo_geometry;
      5  begin
      6     l_window_geom := sdo_geometry(2002, 2157, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1),
      7             SDO_ORDINATE_ARRAY(604853.595, 692379.864, 604879.046, 692350.272));
      8
      9     select id, geometry
    10     into l_id, l_geom
    11     from    BIG_PARTITIONED_TABLE o
    12     where   sdo_equal(o.geometry, l_window_geom) = 'TRUE'
    13     and rownum = 1;
    14
    15  end;
    16  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.13
    
    

    Here is a comparison of the plans to explain.  First, here's the good thing, that is using the spatial index (BIG_PARTITIONED_TABLE_SPIND):

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_EQUAL(O.GEOMETRY, :B1 ) = 'TRUE'
    AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.01       0.02          0         39          0           0
    Fetch        1      0.00       0.01          0         31          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3      0.01       0.04          0         70          0           1
    
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=99 pr=0 pw=0 time=43307 us)
             1          1          1   PARTITION RANGE ALL PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43297 us cost=0 size=66 card=1)
             1          1          1    TABLE ACCESS BY LOCAL INDEX ROWID BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=99 pr=0 pw=0 time=43280 us cost=0 size=66 card=1)
             1          1          1     DOMAIN INDEX  BIG_PARTITIONED_TABLE_SPIND (cr=98 pr=0 pw=0 time=43250 us)
    
    

    Then the slow that does not use the spatial index.

    select id, GEOMETRY
    FROM
    BIG_PARTITIONED_TABLE O WHERE SDO_RELATE(O.GEOMETRY, :B1 , 'mask=equal') = 'TRUE'
      AND ROWNUM = 1
    
    call     count       cpu    elapsed       disk      query    current        rows
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.03       0.03          0       1123          0           0
    Fetch        1     24.25      24.25          0     499429          0           1
    ------- ------  -------- ---------- ---------- ---------- ----------  ----------
    total        3     24.30      24.29          0     500552          0           1
    
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 263     (recursive depth: 1)
    Number of plan statistics captured: 1
    
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
    ---------- ---------- ----------  ---------------------------------------------------
             1          1          1  COUNT STOPKEY (cr=499532 pr=0 pw=0 time=24289612 us)
             1          1          1   HASH JOIN RIGHT SEMI (cr=499532 pr=0 pw=0 time=24289586 us cost=32 size=144 card=1)
             1          1          1    VIEW  VW_NSO_1 (cr=103 pr=0 pw=0 time=31110 us cost=29 size=98016 card=8168)
             1          1          1     COLLECTION ITERATOR PICKLER FETCH SDO_PQRY (cr=103 pr=0 pw=0 time=31104 us cost=29 size=16336 card=8168)
      16914892   16914892   16914892    PARTITION RANGE ALL PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=28678375 us cost=3 size=6600 card=100)
      16914892   16914892   16914892     TABLE ACCESS FULL BIG_PARTITIONED_TABLE PARTITION: 1 7 (cr=499429 pr=0 pw=0 time=23406547 us cost=3 size=6600 card=100)
    
    

    I tried adding an indication / * + index (o BIG_PARTITIONED_TABLE_SPIND) * / but that did not help.

    I am struck this issue during testing of upgrade 10.2.0.5 to 12.1.0.2.  The query works perfectly on 10g - we note only that this question on 12 c.

    I can't use sdo_equal as the real mask that we want is equal + dommagescausdspar + covers.  I'm just using equal here to simplify the test.

    I use "rownum = 1" because I want to just the first result.  In practice I can rewrite probably is a FOR LOOP, I get out after the first result, but that seems all just awful.

    Any ideas?  If anyone has seen anything like this before?  Its an optimizer delivers really so I'm going to cross post the SQL Forum after a certain time, but thought I would post it here first.

    Thank you

    John

    Hi John,.

    Can you please try the following before your slow queries event?

    "ALTER session set events ' trace 54669 name context forever."

    Thank you

    Ying

  • Clarification of the SQL query in 2 day + Guide APEX

    I worked through the Oracle Database Express Edition 2 day + Application Express Developer's Guide, and try to decipher the SQL query in Chapter 4 (building your app).

    The code is:

    SELECT d.DEPARTMENT_ID,

    d.DEPARTMENT_NAME,

    (select count (*) from oehr_employees where department_id = d.department_id)

    "Number of employees", he said.

    substr (e.first_name, 1, 1) |'. ' || Select 'Name Manager',

    c.COUNTRY_NAME 'place '.

    OEHR_DEPARTMENTS d,

    E OEHR_EMPLOYEES

    OEHR_LOCATIONS l,

    C OEHR_COUNTRIES

    WHERE d.LOCATION_ID = l.LOCATION_ID

    AND l.COUNTRY_ID = c.COUNTRY_ID

    AND e.department_id = d.DEPARTMENT_ID

    AND d.manager_id = e.employee_id

    AND instr (superior (d.department_name), superior (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0)

    I don't know exactly what is happening in the last line. I think I understand what the different functions but I'm not clear on the use of the: P2_REPORT_SEARCH string.

    What does this string? This code simply checking that d.department_name isn't NA?

    I have SQL experience but am not very familiar with the Oracle PL/SQL implementation. Can someone please give me a brief breakdown that check is doing in the context of the overall query? The application seems to work even if the conditional statement is not included.

    Thank you.

    2899145 wrote:

    Thanks for the reply. I apologize if the information I added was incomplete. The code came from the day 2 + Application Express (version 4.2) Developer Guide.

    In the section 'your own Application of 4 Buuilding' https://docs.oracle.com/cd/E37097_01/doc.42/e35122/build_app.htm#TDPAX04000 , they describe the creation of a report

    page that includes the "manager_id" and 'location_id '. The SQL query, I pasted above extracted from the data in other tables to substitute the real 'name of the Manager' and 'rent '.

    for the corresponding ID values. It makes sense, and the part of the SQL query that explicitly doing this makes sense.

    However, given that the document is a guide for the development of the APEX, I guess the command:

    AND instr (upper (d.department_name), upper (nvl (:P2_REPORT_SEARCH,d.department_name))) > 0

    done something valuable, and I do not recognize what is exactly the value.

    From a practical point of view why would I need to include this conditional statement?  Which only added to the application?

    Looking at the guide in question, it is clear that the

    AND instr(upper(d.department_name),upper(nvl(:P2_REPORT_SEARCH,d.department_name)))>0
    

    the line is completely unnecessary in the context of this tutorial, and it can be removed. The search in the tutorial app page is implemented by using a report filter interactive rather than a P2_REPORT_SEARCH element, which does not seem to exist at all. (It's a quirk of the APEX that bind variable references to non-existent items are replaced with NULL silently rather than exceptions). I thought that perhaps it would be legacy code a version of the tutorial prior to the introduction of interactive reports at the APEX 3.1, but I can't find explicit instructions to create such an element of filter in the 3.0 tutorial. I guess it must have been automatically generated by the application wizard when you create a standard report page.

    If you do not want to see the effect he would have (as described in the post above), leave it in the source report, add a text element of P2_REPORT_SEARCH, and a button "submit" on page 2 and experimenting to find different values of the element and clicking on the submit button...

  • Required SQL query

    Hello

    Suppose I need to check the number of records of 30 tables in the oracle database in a particular schema, it may have hundreds of tables.
    How to check with simple sql query.

    I know that under method,

    Select count (*) from
    Table1, table2, table3... table30;

    But I need in format below. If I use Group by we will get but we must specify all 30 tables to groupby, is any alternative group instead of keep all 30 tables


    SELECT TABLENAME, COUNT (*)
    OF table1, table2, table3... table30

    Group of table1, table2, table3... table30;

    Try the following query if all tables are present in the same pattern in the case otherwise you must use dba_tables:

    SELECT
      table_name,
      to_number(
      extractvalue(
          XMLTYPE(
            dbms_xmlgen.getxml('select count(*) c from '||table_name))
        ,'/ROWSET/ROW/C')) count
    FROM
      user_tables
    WHERE table_name IN ('A','B','C')
    ORDER BY table_name;
    
  • SQL QUERY THAT RETURNS THE PL/SQL

    Hello

    I'm putting in 4.2 below apex

    DECLARE

    date of frdate: =: P22_FROMDATE;

    date date: =: P22_TODATE;

    l_date1 varchar2 (11): = to_char(frdate,'dd-mon-yyyy');

    l_date2 varchar2 (11): = to_char(todate,'dd-mon-yyyy');

    v_sql varchar2 (32000);

    v_Name varchar2 (4000): = months_name (frdate, todate);

    char (1) of the v1: = q "[']";

    number of lbr1 (6): =: P22_FROMBRANCH;

    number of LBR2 (6): =: P22_TOBRANCH;

    number of M1 (6): = 11;

    Start

    v_sql: ='SELECT * FROM (SELECT LBRCODE, PRDACCTID, MN, AVGX FROM (SELECT LBRCODE, PRDACCTID, MN, SUM (BALL) BALL, COUNT (MN) DAYS, ROUND (SUM (BAL) count (MN), 2) AVGX ';))

    v_sql: = v_sql | "FROM (SELECT LBRCODE, PRDACCTID, TO_CHAR (BALDATE,'|)) CHR (39) | ' MM' | CHR (39) |') ' | ' ||'|| CHR (39) | » _'|| CHR (39) |' | ' || «TO_CHAR (BALDATE,'|)» CHR (39) | ' AAAA '. CHR (39) |') MN, BALL ';

    V_SQL: = V_SQL | "(SELECT Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE, T_OST_NEW (Q2. LBRCODE, Q2. PRDACCTID, T1. BALDATE) BALL ';

    V_SQL: = V_SQL | "FROM (select TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') baldate FROM DUAL Union all the ';

    V_SQL: = V_SQL |' select (TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') + level) double baldate ';

    V_SQL: = V_SQL |' connect by level < = (TO_DATE('||) Chr (39) | l_date2 | Chr (39) | «, » || CHR (39) | ' DD-MON-YYYY ' | CHR (39) |') -TO_DATE('||) Chr (39) | l_date1 | Chr (39) | «, » || CHR (39) | ' Dd-mon-yyyy ' | CHR (39) |')) ) Q1,';

    V_SQL: = V_SQL | "(SELECT LBRCODE,'|) ' (rpad (prdcd, 8,'|)) V1 ||'' || v1 |') || LTRIM (rpad('|| v1 ||) » x'|| V1 | «, 25, » || v1 | » 0' || v1||'),'|| v1 | » x'|| v1 |')) prdacctid OF D009021 WHERE the LBRCODE between ' | : P22_FROMBRANCH |' and ' | : P22_TOBRANCH | "AND moduleinfo =' | TO_NUMBER(:P22_SELECTLIST);

    V_SQL: = V_SQL |') ((Q2)) GROUP BY LBRCODE, PRDACCTID, MN))';

    V_SQL: = V_SQL | "PIVOT (MAX (AVGX) (MN) IN (';))

    V_SQL: = V_SQL | V_NAME;

    V_SQL: = V_SQL |')) ORDER OF LBRCODE, PRDACCTID ';

    RETURN V_SQL;

    END;

    I created all the elements of the required page

    I get the error message like missing expression

    to test, I created a function to return the query, it works very well know to return a query that gives me desired report

    am I missing something?

    Help, please

    HEMU wrote:

    Hello Sir

    Sorry to bother you again

    I tried to use «function that returns colon-delimited topics»

    and I got following error

    unable to determine query headings: ORA-06550: line 1, column 138: PLS-00103: Encountered the symbol ";" when expecting one of the following:  . ( ) , * % & = - + < / > at in is mod remainder not rem =>  <> or != or ~= >= <= <> and or like like2 like4 likec between || multiset member submultiset The symbol ")" was substituted for ";" to continue.
    
    failed to parse SQL query:
    

    can take you a look at page901 once again please and a function named months_namex

    is it feasible that I'm looking for?

    The immediate cause of this error is simply incorrect report headings function call syntax:

    return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy')

    This should be:

    return months_namex(to_date(:p901_fromdate,'dd-mon-yyyy'),to_date(:p901_todate,'dd-mon-yyyy'));

    However there is no months_namex function defined in the workspace.

  • Dynamic PL SQL query

    Hello

    I want to run and store the results of a dynamic sql query in a strored procedure.

    I get the following variables of the user running: v_column_names, v_table_name, v_col, v_value

    The query will be like:

    v_query: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;

    for example v_column_names: = 'ACCOUNT_NUM, SYSTEM_ID, ENTITY_ID ';

    v_table_name: = 'ACCOUNT '.

    v_col: = 'COUNTRY_CODE ';

    v_value: = "USA";

    Here is what I tried

    DECLARE

    v_column_names VARCHAR (200): = 'ENTITY_ID, SYSTEM_ID, ACCOUNT_NUM;

    v_table_name VARCHAR (200): = 'ACCOUNT '.

    v_col VARCHAR (200): = 'COUNTRY_CODE ';

    v_value VARCHAR (200): = "'USA"';

    TYPE column_record () IS RENDERING

    VARCHAR2 (200) C1: = null;

    C2 VARCHAR2 (200): = null;

    C3 VARCHAR2 (200): = null

    );

    TYPE st_table IS TABLE OF column_record INDEX DIRECTORY.

    pk_table st_table;

    NUMBER of v1: = 1;

    BEGIN

    v_select: = 'SELECT'. v_column_names | ' A ' | v_table_name | ' WHERE ' | v_col |' = ' | v_value;

    EXECUTE IMMEDIATE v_select COLLECT LOOSE pk_table.

    I'm IN 1.pk_table.count LOOP

    DBMS_OUTPUT. Put_line (pk_table (v1). (C1);

    DBMS_OUTPUT. Put_line (pk_table (v1). (C2);

    DBMS_OUTPUT. Put_line (pk_table (v1). (C3);

    v1: = v1 + 1;

    END LOOP;

    END;

    The number of column names in v_column_names is dynamic, so I need a way to store the results and then manipulate them.

    I look forward to your reply.

    EDIT: The real question:

    1. in the settings I have pass the table name and the value of the primary key of the row I want to delete.

    2. He then checks if this line is referenced anywhere, removes the reference, and then deletes the current line. This can go, until all the rows that are referenced are removed.

    The above code, I have provided a small part of the largest of stored procedure.

    Thank you all, I found the tips very helpful. I found a solution to my problem:

    Oracle - how to build queries DELETE in PL/SQL, based on the tables of the FK relations? -Stack overflow

    It generates all removal requests to remove a specific line.  Not what I wanted, but this does not solve my problem.

    The reason why is that I discovered that we do not use the ON DELETE CASCADE that we don't remove a record accidentally, I know we have an option to restore, but it is just in case something goes wrong.

  • SQL query for the mapping of a set of prizes to a group of classrooms

    Hi all

    I use Oracle database 11g Release 2.

    I have the following data set:

    Classrooms
    ClassId ClassName ability group
    ------ ----------------------------------------------      --------------     -----------
    Babbage/software Engg Lab 1 24 1
    Basement 2 - block PG 63 1
    3 1 56 1 class
    Class 4 1 24 10
    Class 5 1 24 11
    Class 6 1 35 12
    7 13 42 1 class
    8 14 42 1 class
    9 15 42 1 class
    10 2 35 1 class
    11 3 35 1 class
    12 4 35 1 classroom
    13 5 35 1 class
    14 6 25 1 class
    15 7 25 1 class
    16 1 24 8 class
    17 9 24 1 class
    18 control Sys Lab 1 24
    19 dig & Embd Sys Lab 20 1
    20 PSD & Comm 20 1 Lab
    21 electromechanical system Lab 28 1
    Farabi 22/Web Tech Lab 1 36
    23 gen purpose Lab 40 1
    Shirazi/24dB Tech Lab 1 36
    ADV 25 elect Lab 30 2
    26 16 42 2 class
    27 17 49 2 class
    28 18 56 2 class
    29 19 42 2 class
    30 20 49 2 class
    Class 31 21 35 3
    32 22 35 3 class
    33 20 3 MDA lab

    DegreeBatches
    BatchId BatchName force
    ---------------     ----------------------- --------------
    1 BIT - 11 79
    2 BIT - 12 28
    3 BS (CS)-1 35
    4 BS (CS) 78-2
    5 BE (SE)-1 69
    6. BE (SE) 84-2
    7 BE (SE) 64-3
    8 84 BYTČA-7
    9 43 BYTČA-8
    BEE-1 10, 112
    11 151 BEE-2
    BEE-3 12, 157
    13 BEE-4 157

    I want to map a combination of batch of degree for a class rooms group of such distance that they make full use of the maximum capacity of the class rooms within a group (ideally), or as close to this as possible. Can it be done with a SQL query?

    Any response will be appreciated.

    The SQL Scripts to generate the required tables and populate data is less to:
    CREATE TABLE classrooms (ClassId NUMBER, ClassName VARCHAR2 (50), capacity NUMBER, group NUMBER);
    INSERT INTO the classrooms of the VALUES (1, "Babbage/software Engg Lab', 24, 1");
    INSERT INTO the classrooms of the VALUES (2, 'basement - PG block', 63, 1);
    INSERT INTO the classrooms of the VALUES (3, '1 class room', 56, 1);
    INSERT INTO the classrooms of the VALUES (4, '10 class room', 24, 1);
    INSERT INTO the classrooms of the VALUES (5, '11 class room', 24, 1);
    INSERT INTO the classrooms of the VALUES (6, 'class room 12', 35, 1);
    INSERT INTO the classrooms of the VALUES (7, 'class room 13', 42, 1);
    INSERT INTO the classrooms of the VALUES (8, 'class room 14', 42, 1);
    INSERT INTO the classrooms of the VALUES (9, '15 'class, 42, 1);
    INSERT INTO the classrooms of the VALUES (10, 'class 2', 35, 1);
    INSERT INTO the classrooms of the VALUES (11, 'class room 3', 35, 1);
    INSERT INTO the classrooms of the VALUES (12, 'class room 4', 35, 1);
    INSERT INTO the classrooms of the VALUES (13, 'class room 5', 35, 1);
    INSERT INTO the classrooms of the VALUES (14, 'class room 6', 25, 1);
    INSERT INTO the classrooms of the VALUES (15, '7 class room', 25, 1);
    INSERT INTO the classrooms of the VALUES (16, 'class Room 8', 24, 1);
    INSERT INTO the classrooms of the VALUES (17, 'class room 9', 24, 1);
    INSERT INTO the classrooms of the VALUES (18, 'Control Sys Lab', 24, 1);
    INSERT INTO the classrooms of the VALUES (19, 'Dig & Embd Sys Lab', 20, 1);
    INSERT INTO the classrooms of the VALUES (20, 'DSP & Comm Lab', 20, 1);
    INSERT INTO the classrooms of the VALUES (21, 'system ELECTROMECHANICAL Lab', 28, 1);
    INSERT INTO the classrooms of the VALUES (22, ' Farabi/Web Tech Lab', 36, 1);
    INSERT INTO the classrooms of the VALUES (23, 'Gen purpose Lab', 40, 1);
    INSERT INTO the classrooms of the VALUES (24, ' Shirazi/DB Tech Lab', 36, 1);
    INSERT INTO the classrooms of the VALUES (25, 'Elected Adv Lab', 30, 2);
    INSERT INTO the classrooms of the VALUES (26, 'class room 16', 42, 2);
    INSERT INTO the classrooms of the VALUES (27, 'class room 17', 49, 2);
    INSERT INTO the classrooms of the VALUES (28, '18 'class, 56, 2);
    INSERT INTO the classrooms of the VALUES (29, '19 'class, 42, 2);
    INSERT INTO the classrooms of the VALUES (30, 'class room 20', 49, 2);
    INSERT INTO the classrooms of the VALUES (31, 'class room 21', 35, 3);
    INSERT INTO the classrooms of the VALUES (32, 'room 22', 35, 3);
    INSERT INTO the classrooms of the VALUES (33, 'MDA Lab', 20, 3);

    CREATE TABLE DegreeBatches (BatchId NUMBER, BatchName VARCHAR2 (50), membership NUMBER);
    INSERT INTO DegreeBatches VALUES(1,'BIT-11',79);
    INSERT INTO DegreeBatches VALUES(2,'BIT-12',28);
    INSERT INTO DegreeBatches VALUES (3, 'BS (CS) - 1', 35);
    INSERT INTO DegreeBatches VALUES (4, 'BS (CS) - 2', 78);
    INSERT INTO DegreeBatches VALUES (5,'BE (SE) - 1', 69);
    INSERT INTO DegreeBatches VALUES (6,'BE (SE) - 2', 84);
    INSERT INTO DegreeBatches VALUES (7,'BE (SE) - 3', 64);
    INSERT INTO DegreeBatches VALUES(8,'BICSE-7',84);
    INSERT INTO DegreeBatches VALUES(9,'BICSE-8',43);
    INSERT INTO DegreeBatches VALUES(10,'BEE-1',112);
    INSERT INTO DegreeBatches VALUES(11,'BEE-2',151);
    INSERT INTO DegreeBatches VALUES(12,'BEE-3',157);
    INSERT INTO DegreeBatches VALUES(13,'BEE-4',157);

    Best regards
    Bilal

    Published by: Bilal on December 27, 2012 09:52

    Published by: Bilal on December 27, 2012 10:07

    Bilal, thanks for the nice problem! Another possibility to double check is to write a small PL/SQL function that returns 1 if a duplicate id is found, then equate to 0: "NUMBER of RETURN of Duplicate_Token_Found (p_str_main in VARCHAR2, p_str_trial VARCHAR2). It should analyze the second string and could use p_str_main LIKE '%', | l_id | ', %' for each id. In any case, the query complete (without that) is given below:

    Solution with names
    SQL> WITH rsf_itm (con_id, max_weight, nxt_id, lev, tot_weight, tot_profit, path, root_id, lev_1_id) AS (
      2  SELECT c.id,
      3         c.max_weight,
      4         i.id,
      5         0,
      6         i.item_weight,
      7         i.item_profit,
      8         ',' || i.id || ',',
      9         i.id,
     10         0
     11    FROM items i
     12   CROSS JOIN containers c
     13   UNION ALL
     14  SELECT r.con_id,
     15         r.max_weight,
     16         i.id,
     17         r.lev + 1,
     18         r.tot_weight + i.item_weight,
     19         r.tot_profit + i.item_profit,
     20         r.path || i.id || ',',
     21         r.root_id,
     22         CASE WHEN r.lev = 0 THEN i.id ELSE r.nxt_id END
     23    FROM rsf_itm r
     24    JOIN items i
     25      ON i.id > r.nxt_id
     26     AND r.tot_weight + i.item_weight <= r.max_weight
     27   ORDER BY 1, 2
     28  ) SEARCH DEPTH FIRST BY nxt_id SET line_no
     29  , rsf_con (nxt_con_id, nxt_line_no, con_path, itm_path, tot_weight, tot_profit, lev) AS (
     30  SELECT con_id,
     31         line_no,
     32         To_Char(con_id),
     33         ':' || con_id || '-' || (lev + 1) || ':' || path,
     34         tot_weight,
     35         tot_profit,
     36         0
     37    FROM rsf_itm
     38   UNION ALL
     39  SELECT r_i.con_id,
     40         r_i.line_no,
     41         r_c.con_path || ',' || r_i.con_id,
     42         r_c.itm_path ||  ':' || r_i.con_id || '-' || (r_i.lev + 1) || ':' || r_i.path,
     43         r_c.tot_weight + r_i.tot_weight,
     44         r_c.tot_profit + r_i.tot_profit,
     45         r_c.lev + 1
     46    FROM rsf_con r_c
     47    JOIN rsf_itm r_i
     48      ON r_i.con_id > r_c.nxt_con_id
     49   WHERE r_c.itm_path NOT LIKE '%,' || r_i.root_id || ',%'
     50     AND r_c.itm_path NOT LIKE '%,' || r_i.lev_1_id || ',%'
     51     AND r_c.itm_path NOT LIKE '%,' || r_i.nxt_id || ',%'
     52  )
     53  , paths_ranked AS (
     54  SELECT itm_path || ':' itm_path, tot_weight, tot_profit, lev + 1 n_cons,
     55         Rank () OVER (ORDER BY tot_profit DESC) rnk,
     56         Row_Number () OVER (ORDER BY tot_profit DESC) sol_id
     57    FROM rsf_con
     58  ), best_paths AS (
     59  SELECT itm_path, tot_weight, tot_profit, n_cons, sol_id
     60    FROM paths_ranked
     61   WHERE rnk = 1
     62  ), row_gen AS (
     63  SELECT LEVEL lev
     64    FROM DUAL
     65  CONNECT BY LEVEL <= (SELECT Count(*) FROM items)
     66  ), con_v AS (
     67  SELECT  b.itm_path, r.lev con_ind, b.sol_id, b.tot_weight, b.tot_profit,
     68          Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev - 1) + 1,
     69            Instr (b.itm_path, ':', 1, 2*r.lev) - Instr (b.itm_path, ':', 1, 2*r.lev - 1) - 1)
     70             con_nit_id,
     71          Substr (b.itm_path, Instr (b.itm_path, ':', 1, 2*r.lev) + 1,
     72            Instr (b.itm_path, ':', 1, 2*r.lev + 1) - Instr (b.itm_path, ':', 1, 2*r.lev) - 1)
     73             itm_str
     74    FROM best_paths b
     75    JOIN row_gen r
     76      ON r.lev <= b.n_cons
     77  ), con_split AS (
     78  SELECT itm_path, con_ind, sol_id, tot_weight, tot_profit,
     79         Substr (con_nit_id, 1, Instr (con_nit_id, '-', 1) - 1) con_id,
     80         Substr (con_nit_id, Instr (con_nit_id, '-', 1) + 1) n_items,
     81         itm_str
     82    FROM con_v
     83  ), itm_v AS (
     84  SELECT  c.itm_path, c.con_ind, c.sol_id, c.con_id, c.tot_weight, c.tot_profit,
     85          Substr (c.itm_str, Instr (c.itm_str, ',', 1, r.lev) + 1,
     86            Instr (c.itm_str, ',', 1, r.lev + 1) - Instr (c.itm_str, ',', 1, r.lev) - 1)
     87             itm_id
     88    FROM con_split c
     89    JOIN row_gen r
     90      ON r.lev <= c.n_items
     91  )
     92  SELECT v.sol_id,
     93         v.tot_weight s_wt, v.tot_profit s_pr, c.id c_id, c.name c_name, c.max_weight m_wt,
     94         Sum (i.item_weight) OVER (PARTITION BY v.sol_id, c.id) c_wt,
     95         i.id i_id, i.name i_name, i.item_weight i_wt, i.item_profit i_pr
     96    FROM itm_v v
     97    JOIN containers c
     98      ON c.id = To_Number (v.con_id)
     99    JOIN items i
    100      ON i.id = To_Number (v.itm_id)
    101   ORDER BY sol_id, con_id, itm_id
    102  /
    
        SOL_ID S_WT S_PR  C_ID C_NAME          M_WT C_WT  I_ID I_NAME     I_WT I_PR
    ---------- ---- ---- ----- --------------- ---- ---- ----- ---------- ---- ----
             1  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     3 BSCS-2       35   35
                                                             5 BEE-4        50   50
             2  255  255     1 SEECS UG Block   100   95     4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   70     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
             3  255  255     1 SEECS UG Block   100  100     3 BSCS-2       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     1 BIT-10       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
             4  255  255     1 SEECS UG Block   100  100     3 BSCS-2       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     1 BIT-10       35   35
                                                             5 BEE-4        50   50
             5  255  255     1 SEECS UG Block   100   95     2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   70     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
             6  255  255     1 SEECS UG Block   100  100     2 BIT-11       40   40
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     1 BIT-10       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
             7  255  255     1 SEECS UG Block   100  100     2 BIT-11       40   40
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     1 BIT-10       35   35
                                                             5 BEE-4        50   50
             8  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   85     3 BSCS-2       35   35
                                                             5 BEE-4        50   50
             9  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            10  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   65     2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
            11  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             2 IAEC Building     70   65     4 BSCS-3       40   40
                                                             6 BICSE-7      25   25
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            12  255  255     1 SEECS UG Block   100   95     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     2 BIT-11       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
            13  255  255     1 SEECS UG Block   100   95     1 BIT-10       35   35
                                                             3 BSCS-2       35   35
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   70     4 BSCS-3       40   40
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     2 BIT-11       40   40
                                                             5 BEE-4        50   50
            14  255  255     1 SEECS UG Block   100  100     1 BIT-10       35   35
                                                             2 BIT-11       40   40
                                                             6 BICSE-7      25   25
                             2 IAEC Building     70   65     3 BSCS-2       35   35
                                                             7 BESE-3       30   30
                             3 RIMMS Building    90   90     4 BSCS-3       40   40
                                                             5 BEE-4        50   50
    
    98 rows selected.
    
    Elapsed: 00:00:01.42
    

    Published by: BrendanP on January 20, 2013 11:25
    I found the need to deduplicate regular expression:

    AND RegExp_Instr (r_c.itm_path | r_i.path, ',(\d+),.*?,\1,') = 0)

  • SQL query returns no row vs. multiple lines

    Hello

    I am trying to get the result of a simple sql query,
    If there is no row returned, he would have "No. ROWS" in the result set.
    Other wise all the rows containing data is necessary.

    Let me know how this could be achieved. Under query works for the latter and not first case as mentioned below

    OUTPUT

    + (box 1) when we use B_ID = 123456 +.

    IDS
    -----
    'NO LINE '.

    + (box 2) when we use B_ID = 12345 +.
    IDS
    -----
    1 11112345
    2 22212345
    create table TEMP_AAA
    (
      A_ID VARCHAR2(10),
      B_ID VARCHAR2(10)
    )
    
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('111','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('222','12345');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('333','12000');
    INSERT INTO TEMP_AAA(A_ID,B_ID) VALUES('444','10000');
    WITH 
    MATCH_ROWS AS
    (
           SELECT A_ID||B_ID IDS FROM TEMP_AAA WHERE B_ID=12345
    ),
    
    MATCH_ROW_COUNT AS
    (
           SELECT COUNT(1) AS COUNTS FROM MATCH_ROWS
    ),
    
    PROCESSED_ROWS AS
    (
           SELECT
                 CASE WHEN COUNTS = 0
                      THEN 
                       (SELECT NVL((SELECT IDS FROM TEMP_AAA WHERE B_ID=12345),'NO ROWS') IDS FROM DUAL)
                      ELSE
                       MATCH_ROWS.IDS
                 END IDS     
            FROM MATCH_ROWS,MATCH_ROW_COUNT
    )
    
    SELECT * FROM PROCESSED_ROWS;

    Hello

    I think you want to put this on a report or something. I have what would be easier to do this logic there. But if you want that this is possible.
    Like this

    with
    temp_aaa as
    (select '111' a_id ,'12345' b_id from dual union all
    select '222'      ,'12345'  from dual union all
    select '333'      ,'12000'  from dual union all
    select '444'      ,'10000'  from dual
    )
    , wanted_rows as
    ( select  '123456' B_ID from dual)
    select
      temp_aaa.A_ID || temp_aaa.B_ID IDS 
    
    from
      temp_aaa
      ,wanted_rows
    where
      temp_aaa.b_id = wanted_rows.b_id
    union all
    select
      'NO ROWS'
    FROM
      DUAL
    WHERE
      (SELECT COUNT(*) FROM TEMP_AAA, wanted_rows WHERE TEMP_AAA.B_ID = wanted_rows.B_ID) = 0
    

    In addition, you mix var and number of always use the same type or convert explicitly (to_number or to_char)

    WITH
    MATCH_ROWS AS
    (
           SELECT A_ID||B_ID IDS FROM TEMP_AAA WHERE      B_ID           =12345
    --                                                    varchar2(10)   number
    ),
    ...
    

    And again in the

                      THEN
                       (SELECT NVL((SELECT IDS FROM TEMP_AAA WHERE B_ID           =12345),'NO ROWS') IDS FROM DUAL)
    --                                                             varchar2(10)   number
    

    Kind regards

    Peter

Maybe you are looking for

  • Digital, analog output file trigger

    Hello I'm trying to produce an analog output to text file. I have attached the text file with entries and file vi. When I connect oscilloscope, there is no waveform.  I'm using labview for two days. What is wrong with my code?

  • Problem mit Daten aus ATFX-Datei

    Hallo, ICH habe identische Daten aus unterschiedlichen sources. Once direkt aus einem Datenlogger als ATFX, das andere bad wurden die gleichen Daten first in data base ASAM ODS importiert und von eine sleeps wieder in ein ATFX used. Leider wird dann

  • ProBook 4710 overheating

    I just pulled this out of the closet after the purchase of a Tablet - update of current patches - noticed after the update that the laptop was closed (I leave on through weekend for easy use). I didn't pay any attention to the closure, thought it was

  • Can I use a copy of HP OEM of Windows XP on a computer not HP after got rid of HP?

    original title: non - OEM I have a HP PC with Windows XP pre-installed. Recently, we got rid of this PC. I realized that this restore CD was windows 7 on it. Is there a way I can use this copy of windows on a machine no HP.

  • I have a desktop white with all the icons and the taskbar, but cannot set the background.

    original title: I have a white desktop with all icons and task bar, but can't set a background. Nothing happens when I right click on the desktop to adjust only the properties please help We have a white desk with all the icons and taskbar. Everythin