cloumn on the emp table online

Hello world

I want to do EMP table in columns by departments
under the name of employees of each Department

for example,.

10. 20
CLARK | SMITH
KING | FORD
MILLER | ADAMS

Thank you

You mean like this?

SQL> select * from emp;

     EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
---------- ---------- --------- ---------- -------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
      7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
      7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10

14 rows selected.

SQL> ed
Wrote file afiedt.buf

  1  with d1 as (select ename, row_number() over (order by empno) as rn from emp where deptno = 10)
  2      ,d2 as (select ename, row_number() over (order by empno) as rn from emp where deptno = 20)
  3      ,d3 as (select ename, row_number() over (order by empno) as rn from emp where deptno = 30)
  4  --
  5  select d1.ename as dept10, d2.ename as dept20, d3.ename as dept30
  6  from   d1 full outer join d2 on (d2.rn = d1.rn)
  7*           full outer join d3 on (d3.rn = nvl(d2.rn,d1.rn))
SQL> /

DEPT10     DEPT20     DEPT30
---------- ---------- ----------
CLARK      SMITH      ALLEN
KING       JONES      WARD
MILLER     SCOTT      MARTIN
           ADAMS      BLAKE
           FORD       TURNER
                      JAMES

6 rows selected.

As already mentioned, in a reporting tool is much better.

Tags: Database

Similar Questions

  • How to insert 10,000 records test data into the emp table

    Hi I am new to oracle can someone please help me write a program so that I can insert the test data into the emp table
    SELECT       LEVEL empno,
                 DBMS_RANDOM.string ('U', 20) emp_name,
                 TRUNC (DBMS_RANDOM.VALUE (10000, 100000), 2) sal,
                 DBMS_RANDOM.string ('U', 10) job,
                 TO_DATE ('1990-01-01', 'yyyy-mm-dd')
                 + TRUNC (DBMS_RANDOM.VALUE (1, 6000), 0)
                   hiredate,
                 CASE
                   WHEN LEVEL > 10 THEN TRUNC (DBMS_RANDOM.VALUE (1, 11), 0)
                   ELSE NULL
                 END
                   mgr,
                 TRUNC (DBMS_RANDOM.VALUE (1, 5), 0) deptno
    FROM         DUAL
    CONNECT BY   LEVEL <= 10000
    
  • How can I get the second and third highest salary from the emp table

    How can I get the second and third highest salary from the emp table in the ecah Department
    SQL> ed
    Wrote file afiedt.buf
    
      1  select empno, ename, sal, deptno
      2  from (
      3    select empno, ename, sal, deptno, dense_rank() over (partition by deptno order by sal desc) as rn
      4    from emp
      5    )
      6* where rn in (2,3)
    SQL> /
    
         EMPNO ENAME             SAL     DEPTNO
    ---------- ---------- ---------- ----------
          7782 CLARK            2450         10
          7934 MILLER           1300         10
          7566 JONES            2975         20
          7876 ADAMS            1100         20
          7499 ALLEN            1600         30
          7844 TURNER           1500         30
    
    6 rows selected.
    
    SQL>
    
  • selecting max 5 salaries in the emp table

    Hi I tried the following query to obtain the emp table max 5 salaries...
    SQL> select sal
      2  from (select sal,empno from emp order by sal desc
      3  where rownum<6;
    
           SAL
    ----------
          5000
          3000
          3000
          2975
          2850
    But here in the output of the duplicate rows are there... I need to remove this and number total should be equal to only 5...
    If I put the distinct clause, then I'll take 4 rows only... but I need the salaries of the top 5...

    Thank you
    select *
      from (
    select distinct sal
      from emp
     order by sal desc
     ) where rownum <= 5
    ;
    
  • SELECT on the emp table query

    Hello


    How to find the display the o/p as a manager name under employees dependent child parent like relation ship on the noraml emp table:

    sample o/p:

    use of name
    Nativity scene XX
    sales of yy
    YY1 sales
    Manager of the AA
    marketing of RR
    RR1 marketing


    Thank you

    921306 wrote:

    So I need, like that, child-parent relationship between the Manager under employees...

    Then join the parent with the child entity entity to create the parent-child relationship.

    The two entities are in the same table, it means to join the table to itself. For example

    SQL> select
      2          child.ename                     as CHILD,
      3          child.job                       as CHILD_JOB,
      4          nvl(parent.ename,'')      as PARENT,
      5          parent.job                      as PARENT_JOB
      6  from emp parent,
      7       emp child
      8  where child.mgr = parent.empno (+)
      9  /
    
    CHILD      CHILD_JOB PARENT     PARENT_JO
    ---------- --------- ---------- ---------
    FORD       ANALYST   JONES      MANAGER
    SCOTT      ANALYST   JONES      MANAGER
    JAMES      CLERK     BLAKE      MANAGER
    TURNER     SALESMAN  BLAKE      MANAGER
    MARTIN     SALESMAN  BLAKE      MANAGER
    WARD       SALESMAN  BLAKE      MANAGER
    ALLEN      SALESMAN  BLAKE      MANAGER
    MILLER     CLERK     CLARK      MANAGER
    ADAMS      CLERK     SCOTT      ANALYST
    CLARK      MANAGER   KING       PRESIDENT
    BLAKE      MANAGER   KING       PRESIDENT
    JONES      MANAGER   KING       PRESIDENT
    SMITH      CLERK     FORD       ANALYST
    KING       PRESIDENT 
    
    14 rows selected.
    
    SQL> 
    

    The basic concept is easy - set the parent entity, set the child entity, join the parent to the child.

    If some entities will not have parents (root entities), then an outer join is required of the child entity to the parent entity.

    Everything simply because the two entities are in the same table, does not change the logic or the approach. It's perfectly valid for a join table.

  • sum of sal and comm in the emp table

    Hi all

    for the table emp with enam, eno, dept, sal and comm fields

    I want to display a field in oracle forms 6i, who will show me the sum of sal and comm

    I've created a field of no database
    and wrote this code in the formula
    declare
    summ number(10);
    begin
    
    summ=:sal + :comm
    end;
    but I get the compilation failed

    kindly Guide

    thanking in advance

    Hello

    your code

    declare
    summ number(10);
    begin
    
    summ =:sal + :comm  --this line must be  summ :=  nvl(:sal,0) + nvl(:comm ,0)
    end;
    

    Try this code to a trigger
    change after exp.

    declare
    summ number(10);
    begin
    
    summ := nvl(:sal,0) + nvl(:comm,0)
    end;
    

    or send me your complete code.
    Thank you

  • How to display data from the emp table?

    Hi everyone, this is my first post in this portal. I want to display the details of the table emp... for this I use this SQL statement.

    Select * from emp where mgr = nvl(:mgr,mgr);

    When I give the entry as 7698 it shows the matching records... and also when I don't give any input then it shows all the records except the Archbishop with null values.

    (1) I want to display all the records when I do not give any input, including null values
    (2) I want to display all the records that a Bishop is null

    Is it possible to integrate in order to include all these in a single query.

    Hello

    937440 wrote:
    Hi everyone, this is my first post in this portal.

    Welcome to the forum!
    Don't forget to read the forum FAQ {message identifier: = 9360002}

    I want to display the details of the table emp... for this I use this SQL statement.

    Select * from emp where mgr = nvl(:mgr,mgr);

    When I give the entry as 7698 it shows the matching records... and also when I don't give any input then it shows all the records except the Archbishop with null values.

    (1) I want to display all the records when I do not give any input, including null values
    (2) I want to display all the records that a Bishop is null

    Is it possible to integrate in order to include all these in a single query.

    It's a little unsure what you're asking.
    The following query always includes the lines where mgr is NULL and when the binding variable: mgr is NULL, it displays all the lines:

    SELECT  *
    FROM     emp
    WHERE     LNNVL (mgr != :mgr)
    ;
    

    In other words, when: 7698 = mgr, it displays 6 rows and when: mgr is NULL, it displays 14 rows (assuming you are using the table provided by Oracle scott.emp).

    The following query includes lines where Bishop is ZERO only when the binding variable: mgr is NULL, in which case it shows all lines:

    SELECT     *
    FROM     emp
    WHERE     :mgr     = mgr
    OR       :mgr       IS NULL
    ;
    

    When: mgr = 7698, this will display 5 rows and when: mgr is NULL, it displays 14 rows.

    The following query includes lines where Bishop is ZERO only when the link variab; e: mgr is NULL, in which case it shows only those rows where mgr is NULL. In other words, it treats NULL as a value:

    SELECT     *
    FROM     emp
    WHERE     DECODE ( mgr
                , :mgr, 'OK'
                )     = 'OK'
    ;
    

    When: mgr = 7698, this will display 5 rows and when: mgr is NULL, it displays 1 row.

  • minimum hiredate from the emp table

    Hello

    There is a table EMP, hiredate column (date). I want to get the record with minimum hiredate and using this query.
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    
    SQL> with t as
      2  (select 'A' ename, 1 enum, '1-Oct-2008' hiredate from dual union all
      3  select 'B', 2, '1-Jan-2002' from dual union all
      4  select 'C', 3, '1-Mar-2008' from dual)
      5  select * from t
      6  where hiredate = (select min(hiredate) from t);
    
    E       ENUM HIREDATE
    - ---------- ----------
    B          2 1-Jan-2002
    
    SQL> 
    Is there another way to do it, without using subquery?

    Kind regards
    Ritesh

    Another option:

    SELECT  MIN(ENUM)       KEEP (DENSE_RANK FIRST ORDER BY HIREDATE)       AS ENUM
    ,       MIN(HIREDATE)   KEEP (DENSE_RANK FIRST ORDER BY HIREDATE)       AS HIREDATE
    FROM    t
    

    EDIT: See the post of John Spencer as it has a more in-depth explanation. This will only return the FIRST record oracle meets with minimal hiredate. It will not return more records if more than one employee has the same minimum hiredate.

    Published by: Centinul on October 23, 2009 09:38

  • get the cumulative sum of the salaries of the employees of emp table

    Hi gurus,

    Can any body tell me how to get the cumulative sum of the salaries of the employees in the emp table using analytical functions.

    Thanks in advance...

    Please read the document

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions163.htm#sthref2186

    Look for example at the bottom of the document.

  • EMP table query

    Hi friends,

    Please help me get the following output from the EMP table:
    DEPTNO     EMPNO     ENAME     SAL      HIREDATE
    ------------------------------------------------------------------------------------
    10             7521        Arun         1000    01-Jan-2005
                    7522       Bala           2000    01-Feb-2005 
                    7523        Chitra         3000    01-Mar-2005
    20             7524        Divya         4000    01-Apr-2005
                    7525        Elango        5000    01-May-2005 
    30             7526        Fathima      6000    01-Jun-2005
                    7527        Gopal         7000     01-Jul-2005
                    7528        Hari            8000    01-Aug-2005
    Published by: BluShadow on February 15, 2012 08:29
    addition of {noformat}
    {noformat} tags for improved (not perfect, due to OP's source) readability.  Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    According to my understanding, you could require something like this:

         DEPTNO      EMPNO ENAME             SAL HIREDATE
    ---------- ---------- ---------- ---------- ---------
            10       7934 MILLER           1300 23-JAN-82
                     7839 KING             5000 17-NOV-81
                     7782 CLARK            2450 09-JUN-81
            20       7876 ADAMS            6200 12-JAN-83
                     7369 SMITH             800 17-DEC-80
                     7788 SCOTT            3000 09-DEC-82
                     7566 JONES            2975 02-APR-81
                     7902 FORD             3000 03-DEC-81
            30       7844 TURNER           1500 08-SEP-81
                     7698 BLAKE            2850 01-MAY-81
                     7521 WARD             1250 22-FEB-81
                     7499 ALLEN            1600 20-FEB-81
                     7521 WARD             6500 22-FEB-81
            40       7900 JAMES            5900 03-DEC-81
                     7654 MARTIN           6500 28-SEP-81
    
    Then, the query you could use is:
    
    SELECT (CASE WHEN rn = 1 THEN deptno ELSE NULL END) Deptno, empno, ename, sal, hiredate
    FROM (
    SELECT deptno, ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY empno) rn ,empno, ename, sal, hiredate
    FROM emp); 
    

    Published by: claire on February 14, 2012 23:17

  • XML from the Oracle Table data

    Hi all

    I'm new to this network. I'm also new to oracle XML package. I want a help with the query below.

    CREATE TABLE EMP (ID NUMBER PRIMARY KEY, NAME VARCHAR2 (10), TELEPHONE NUMBER);

    INSERT INTO EMP (ID, NAME, PHONE) VALUES (11, 'Joy', 1234);
    INSERT INTO EMP (ID, NAME, PHONE) VALUES (22, 'Mike', 5678).
    INSERT INTO EMP (ID, NAME, PHONE) VALUES (33, "Jason", NULL);
    COMMIT;

    I want to export data from the EMP table in an XML file with the format below.

    Power required:

    <? XML version = "1.0" encoding = "UTF-8"? > < Joy STATICDATA > < EMP > < ID > 11 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? > < Mike STATICDATA > < EMP > < ID > 22 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? > < Jason STATICDATA > < EMP > < ID > 33 < /ID > < NAME > < / NAME > < / EMP > < / STATICDATA >

    I used some XML functions and you wrote the following query.

    Select XMLROOT (XMLELEMENT (staticdata, XMLELEMENT (EMP, XMLELEMENT(ID,ID), XMLELEMENT(NAME,NAME))), version "1.0" encoding = "UTF - 8') xml EMP;

    my query output:

    <? XML version = "1.0" encoding = "UTF-8"? >
    < STATICDATA >
    < EMP >
    < ID > 11 / < ID >
    Joy of < NAME > < / NAME >
    < / EMP >
    < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? >
    < STATICDATA >
    < EMP >
    < ID > 22 / < ID >
    < NAME > Mike < / NAME >
    < / EMP >
    < / STATICDATA >
    <? XML version = "1.0" encoding = "UTF-8"? >
    < STATICDATA >
    < EMP >
    < ID > 33 / < ID >
    Jason < NAME > < / NAME >
    < / EMP >
    < / STATICDATA >


    But I want the out as the power required above. all records in a single line. can someone help me achieve the desired output. also can I export all columns of the table with something like select * from the table in the XML file?

    Thank you
    Delobelle

    Don't know why you need it on a single line, but you could:

    Select XMLTYPE (REGEXP_REPLACE (XMLROOT (XMLELEMENT (staticdata, XMLELEMENT (EMP, XMLELEMENT(ID,ID), XMLELEMENT(NAME,NAME))), version "1.0" encoding = "UTF - 8'), CHR (10) |)) ' *<><'))>
    FROM EMP;

    SY.

  • steps to create the new table using existing metadata

    Hi all


    That's what I want to achieve,

    I want to create a procedure that will take an input parameter as a table name lets say 'EMP ',.
    This procedure checks if this table exists or not?
    If they don't exist
    It will create a new table with the name _dummy join the existing table name (ex: new table will be EMP_DUMMY).
    and new table should have the same structure of the table, indexes, and constraints on the EMP table.


    NB: It should not be created using select as create table EMP_DUMMY select * from EMP where = condition false;



    Can someone help me please how to achieve this?

    Please, don't post duplicate discussions.

    Check your thread previous stored procedure to create a new table with the existing table structure to further discussions

  • How to load the child table by using a simple slider...?

    How can I loa the child table by using a PL/SQL block cursor...

    for example, I have a table of the source called method

    EmpNo, empname, deptid deptname

    and I have 2 tables of taget... EMP and Dept.

    EMP
    ===
    EmpNo, empname, deptid

    Dept
    ====
    deptID, deptname


    Here, I want to load method for emp data and... Dept where dept does not contain data in double...

    For now... I used the cursor and in the same cursor, I'm loading data first dept table and then to the emp table.
    I use for dept, exceptional setting, which will manage a PK constraint violation error by doing nothing...

    in this way, there will be no duplicates... but it is not advisable because I 15,00,000 lines in the method table.

    Is there another way to do it?

    OK, I'd probably go with the method two insert, but as an alternative, here's a way to do it in a single insert:

    create table emp_info as
    select 1 empno, 'a' empname, 101 deptid, 'aaa' deptname from dual union all
    select 2, 'b' empname, 201 deptid, 'bbb' deptname from dual union all
    select 3, 'c' empname, 101 deptid, 'aaa' deptname from dual union all
    select 4, 'd' empname, 101 deptid, 'aaa' deptname from dual union all
    select 5, 'e' empname, 301 deptid, 'ccc' deptname from dual;
    
    create table emp (empno number primary key, empname varchar2(3), deptid number);
    
    create table dept (deptid number primary key, deptname varchar2(3));
    
    insert all
      WHEN rn = 1 THEN
           into dept (deptid, deptname)
           values (deptid, deptname)
      WHEN rn > 0 THEN
           into emp (empno, empname, deptid)
           values (empno, empname, deptid)
    select empno, empname, deptid, deptname, rn
    from   (select empno,
                   empname,
                   deptid,
                   deptname,
                   row_number() over (partition by deptid order by empno) rn
            from   emp_info);
    
      8 rows inserted
    
    commit;
    
    select * from emp;
    
         EMPNO EMP     DEPTID
    ---------- --- ----------
             1 a          101
             3 c          101
             4 d          101
             2 b          201
             5 e          301
    
    select * from dept;
    
        DEPTID DEP
    ---------- ---
           101 aaa
           201 bbb
           301 ccc
    

    You must test these two methods to see which is more efficient.

  • separate account using the lookup table

    How can I get a separate count of column values by using another table?

    Let's say I want to get a separate account of all 'company_name' files in the 'emp' table that corespond (soccer match) with table of 'research', 'State' category.

    What I want is to find charges for all businesses that have a value of 'california' in the 'Status' column of the 'search' Table. I want the output to look like:

    Sears 17
    Pennys 22
    Marshalls 6
    Macys 9

    I want the result to show me the company names dynamically as I don't know what they are, just that they are part of the group 'State' in the lookup Table object. Does make sense?

    M

    If you want a counter for each value of rfs_category, but instead of rfs_category you want to display, it's translated value lookup_value_desc.

    This should do it for you:

    select lookup_value_desc, the_count
      from lookup
      join (select rfs_category, count(*) the_count
              from RFS group by rfs_category)
        on rfs_category = lookup_type;
    
  • Remove the same instance of two separate tables online

    Hi all

    I have two tables that each repeatable lines. Both tables must display almost the same information in each case of the line (I managed to code to link the values in specific cases of the lines). However, I added a button in the repeatable row, which allows the user to remove from the current instance of the line, so will they look back and realize that they do not need a line, they can take directly from the table. However, I can't seem to get the deletion affects the same instance of row of the second table. Is it possible to do this? I'm not terribly familiar with the instance Manager.

    Any help would be greatly appreciated. I just can't understand how to identify a specific instance of the repeatable row in table 2.

    Hello

    Removing instances in the event of an object that is inside the instance, you must ensure that you remove this particular instance at the end of the event.

    For example:

    If you delete the instance that the button is on the inside before finishing the entire event, the program will not recognize what event is to finish because you have removed it from the object that is triggered...

    You try here at the end of the code that no longer exists...

    I suggest that you still need to delete the instance (this) object at the end of any event to make sure to complete all your actions before deleting the object.

    I hope this helps!

Maybe you are looking for