How can I count in Joins?

Hello,
I have the following table definitions:
--- Tables
CREATE TABLE group_test
(ID number NOT NULL,
group_name varchar2(20));
ALTER TABLE group_test ADD (CONSTRAINT group_test_p primary key (ID));
CREATE TABLE member_of_groups
(group_test_id number not null,
member varchar2(20));
ALTER TABLE member_of_groups ADD (CONSTRAINT gt_id_fk FOREIGN KEY (group_test_id) REFERENCES group_test(ID));
--- Fill in some data
insert into group_test (id,group_name) values(1,'group_1');
insert into group_test (id,group_name) values(2,'group_2');
insert into group_test (id,group_name) values(3,'group_3');
insert into group_test (id,group_name) values(4,'group_4');
insert into group_test (id,group_name) values(5,'group_5');
commit;
insert into member_of_groups (group_test_id,member) values (1,'Miller');
insert into member_of_groups (group_test_id,member) values (1,'Smith');
insert into member_of_groups (group_test_id,member) values (2,'Walker');
insert into member_of_groups (group_test_id,member) values (3,'Almeida');
insert into member_of_groups (group_test_id,member) values (3,'Walton');
insert into member_of_groups (group_test_id,member) values (3,'McScrooge');
insert into member_of_groups (group_test_id,member) values (4,'Hoover');
insert into member_of_groups (group_test_id,member) values (4,'Brando');
insert into member_of_groups (group_test_id,member) values (5,'Walther');
commit;
-------------------- Queries
select all group_test.group_name,member_of_groups.member from group_test, member_of_groups where group_test.id = member_of_groups.group_test_id;
---------- RESULT
GROUP_NAME MEMBER
group_1 Miller
group_1 Smith
group_2 Walker
group_3 Almeida
group_3 Walton
group_3 McScrooge
group_4 Hoover
group_4 Brando
group_5 Walther
select count(1) as counter from group_test, member_of_groups where group_test.id = member_of_groups.group_test_id group by group_test.group_name;
---------- RESULT
COUNTER
2
1
3
2
1
----- PL/SQL-Code
set serveroutput on
DECLARE
     counter number := 0;
     group_store group_test.group_name%TYPE := '';
     mem_store member_of_groups.member%TYPE := '';
BEGIN
     for c_members in (select all group_test.group_name as gn,member_of_groups.member as mem from group_test, member_of_groups where group_test.id = member_of_groups.group_test_id) loop
          IF (group_store = c_members.gn) then
               counter := counter + 1;
          else
               counter := 1;
               group_store := c_members.gn;
               mem_store := c_members.mem;
          end if;
          if (counter > 1) then          -- Output only groups with more than 1 member
               if (counter = 2) then     -- Output of the first row
                    dbms_output.put_line(group_store || '     ' || mem_store || '     1');
               end if;
               dbms_output.put_line(c_members.gn || '     ' || c_members.mem || '     ' || counter);
          end if;
     end loop;
end;
---------- RESULT
group_1 Miller 1
group_1 Smith 2
group_3 Almeida 1
group_3 Walton 2
group_3 McScrooge 3
group_4 Hoover 1
group_4 Brando 2
----------------------------------------- END OF CODE
Now I want to do this with a plain SQL query. Any hints?
Holger
Edited by: user4546673 on 25.11.2009 06:19

user4546673 wrote:
Thank you very much,
Sorry, your solution is not exact the same and this is not working:
select group_test.group_name,member_of_groups.member,
row_number() over(partition by group_test.group_name order by member_of_groups.member) rn
from group_test,member_of_groups where group_test.id = member_of_groups.group_test_id and rn > 1;
ORA-00904: "RN": invalid identifierIt is not what you asked originally. Analytical functions are calculated after rows are fetched, so if you wnat rn > 1, you need to wrap it in in-line view:
SQL> select group_test.group_name,member_of_groups.member,
  2  row_number() over(partition by group_test.group_name order by member_of_groups.member) rn
  3  from group_test,member_of_groups where group_test.id = member_of_groups.group_test_id and rn > 1;
from group_test,member_of_groups where group_test.id = member_of_groups.group_test_id and rn > 1
ERROR at line 3:
ORA-00904: "RN": invalid identifier
select  group_name,
        member
  from  (
         select  group_test.group_name,
                 member_of_groups.member,
                 row_number() over(partition by group_test.group_name order by member_of_groups.member) rn
           from  group_test,
                 member_of_groups
           where group_test.id = member_of_groups.group_test_id
  where rn > 1
  order by group_name,
           rn
GROUP_NAME           MEMBER
group_1              Smith
group_3              McScrooge
group_3              Walton
group_4              Hoover
SQL> SY.

Similar Messages

  • How can I count the participants' number in TextChatApp? (using SharedObject, FMS)

    Hi all.
    How can I count participants' number?
    If the 3st user enter the room, the 3st user have to know that how many users are in the room.
    How do I know how many users are in the room?
    Thanks in advanced.
    Kevin.

    You have server side hooks for connections coming in or being closed (including here custom code for server disconnecting users for idle purposes).
    you need to keep track of the connections I don't remember now what FMS offers out of the box. Let's assume not much.
    When connection is coming in you can choose to accept or reject it. When you accept a connection you need to add it to your existing connections array or whatever data structure you use to keep track of them. Also you need to iterate to all connected users (clients) and call a custom method "userJoined()" on them to notify that a new user has joined.
    When a user leaves you need to remove the user from the collection and also notify that it left.
    on wowza you have stuff like :
    private HashSet();
    public void onConnect(IClient client, RequestFunction function,
                AMFDataList params) {
    public void onDisconnect(IClient client) {
    public void onConnectAccept(IClient client) {
        _connectedClients.add(client); 
        sendUserJoined();
    @param client
        public void onConnectReject(IClient client) {
             _connectedClients.remove(client); 
            sendUserLeft();
        public void sendUserJoined(String userName)
            Iterator it = _connectedClients.iterator();
            while (it.hasNext()) { 
                IClient each =  it.next();
                    each.call("userLeft", userName);
    FMS has similar hooks. This is simplified but you have a rough idea. You can call clients with no parameters and then is up to client so call back for updates to the server if interested. You need to implement "userJoined" and userLeft client side also.
    C

  • How Can We Tune the Joins with "OR" Caluse ?

    Hi
    We've identified one Query in one of Our PL/SQL Stored Procedure which is taking huge time to fetch the records. I have simulated the problem as shown below. The problem Is, How can i tune the Jions with "OR" Clause. i have tried replacing them with Exists Caluse, But the Performance was not much was expected.
    CREATE TABLE TEST
    (ID NUMBER VDATE DATE );
    BEGIN
      FOR i IN 1 .. 100000 LOOP
        INSERT INTO TEST
        VALUES
          (i, TO_DATE(TRUNC(DBMS_RANDOM.VALUE(2452641, 2452641 + 364)), 'J'));
        IF MOD(i, 1000) = 0 THEN
          COMMIT;
        END IF;
      END LOOP;
    END;
    CREATE TABLE RTEST1 ( ID NUMBER, VMONTH NUMBER );
    INSERT INTO RTEST1
    SELECT ID, TO_NUMBER(TO_CHAR(VDATE,'MM'))
    FROM TEST ;
    CREATE TABLE RTEST2 ( ID NUMBER, VMONTH NUMBER );
    INSERT INTO RTEST2
    SELECT ID, TO_NUMBER(TO_CHAR(VDATE,'MM'))
    FROM TEST;
    CREATE INDEX RTEST1_IDX2 ON RTEST1(VMONTH)
    CREATE INDEX RTEST2_IDX1 ON RTEST2(VMONTH)
    ALTER TABLE RTEST1 ADD CONSTRAINT RTEST1_PK  PRIMARY KEY (ID)
    ALTER TABLE RTEST2 ADD CONSTRAINT RTEST2_PK  PRIMARY KEY (ID)
    SELECT A.ID, B.VMONTH
    FROM RTEST1 A , RTEST2 B
    WHERE A.ID = B.ID  
    AND ( (A.ID = B.VMONTH) OR ( B.ID = A.VMONTH ) )  
    BEGIN
    DBMS_STATS.gather_table_stats(ownname => 'PHASE30DEV',tabname => 'RTEST1');  
    DBMS_STATS.gather_table_stats(ownname => 'PHASE30DEV',tabname => 'RTEST2');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST1_IDX1');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST2_IDX2');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST1_IDX2');
    DBMS_STATS.gather_index_stats(ownname => 'PHASE30DEV',indname => 'RTEST2_IDX1');
    END; Pls suggest !!!!!!! How can I tune the Joins with "OR" Clause.
    Regards
    RJ

    I don't like it, but you could use a hint:
    SQL>r
      1  SELECT A.ID, B.VMONTH
      2  FROM RTEST1 A , RTEST2 B
      3  WHERE A.ID = B.ID
      4* AND ( (A.ID = B.VMONTH) OR ( B.ID = A.VMONTH ) )
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=94 Card=2 Bytes=28)
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'RTEST2' (Cost=94 Card=1 Bytes=7)
       2    1     NESTED LOOPS (Cost=94 Card=2 Bytes=28)
       3    2       TABLE ACCESS (FULL) OF 'RTEST1' (Cost=20 Card=100000 Bytes=700000)
       4    2       BITMAP CONVERSION (TO ROWIDS)
       5    4         BITMAP AND
       6    5           BITMAP CONVERSION (FROM ROWIDS)
       7    6             INDEX (RANGE SCAN) OF 'RTEST2_PK' (UNIQUE)
       8    5           BITMAP OR
       9    8             BITMAP CONVERSION (FROM ROWIDS)
      10    9               INDEX (RANGE SCAN) OF 'RTEST2_IDX1' (NON-UNIQUE)
      11    8             BITMAP CONVERSION (FROM ROWIDS)
      12   11               INDEX (RANGE SCAN) OF 'RTEST2_PK' (UNIQUE)
    Statistics
              0  recursive calls
              0  db block gets
         300332  consistent gets
              0  physical reads
              0  redo size
            252  bytes sent via SQL*Net to client
            235  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              2  rows processed
    SQL>SELECT /*+ ordered use_hash(b) */ A.ID, B.VMONTH
      2    FROM RTEST1 A, RTEST2 B
      3   WHERE A.ID = B.ID  AND(A.ID = B.VMONTH OR B.ID = A.VMONTH)
      4  ;
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=175 Card=2 Bytes=28)
       1    0   HASH JOIN (Cost=175 Card=2 Bytes=28)
       2    1     TABLE ACCESS (FULL) OF 'RTEST1' (Cost=20 Card=100000 Bytes=700000)
       3    1     TABLE ACCESS (FULL) OF 'RTEST2' (Cost=20 Card=100000 Bytes=700000)
    Statistics
              9  recursive calls
              0  db block gets
            256  consistent gets
            156  physical reads
              0  redo size
            252  bytes sent via SQL*Net to client
            235  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              2  rows processed

  • How can i count no rows in my database table

    plz tell me how can i count no of rows in my database table with[b] ResultSet object

    Hi ! hope this code helps you .
    We can use the count(*) to get the total no of records in the table ad then access it through the getString method .
    import java.sql.*;
    public class JdbcTest
         public static void main(String [] args ) throws Exception
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              String DBURL = "jdbc:odbc:mydsn" ;
              Connection conn = DriverManager.getConnection(DBURL);
              Statement st = conn.createStatement();
              ResultSet rs = st.executeQuery("select count(*) from table1");
              rs.next();
              System.out.println("total rec = " + rs.getString(1));     
    Cheers !

  • How can I count events during a given time with 2 counters (6025 E)

    Hi, How can I count events during a given time (1 sec for example) with 2 counters:
    what is the best way?
    how should i configurate both counter?
    i have done the 1st counter in ev_counter with the gate being the output of the 2nd; and how can i say to the 2nd to trig the first after 1 sec counting? (trig at start and at end) what are the functoins calls in NIDAQ. i am using Visual C++

    Greetings,
    When you perform event counting a gate signal can be added such that if a low signal occurs on the gate, then the counter will pause. When a high signal is seen, the counter will continue counting edges. When you install the NI-DAQ driver you should have installed the examples for Visual C++. The counter examples are found in \Program Files\National Instruments\NI-DAQ\Examples\VisualC\Ctr. Take a look at STCeventCount.C. Be sure to only use STC examples with your hardware. The E-series boards contain the DAQ-STC chip.
    Now, all you need is a gate signal with a width (high time) of 1 second. You could use an external frequency or pulse generator to do this. Or, you could just use the second counter found on your PCI-6025E board. In this
    case you could configure the second counter to generate a single pulse. Take a look at the STCgenerateSinglePulse.C example. As long as the pulse is in a high state for one second you can use it to gate (or time) your counting of events.
    Regards,
    Justin Britten
    Applications Engineer
    National Instruments

  • How can I count time with labview7?

    Hi
    How can I count time with labview 7 and NI-DAQmx like I did with labview 6.1 and "count time-easy.vi" (count event or Time.vi).
    I have a 6025E and labview 7.0
    Thanks

    I am not sure what you want to do or why..
    ... but here goes (some suggestions)
    If you want to count the time between two events, you have a choice, you may use the Tick Count. Inisitalize it first by getting a timestamp and then do a difference within a loop. The difference will give you the time elapsed in ms.
    You can also use the Get Date/Time String or Get Date / Time in seconds and once again take a snapshot when a first even occurs and another snapshot at the next even (at a point where you want to measure elasped time). This method is particularly useful if you want to timestamp an event.
    If I didn't answer your question, can you elaborate what you mean by "How can I count time".
    Best of luck..
    JLV

  • How can we say if Join better than using Sub Queries ??

    Hi all,
    I am trying to understand the rationale behind "Is _Inner Join_ better than using _Sub Query_ ?" for this scenario ...
    I have these tables --
    Table1 { *t1_Col_1* (PrimaryKey), t1_Col_2, t1_Col_3, t1_Col_4 }
    -- Number of rows = ~4Million , t1_Col_3 has say 60% entries non-zero -----> (Condition 4)
    Table2 { *t2_Col_1* (PK), t2_Col_2, t2_Col_3 }
    -- Number of rows = ~150Million, t2_Col_2 maps to t1_Col_1 -----> (Condition 1). This means for every distinct value of t1_Col_1 (its PK) we'll have multiple rows in Table2.
    Table3 { *t3_Col_1* (PK), t3_Col_2, t3_Col_3 }
    -- Number of rows = ~50K, t3_Col_1 maps to t1_Col_2 -----> (Condition 2)
    Table4 { *t4_Col_1* (PK), t4_Col_2, t4_Col_3 }
    -- Number of rows = ~1K, t4_Col_2 maps to t3_Col_2 -----> (Condition 3)
    Now here are the 2 queries: -
    Query using direct join --
    SELECT t1_Col_1, t2_Col_1, t3_Col_1, t4_Col_2
    FROM Table1, Table2, Table3, Table4
    WHERE t1_Col_1=t2_Col_2 -- Condition 1
    AND t1_Col_2=t3_Col_1 -- Condition 2
    AND t3_Col_2=t4_Col_1 -- Condition 3
    AND t1_Col_3 != 0
    Query using SubQuery --
    SELECT t1_Col_1, t2_Col_1, t3_Col_1, t4_Col_2
    FROM Table2,
    (SELECT t1_Col_1, t3_Col_1, t4_Col_2
    FROM Table1,Table3, Table4
    WHERE
    AND t1_Col_2=t3_Col_1 -- Condition 2
    AND t3_Col_2=t4_Col_1 -- Condition 3
    AND t1_Col_3!= 0
    WHERE t1_Col_1=t2_Col_2 -- Condition 1
    Now the golden question is - How can I document with evidence that Type-1 is better than Type-2 or the other way ? I think the 3 things in comparison are: -
    - Number of rows accessed (Type-1 better ?)
    - Memory/Bytes used (Again Type-1 better ?)
    - Cost ( ?? )
    (PS - testing on both MySQL, Oracle10g)
    Thanks,
    A

    So, is it right to conclude that Optimizer uses the optimal path and then processes the query resulting in nearly the same query execution time ?If the optimizer transforms two queries so that they end up the same, then they will run in the same time. Of course, sometimes it cannot do so because of the the way the data is defined (nulls are often a factor; constraints can help it) or the way the query is written, and sometimes it misses a possible optimization due to inaccurate statistics or other information not available to it, or limitations of the optimizer itself.
    Is this the right place to ask for MySQL optimization ?Probably not.

  • How can I make this join in ADF and make CRUD operation in this

    How to make this relation in ADF
    I have table employees and this is my master table
    Table Name: Employees
    Columns:
    Employee_id(PK)
    Employee_name
    Employee_Salary
    I have a child table that is called related employee that contains employees related to this employee
    Table_name: Related_Employee
    Columns:
    Related_Employee_Table_Id(PK)
    Employee_id(FK)
    Related_Employee_Id
    When I open employee id = 100 for example and add related employee id = 10
    this is added with no problem but the requirement is that when I open employee 10 I find employee id 100 as related employee
    How can I make this scenario.

    The best way to understand this is to look at an example. If you are using an oracle database such as XE for you have a schema called hr. This shema has a number of tables two of which are departments and employees. a department has multiple employees correct. So in your example a employee may be related to x # of other employees perhaps. A very similar scenario as that in the hr Schema. If you don't have an Oracle XE database, download one from here -> http://www.oracle.com/technetwork/database/express-edition/downloads/index.html
    Create Business Components off of the Departments and Employees schema and you'll see that due to the db design, you get what you're talking about for free (i.e. the join). Thus, you have the master-detail relationship you're looking for. For a quick tip, here is the relationship between departments and employees in the hr schema via a create script that you can exam with data inserts included:
    SET SQLBLANKLINES ON
    CREATE TABLE DEPARTMENTS
    DEPARTMENT_ID NUMBER(4, 0) NOT NULL
    , DEPARTMENT_NAME VARCHAR2(30 BYTE) NOT NULL
    , MANAGER_ID NUMBER(6, 0)
    , LOCATION_ID NUMBER(4, 0)
    , CONSTRAINT DEPT_ID_PK PRIMARY KEY
    DEPARTMENT_ID
    USING INDEX
    CREATE UNIQUE INDEX DEPT_ID_PK ON DEPARTMENTS (DEPARTMENT_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ENABLE
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 1
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE TABLE EMPLOYEES
    EMPLOYEE_ID NUMBER(6, 0) NOT NULL
    , FIRST_NAME VARCHAR2(20 BYTE)
    , LAST_NAME VARCHAR2(25 BYTE) NOT NULL
    , EMAIL VARCHAR2(25 BYTE) NOT NULL
    , PHONE_NUMBER VARCHAR2(20 BYTE)
    , HIRE_DATE DATE NOT NULL
    , JOB_ID VARCHAR2(10 BYTE) NOT NULL
    , SALARY NUMBER(8, 2)
    , COMMISSION_PCT NUMBER(2, 2)
    , MANAGER_ID NUMBER(6, 0)
    , DEPARTMENT_ID NUMBER(4, 0)
    , CONSTRAINT EMP_EMP_ID_PK PRIMARY KEY
    EMPLOYEE_ID
    USING INDEX
    CREATE UNIQUE INDEX EMP_EMP_ID_PK ON EMPLOYEES (EMPLOYEE_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ENABLE
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 1
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX DEPT_LOCATION_IX ON DEPARTMENTS (LOCATION_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_DEPARTMENT_IX ON EMPLOYEES (DEPARTMENT_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_JOB_IX ON EMPLOYEES (JOB_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_MANAGER_IX ON EMPLOYEES (MANAGER_ID ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    CREATE INDEX EMP_NAME_IX ON EMPLOYEES (LAST_NAME ASC, FIRST_NAME ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_EMAIL_UK UNIQUE
    EMAIL
    USING INDEX
    CREATE UNIQUE INDEX EMP_EMAIL_UK ON EMPLOYEES (EMAIL ASC)
    LOGGING
    TABLESPACE "USERS"
    PCTFREE 10
    INITRANS 2
    STORAGE
    INITIAL 65536
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    BUFFER_POOL DEFAULT
    ENABLE;
    ALTER TABLE DEPARTMENTS
    ADD CONSTRAINT DEPT_LOC_FK FOREIGN KEY
    LOCATION_ID
    REFERENCES LOCATIONS
    LOCATION_ID
    ENABLE;
    ALTER TABLE DEPARTMENTS
    ADD CONSTRAINT DEPT_MGR_FK FOREIGN KEY
    MANAGER_ID
    REFERENCES EMPLOYEES
    EMPLOYEE_ID
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_DEPT_FK FOREIGN KEY
    DEPARTMENT_ID
    REFERENCES DEPARTMENTS
    DEPARTMENT_ID
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_JOB_FK FOREIGN KEY
    JOB_ID
    REFERENCES JOBS
    JOB_ID
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_MANAGER_FK FOREIGN KEY
    MANAGER_ID
    REFERENCES EMPLOYEES
    EMPLOYEE_ID
    ENABLE;
    ALTER TABLE DEPARTMENTS
    ADD CONSTRAINT DEPT_NAME_NN CHECK
    (DEPARTMENT_NAME IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_EMAIL_NN CHECK
    (EMAIL IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_HIRE_DATE_NN CHECK
    (HIRE_DATE IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_JOB_NN CHECK
    (JOB_ID IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_LAST_NAME_NN CHECK
    (LAST_NAME IS NOT NULL)
    ENABLE;
    ALTER TABLE EMPLOYEES
    ADD CONSTRAINT EMP_SALARY_MIN CHECK
    (SALARY > 0)
    ENABLE;
    COMMENT ON TABLE DEPARTMENTS IS 'Departments table that shows details of departments where employees
    work. Contains 27 rows; references with locations, employees, and job_history tables.';
    COMMENT ON TABLE EMPLOYEES IS 'employees table. Contains 107 rows. References with departments,
    jobs, job_history tables. Contains a self reference.';
    COMMENT ON COLUMN DEPARTMENTS.DEPARTMENT_ID IS 'Primary key column of departments table.';
    COMMENT ON COLUMN DEPARTMENTS.DEPARTMENT_NAME IS 'A not null column that shows name of a department. Administration,
    Marketing, Purchasing, Human Resources, Shipping, IT, Executive, Public
    Relations, Sales, Finance, and Accounting. ';
    COMMENT ON COLUMN DEPARTMENTS.MANAGER_ID IS 'Manager_id of a department. Foreign key to employee_id column of employees table. The manager_id column of the employee table references this column.';
    COMMENT ON COLUMN DEPARTMENTS.LOCATION_ID IS 'Location id where a department is located. Foreign key to location_id column of locations table.';
    COMMENT ON COLUMN EMPLOYEES.EMPLOYEE_ID IS 'Primary key of employees table.';
    COMMENT ON COLUMN EMPLOYEES.FIRST_NAME IS 'First name of the employee. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.LAST_NAME IS 'Last name of the employee. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.EMAIL IS 'Email id of the employee';
    COMMENT ON COLUMN EMPLOYEES.PHONE_NUMBER IS 'Phone number of the employee; includes country code and area code';
    COMMENT ON COLUMN EMPLOYEES.HIRE_DATE IS 'Date when the employee started on this job. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.JOB_ID IS 'Current job of the employee; foreign key to job_id column of the
    jobs table. A not null column.';
    COMMENT ON COLUMN EMPLOYEES.SALARY IS 'Monthly salary of the employee. Must be greater
    than zero (enforced by constraint emp_salary_min)';
    COMMENT ON COLUMN EMPLOYEES.COMMISSION_PCT IS 'Commission percentage of the employee; Only employees in sales
    department elgible for commission percentage';
    COMMENT ON COLUMN EMPLOYEES.MANAGER_ID IS 'Manager id of the employee; has same domain as manager_id in
    departments table. Foreign key to employee_id column of employees table.
    (useful for reflexive joins and CONNECT BY query)';
    COMMENT ON COLUMN EMPLOYEES.DEPARTMENT_ID IS 'Department id where employee works; foreign key to department_id
    column of the departments table';

  • How can i count the word in a cell.

    Dear Experts,
    i want to count the word in cell how can i do this ?
    Isthere any function ?
    plz give logic or command.

    You can ty :
    SQL> var text varchar2(50)
    SQL> exec :text := 'How do I count the number of words in my cell?'
    PL/SQL procedure successfully completed.
    SQL> select text,
      2         sum(case when substr(text,rownum,1)=' '
      3                       and substr(text,rownum-1,1)!=' '
      4                  then 1
      5                  else 0 end) nb_word
      6  from (select rownum,:text||' ' text,length(:text) ln from dual)
      7  connect by level <= ln+1
      8  group by text
      9  /
    TEXT
       NB_WORD
    How do I count the number of words in my cell?
            11
    SQL>  exec :text := 'How     do I count the number of words in my   cell?    '
    BEGIN :text := 'How     do I count the number of words in my   cell?    '; END;
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 1
    SQL> var text varchar2(1000)
    SQL> exec :text := 'How     do I count the number of words in my   cell?    '
    PL/SQL procedure successfully completed.
    SQL> select text,
      2         sum(case when substr(text,rownum,1)=' '
      3                       and substr(text,rownum-1,1)!=' '
      4                  then 1
      5                  else 0 end) nb_word
      6  from (select rownum,:text||' ' text,length(:text) ln from dual)
      7  connect by level <= ln+1
      8  group by text
      9  /
    TEXT
       NB_WORD
    How     do I count the number of words in my   cell?
            11
    SQL> select * from v$version where rownum=1;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    SQL> Nicolas.
    Well, we can discuss about what limit a word : here space, but there is point, double-point, and so on... And about what is a word : do the punctuation is a word ?
    For example :
    "It's a word !"=>how many words are in this sentence ?
    http://en.wikipedia.org/wiki/Word
    Message was edited by:
    N. Gasparotto

  • How can I count patterns of multiple rows in a table

    I just can't wrap my head around a query I need to identify the unique set of patterns with a table...by patterns I mean the following...
    This is medical procedural data, wherein the first procedure code is followed by 0 or more procedures in a sequence for each case. I need to find out how many of each sequence of procedures exist in the table from all the cases...
    row_id caseid proc_code sequence
    1 1 A 1
    2 1 B 2
    3 2 C 1
    4 3 A 1
    5 3 B 2
    So in this example data set I would like an output like this (something similar that would produce the number of times A followed B...and so on)
    row_id proc_set count(*)
    1 A-B 2
    2 C 1
    If someone could at least point me in a direction, I'd appreciate it...thanks ron.

    Interesting variation, Solomon.Yes, but gives different results if there are more than two linked procedures:
    SQL> with t as (
      2             select 1 case_id,'A' proc_code,1 seq from dual union all
      3             select 1,'B',2 from dual union all
      4             select 1,'C',3 from dual union all
      5             select 2,'C',1 from dual union all
      6             select 3,'A',1 from dual union all
      7             select 3,'B',2 from dual
      8            )
      9  select  proc_set,
    10          count(*) cnt
    11    from  (
    12           select  case level
    13                     when 1 then proc_code
    14                     else connect_by_root(proc_code) || '-' || proc_cod
    15                   end proc_set
    16             from  t
    17             where connect_by_isleaf = 1
    18             start with seq = 1
    19             connect by case_id = prior case_id
    20                    and seq     = prior seq + 1
    21          )
    22    group by proc_set
    23  /
    PROC_SET                    CNT
    A-B                           1
    C                             1
    A-C                           1While we get
    SQL> with t as (
      2  select 1 row_id, 1 caseid, 'A' proc_code, 1 sequence from dual union
      3  select 2, 1, 'B', 2 from dual union
      4  select 4, 2, 'C', 1 from dual union
      5  select 3, 1, 'C', 3 from dual union
      6  select 5, 3, 'A', 1 from dual union
      7  select 6, 3, 'B', 2 from dual)
      8  select row_number() over (order by proc_set) row_id,  proc_set, count(0) from (
      9  select ltrim(sys_connect_by_path(proc_code,'-'),'-') proc_set
    10    from t
    11  where connect_by_isleaf=1
    12  connect by prior sequence+1 = sequence and prior caseid=caseid
    13  start with sequence=1)
    14  group by proc_set;
        ROW_ID PROC_SET               COUNT(0)
             1 A-B                           1
             2 A-B-C                         1
             3 C                             1Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

  • How can i count no.of links on a web page using VBA programmability

    hi,
    could anybody help me in getting the no.of links,no.of images in e-tester using custom programmability test.
    i'm new to e-tester.
    earlier i was using QTP. i know VBScript and how to getitemscount in QTP

    Hi pasumarthi,
    Great question! Try putting the following code in the Private Sub RSWVBAPage_afterPlay(). If you run into problems, please reply to this message. This code can also be copied into a custom vba test if you wanted to test the number of links and images on the page against a specific number.
    'Variable declarations
    Dim images As Collection
    Dim links As Collection
    Dim resultbImages As Boolean
    Dim resultbLinks As Boolean
    Dim item As Object
    'Initialize variables
    resultbImages = False
    resultbLinks = False
    'Get all the elements that have a tag of IMG
    resultbImages = RSWApp.om.FindElements(images, , "IMG")
    'Get all the elements that have a tag of A
    resultbLinks = RSWApp.om.FindElements(links, , "A")
    Call RSWApp.WriteToLog(, , "There are " & images.count & " images on the page")
    Call RSWApp.WriteToLog(, , "There are " & links.count & " links on the page")
    Message was edited by: kgehrke

  • How can I add left join in the coding

    I intend to dynamic add left jion in my java class.
    so I write the coding like below:
    incident_id = svc_yokyu_id(+)
    (Both of them have been selected in the select sentence.)
    However, when I run the app, it will throw a sql error.(ora-01416)
    then I copy the error sql sentence and try to test it
    QRSLT WHERE (incident_id = svc_yokyu_id(+))--this is a error sql sentence.
    Finding that if I delete the left join,(+), the sql will run right,
    or I modify the sql like
    QRSLT WHERE incident_id in (Select svc_yokyu_id from xxfm_srl_sr_jc_relation xssjr where incident_id = xssjr.svc_yokyu_id(+)) , it run right as well.
    according to bussiness requestion, I can't write the coding like above,
    so, i don't know how to implement it.
    and i hope to your advice. thx

    Does a hand come out of the screen, grabbing you by the wrist, every time you try?
    Just guessing…
    Peter

  • How can i count the times one TAG occurred in a XMLTYPE?

    hi all
    is there method i can use to count the times one specified TAG occurred in a XMLTYPE?
    i just konw the method getClobVal,existNode,extract,...
    but none seems can help this
    anyone can help me?

    i see
    i think i know how to use Xpath func
    but when i try the following statement on sqlplus( Release 9.2.0.4.0),it says :"the XPATH is not supportted"
    declare
    l_xml xmltype;
    num number;
    begin
    select XML_BODY into l_xml from KD_SHIMEN_SEISEI w where FILE='SMNDATA';
    --get value OK!
    num := xmltype.extract(l_xml,'/Tag1[1]/Tag2/text()').getNumberVal();
    --sum or count ,failed,Xpath not support?
    num := xmltype.extract(l_xml,'sum(/Tag1/Tag2/text())').getNumberVal();
                   DBMS_OUTPUT.PUT_LINE(num);
    end;
    can u explain this?

  • How can I count the number of values in one column which answer to a condition in another column?

    I'm using Numbers 3.2 and would like to count the names in a column which satisfy a condition in a different column. There are 3 "streams" through which these names have come to me, and I would like to easily identify how many have come from each stream. Any help?

    Hi DirtyDawg,
    COUNTIF is your friend here.
    If your source is in column C and your streams are 1, 2 and 3:
    =COUNTIF(C,"=stream1")
    =COUNTIF(C,"=stream2")
    =COUNTIF(C,"=stream3")
    These need to be in a footer or header row or in a different column than C.
    hope this helps,
    quinn

  • How can I count the total number of keyframes in a project in After effects?

    I would just like to know how to get the quantity of how many keyframes I have in my project. I've always thought counting keyframes is pretty interesting xD

    That's a new one!  I don't think anyone's ever been curious about that.  Which means it's an excellent bet that there isn' any automated way to do it: it may be interesting from an academic viewpoint, but I'm stumped about a practical use.  I think you'd just have to count layer by layer, and hope you don't get interrupted.

Maybe you are looking for