SQL for the calculation of the salary

Version: 11.2

Permanent employees get monthly salary, contract workers get only commission.
Some permanent employees such as PETER and JOHANN get salary and Commission


I want to find the total amount paid to permanent and non-permanent.

The computation of the total, for employees who receive the salary and Commission as PETER and JOHANN, I want to ignore the Commission and considers that pay them for the calculation of total compensation.
ie. When computing the total amount paid to all these employees

    I want to ignore commision of 400 received by PETER 
    and
    I want to ignore commision of 1000 received by  JOHANN
That is to say. The Total amount paid will be: 18 500

create table pay_master (emp_type varchar2(50) , empname varchar2(50), salary number , comm number );


insert into pay_master values ( 'PERM', 'KAREN' , 2000, 0 );
insert into pay_master values ( 'PERM', 'HANS'  , 3000, 0 );
insert into pay_master values ( 'CONTRACT', 'KEITH'  , 0, 1000 );

insert into pay_master values ( 'CONTRACT', 'ABDUL'  , 0, 2000 );
insert into pay_master values ( 'PERM', 'KRISHNA'  , 1000, 0 );
insert into pay_master values ( 'CONTRACT', 'CHENG'  , 0, 1500 );
insert into pay_master values ( 'PERM', 'PETER'  , 5000, 400 );
insert into pay_master values ( 'PERM', 'JOHANN'  , 3000, 1000 );


col EMP_TYPE format a10
col EMPNAME format a10

SQL> select * From pay_master order by empname;

EMP_TYPE   EMPNAME        SALARY       COMM
---------- ---------- ---------- ----------
CONTRACT   ABDUL               0       2000
CONTRACT   CHENG               0       1500
PERM       HANS             3000          0
PERM       JOHANN           3000       1000           ---------------> Ignore this commision when calculating the total pay
PERM       KAREN            2000          0
CONTRACT   KEITH               0       1000
PERM       KRISHNA          1000          0
PERM       PETER            5000        400           ---------------> Ignore this commision when calculating the total pay

8 rows selected.

SQL> select EMPNAME , salary+comm from pay_master order by empname;

EMPNAME    SALARY+COMM
---------- -----------
ABDUL             2000
CHENG             1500
HANS              3000
JOHANN            4000
KAREN             2000
KEITH             1000
KRISHNA           1000
PETER             5400

8 rows selected.

SQL> select sum(salary+comm) from pay_master;

SUM(SALARY+COMM)
----------------
           19900


Expected output from the SQL with the above mentioned logic is 18500
How can I do this in SQL? I think that I can't use CASE here statement because the CASE statement works only in a single column. Right?

Hello

J.Kiechle wrote:
... I think that I can't use CASE here statement because the CASE statement works only in a single column. Right?

A CASE results in a single value expression. It may depend on any number of columns (that is, of reference): 0, 1, 2, 3 or more.

For example, the following is based on 2 columns, x and y:

CASE
    WHEN  x > y
    THEN  x
    ELSE  y
END

which is just another way to get the same results that

GREATEST (x, y)

You can use either of the foregoing, for your problem (assuming that the salary and the Commission are always 0 or more).

Published by: Frank Kulash, Sep 21, 2012 05:40

Tags: Database

Similar Questions

  • Assignment is not eligible for the salary item.

    We trying to fill in the data in the table per_pay_proposals (Salary) in HRMS through the hr_maintain_proposal_api.

    But the Exceptions of API that "assignment is not eligible for the salary item. We have specified the base of the salary, payroll and the required functions.

    The assignment is a transfer of assets and the wage proposal is approved a.

    Can anyone tell us about the cause of this problem and a possible solution, because we are not able to find the cause.


    Thank you
    Bond

    Link to the element should be created for the item that is linked to the basis of the salary.

  • SQL for the webADI fields

    Hello

    I need a SQL to retrieve the fields and another piece of land to show if it is a line or a header for the WebADI project.

    Can someone provide me with this SQL if you have already worked on it?

    Thank you and best regards,

    Yuvraj

    SELECT DISTINCT fap.application_short_name 'Application Short Name',

    bib.User_Name "integrating user name."

    BLB.user_name "name of the page layout."

    bicb.interface_col_name "name of the field."

    blbb.user_name 'investment. "

    BLC. Default_value 'Default Value ',.

    UPPER CASE (NVL (blc.default_type, 'NONE'))

    WHEN 'NONE', THEN 'none'

    WHEN "FORMULA", THEN "Formula".

    WHEN 'CONSTANT' THEN 'constant '.

    WHEN 'PARAMETER' THEN 'setting '.

    WHEN 'SQL' THEN 'SQL '.

    WHEN 'ENVIRONMENT' THEN 'environment '.

    ANOTHER "UNKNOWN".

    END

    'The Type by default'

    OF apps.fnd_application fap.

    Apps.bne_integrators_vl bib,

    Apps.bne_layouts_vl blb,

    Apps.bne_layout_blocks_tl Boop,

    Apps.bne_layout_cols blc,

    Apps.bne_interface_cols_b bicb,

    Apps.bne_components_b bcb,

    Apps.bne_param_lists_b bplb,

    Apps.bne_param_list_items bpli

    WHERE 1 = 1

    AND fap.application_id = bib.application_id

    -bne_integrators_b | bne_layouts_b

    AND bib.integrator_code = blb.integrator_code

    AND bib.application_id = blb.integrator_app_id

    -bne_layouts_b | bne_layout_blocks_b

    AND blb.layout_code = blbb.layout_code

    AND blb.application_id = blbb.application_id

    -bne_layout_blocks_b | bne_layout_cols

    AND blbb.layout_code = blc.layout_code

    AND blbb.application_id = blc.application_id

    AND blbb.block_id = blc.block_id

    -bne_layout_cols | bne_interface_cols_b

    AND blc.application_id = bicb.application_id

    AND blc.interface_code = bicb.interface_code

    AND blc.sequence_num = bicb.sequence_num

    -bne_interface_cols_b | bne_components_b

    AND bicb.application_id = bcb.application_id

    AND bicb.val_component_code = bcb.component_code

    -bne_components_b | bne_param_lists_b

    AND bcb.param_list_code = bplb.param_list_code

    -bne_param_lists_b | bne_param_list_items

    AND bplb.param_list_code = bpli.param_list_code

    AND blbb.language = 'en '.

    AND fap.application_short_name = 'PA '.

    ORDER BY 1, 2;

  • How the group using SQL for the desired output.

    Hi all

    I am currently using oracle 10.2.0.4.0

    Create a table script:
    CREATE TABLE FORTEST
    ( gpno VARCHAR2(10 BYTE),
      classnumber  VARCHAR2(10 byte),
      age_min NUMBER,
      age_max NUMBER,
      amount NUMBER)
    INSERT statement:
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 01,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 01,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 01,36,40,3) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 02,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 02,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 02,36,40,5) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 03,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 03,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G123' , 03,36,40,3) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G124' , 01,0,29,1) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G124' , 01,30,35,2) 
    insert into fortest  (GPNO,classnumber,age_min,age_max,amount) values
    ('G124' , 01,36,40,3) 
    power required:
    gpno    classnumber    age_min    age_max    amount
    G123    1,3                0        29        1
    G123    1,3                30       35        2
    G123    1,3                36       40        3
    G123    2                  0        29        1
    G123    2                  30       35        2
    G123    2                  36       40        5
    G124    1                  0        29        1
    G124    1                  30       35        2
    G124    1                  36       40        3
    as for gpno g123, classnumber 1 and 3, the rates are the same in all the age_min and age_max they need to be grouped.
    even if gpno 123 classnumber 2 has the same rates as the classesnumber 1 and 3 for the age groups 0 to 29 and 30 to 35,
    rates are different for ages 36 to 40. so it should not be placed together. How can I do this in SQL

    any help is appreciated.

    Thanks in advance.

    Hello

    Thorny problem!

    Unfortunately, LISTAGG was created to the Oracle 11.2. About half of the complexity here is the aggregation of chain, i.e. forming the list of the classnumbers, as '1.3', using only functions available in Oracle 10.2.

    Here's a solution:

    WITH     got_gpno_classnumber_cnt   AS
    (
         SELECT     gpno, classnumber, age_min, age_max, amount
         ,     COUNT (*) OVER ( PARTITION BY  gpno
                                      ,            classnumber
                          )   AS gpno_classnumber_cnt
         FROM    fortest
    --     WHERE     ...     -- If you need any filtering, this is where it goes
    )
    ,     pairs          AS
    (
         SELECT    a.gpno
         ,       a.classnumber
         ,       MIN (b.classnumber)
                    OVER ( PARTITION BY  a.gpno
                              ,                    a.classnumber
                      )     AS super_classnumber
         FROM       got_gpno_classnumber_cnt  a
         JOIN       got_gpno_classnumber_cnt  b  ON   a.gpno     = b.gpno
                                      AND  a.age_min     = b.age_min
                                    AND  a.age_max     = b.age_max
                                    AND  a.amount     = b.amount
                                    AND  a.gpno_classnumber_cnt
                                            = b.gpno_classnumber_cnt
         GROUP BY  a.gpno
         ,            a.classnumber
         ,       b.classnumber
         HAVING       COUNT (*)     = MIN (a.gpno_classnumber_cnt)
    )
    ,     got_rnk          AS
    (
         SELECT DISTINCT
                 gpno, classnumber, super_classnumber
         ,     DENSE_RANK () OVER ( PARTITION BY  gpno
                                   ,                    super_classnumber
                                   ORDER BY          classnumber
                           )         AS rnk
         FROM    pairs
    )
    ,     got_classnumbers     AS
    (
         SELECT     gpno, classnumber, super_classnumber
         ,      SUBSTR ( SYS_CONNECT_BY_PATH (classnumber, ',')
                       , 2
                     )     AS classnumbers
         FROM     got_rnk
         WHERE     CONNECT_BY_ISLEAF = 1
         START WITH     rnk             = 1
         CONNECT BY     rnk             = PRIOR rnk + 1
              AND     gpno             = PRIOR gpno
              AND     super_classnumber  = PRIOR super_classnumber
    )
    SELECT DISTINCT
           g.gpno
    ,       c.classnumbers
    ,       g.age_min
    ,       g.age_max
    ,       g.amount
    FROM       got_gpno_classnumber_cnt  g
    JOIN       got_classnumbers         c  ON   c.gpno        = g.gpno
                                 AND  c.classnumber  = g.classnumber
    ORDER BY  g.gpno
    ,            c.classnumbers
    ;
    

    Out (just as you requested):

    GPNO       CLASSNUMBERS       AGE_MIN    AGE_MAX     AMOUNT
    ---------- --------------- ---------- ---------- ----------
    G123       1,3                      0         29          1
    G123       1,3                     30         35          2
    G123       1,3                     36         40          3
    G123       2                        0         29          1
    G123       2                       30         35          2
    G123       2                       36         40          5
    G124       1                        0         29          1
    G124       1                       30         35          2
    G124       1                       36         40          3
    
  • Help: SQL for the massive update (service lead)

    Hello

    I use Oracle11.2. I want to update the column of hist_dttm of tb_hist with the tb_base crt_dttm column value in the following line, which is ordered by crt_dttm. Here are the details:

    creat table tb_base (tid varchar2 (32), crt_dttm timestamp (6));
    creat table tb_hist (tid varchar2 (32), crt_dttm timestamp (6), upd_dttm timestamp (6));

    insert into tb_base values ("AAA", to_timestamp (12 January 05 14:00:00.123456', ' dd-mm-rr hh24:mi:ss.ff'));))
    insert into tb_base values ("AAA", to_timestamp (May 12 05 14:00:00.123456', ' dd-mm-rr hh24:mi:ss.ff'));))
    insert into tb_base values ("AAA", to_timestamp (16 December 05 14:00:00.123456', ' dd-mm-rr hh24:mi:ss.ff'));))

    insert into tb_base values ("AAA", to_timestamp (12 January 05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff'), null);
    insert into tb_base values ("AAA", to_timestamp (May 12 05 14:00:00.123456', 'dd-mm-rr hh24:mi:ss.ff'), null);

    I use the following SQL to update the column upd_dttm of the tb_hist, I'm waiting for the upd_dttm needs to be updated to "12/05/05 14:00:00.123456 ' and 14:00:00.123456 16 December 05. However they is NULL. Any suggestion?



    Update tb_hist hist
    Set (upd_dttm) = (select lead (base. CRT_DTTM over (Partition by order of base.tid of base.crt_dttm)
    tb_base base
    where base.tid = hist.tid
    and base.crt_dttm = hist.crt_dttm)
    ;
     update tb_hist
      set crt_dttm= (select min (crt_dttm)
           from tb_base
         where tb_base.crt_dttm > tb_hist.crt_dttm)
    

    Published by: DPT Opitz Consulting com on 09.10.2012 19:24

    Published by: DPT Opitz Consulting com on 09.10.2012 19:25

  • SQL for the synchronous question of AIR vs. asynchronous

    Gidday guys

    I've implemented a SQLite database that will be processing up to 150 000 lines at the same time.  I use parametized queries, wrapped in a transaction, it should be fast enough. I use asynchronous methods.

    I put the motions and managed to get a static test of query in the database using the parameters.  Wahooo!

    However, now I did it dynamic to receive bulk data, I get the error:

    "Operation could not be performed SQLStatement.executing is true.

    I wonder if anyone can

    (a) suggest that synchronous may be a better option

    or

    (b) guide me as to what order the functions and event listeners would fix my follows established...

    THE PROCESS:

    -J' have a lot of file names in an array, that need to be tweaked before thrown into the database

    -J' set up the sql (leg work done earlier) connection, the query statement, and then start a transaction:

    insertStmt.sqlConnection = conn;

    insertStmt.text = "INSERT or IGNORE INTO tester3 VALUES (@col1, @col2);

    Conn.Begin ();

    -table is thrown into a function that starts an enterFrame iteration (if the display does not freeze), where I change the names of files, and put each file name twisted and other (also directed for the database) data in an object and deliver it to the function that prepares the data in the settings...

    prepareParameters ({col1:col1var, col2:col2var});})

    prepareParameters(row:Object):void

    {

    [insertStmt.parameters["@col1"] = row.col1;

    [insertStmt.parameters["@col2"] = row.col2;

    insertStmt.execute ();
    }

    -at the end of the loop table, call the transaction end function

    I think the problem is that the loop sends the next object to prepareParameters() until the database has finished executing the last insert statement.

    I tried to configure a listener for results to try to make Flash do not return to the loop until the listener received something, but I get the same error.

    My first thought was "Hey, shouldn't Flash wait until after insertStmt.execute ();" has finished before returning to the loop that calls its function? But maybe this happens in synchronous treatment?

    Thanks for your thoughts guys.

    Before I head to a few races a couple quick notes.

    If you just want a quick number of items affected in the database across all executions altogether (although SQLConnection is maintained), you can use this property:

    http://help.Adobe.com/en_US/FlashPlatform/reference/ActionScript/3/Flash/data/SQLConnectio #totalChanges n.html

    To be more practical, SQLResult can be used on a SQLStatement instance after it is over (after the RESULT event). If you do not want to use it (as in the example above) in the manager function, _runQuery. The SQLEvent sent to method (apart from the first _runQuery (null)) will contain a reference to the SQLStatement instance that has been run. You can see me access it explicitly to remove the handler from the success of it as follows:

    If (e)

    {

    SQLStatement (e.taget) .removeEventListener (SQLEvent.RESULT, _runQuery);

    }

    Which is simply check to see if I have a valid (non-null) event sent to the method and if yes I use it to remove the handler. I could use a weak reference in the event handler, but on devices, I would be extremely explicit in removing all memory that I absolutely is useless as soon as possible.

    That said, each SQLStatement has getResult() method:

    http://help.Adobe.com/en_US/FlashPlatform/reference/ActionScript/3/Flash/data/SQLStatement .html #getResult ()

    That method contains the method, you asked:

    http://help.Adobe.com/en_US/FlashPlatform/reference/ActionScript/3/Flash/data/SQLResult.ht ml #rowsAffected

    It's just the number of rows affected by your last statement (UPDATE, INSERT, DELETE,...). If you want to follow him through multiple SQLinstructions you could do a new class var to collect the results, if you do not use SQLConnection totalChanges I linked above:

    If (e)

    {

    get an official reference

    var insertStmt:SQLStatement = (e.target) SQLStatement;

    results of this execution

    var result: SQLResult = insertStmt.getResult ();

    draw some properties of an "INSERT" as you do

    trace ("Insert ID:" + result.lastInsertRowID + ", affected rows:" + result.rowsAffected);

    If you perform the UPDATE/DELETION there are .data with an array property

    all the results that you can browse, exhausted for example length of results

    (just treat it as type Array and iterate over it if you wish)

    trace ("result Total SQL statements:" + result.data.length);

    remove the listener

    insertStmt.removeEventListener (SQLEvent.RESULT, _runQuery);

    }

    Keep in mind, it's TO-achieve, not a total. This allows you to review the results of each "single" execute() that you are running. You can search for questions or to check the validity of the data, etc., on each function execute(). If you don't really care that then just check the _sqlConn.totalChanges for one number for everything that moved the database runs.

    Don't forget to close the connection of _sqlConn after all function execute() statements look the next time you run queries, it resets the totalChanges. Also on something like a DELETION * a SQLResult returned 0 results. It is mentioned in the documentation, read paragraph 3 on the addition of a 'WHERE 1 = 1' just to get results to fill:

    http://help.Adobe.com/en_US/FlashPlatform/reference/ActionScript/3/Flash/data/SQLResult.ht ml #rowsAffected

  • Help with Sql for the annual report by month

    Hi, I got the task of creating an annual report each month that shows the benefits of the enterprise by month and total in the last column to show what branch was the hightest income.
    Branch | January | February | March | April | Can | June... | Total |
    ABC | $0.00 | $0.00 | $0.00 | $0.00 | $0.00 | $0.00 | Total of the Amt |
    DEF | $18.01. $3.88. $18.01. $4.12 | $18.01. $3.97 | Total of the Amt |

    Can someone please help me give an idea of how to write sql for this report... ? I build subqueries for everymonth giving dates for Jan/Feb/March... but I think that this is not the right way to do it...
    -----------------------------------------------------------------------------------------------------------------------
    SELECT
    Sum (a.Commission) December,
    Sum (b.Commission) November
    Of
    (
    Select
    c.account_ID,
    c.Officer,
    c.account_product_class_id,
    Sum (c.dp_monthly_premium) Commission
    Of
    c contract
    Where
    c.account_ID = 109 and
    c.Status = 'APPROVED' and
    c.protection_effective between December 1, 2009 "and on December 31, 2009"
    Group by
    c.account_ID,
    c.Officer,
    c.account_product_class_id
    ),
    (
    Select
    c.account_ID,
    c.Officer,
    c.account_product_class_id,
    Sum (c.dp_monthly_premium) Commission
    Of
    c contract
    Where
    c.account_ID = 109 and
    c.Status = 'APPROVED' and
    c.protection_effective between November 1, 2009 "-November 30, 2009"
    Group by
    c.account_ID,
    c.Officer,
    c.account_product_class_id
    ) b
    -----------------------------------------------------------------------------------------------------------
    I always hight hope this forum. So please help. Thanks in advance.

    Published by: Aditi_Seth on January 26, 2010 14:29

    You may reach the columns using decode:

    Select sum (decode (to_char (c.protection_effective, 'MM'), 1, c.dp_monthly_premium, 0)) January
    , sum (decode (to_char (c.protection_effective, 'MM'), 2, c.dp_monthly_premium, 0)) February

    etc.

    At least, this will improve efficiency, because you need only make one pass.

    no guarantee that the media are quite right - I did not execute the query, but I think that you should get the idea!

  • variable presentation in the SQL for the scale marker

    ! http://img101.imageshack.us/img101/3476/sqlscalemarket.PNG!

    Hi, experts,

    I want to know if variable presentation is supported in the "sql query" "scale marker.

    I want to move the selected value from the prompt for the sql query!

    Thank you!

    I want to know if variable presentation is supported in the "sql query" "scale marker.

    Scale marker made reference here to the axis scale to increase the width and height or the zoom layout data is dedicated to the see, it has nothing to do with the variable presentation as such. If you can not pass any value for the variable.

  • See APEX SQL for the treatment of automatic line

    Hello

    I get an error like this when you try to update with the automatic processing of line:
    ORA-20505: DML error: p_rowid = 89, p_alt_rowid = network_user_mou_id, p_rowid2 =, p_alt_rowid2 is. ORA-06550: line 1, column 17: PL/SQL: ORA-00936: lack of expression ORA-06550: line 1, column 9: PL/SQL: statement ignored
    Is there a way to see the generated SQL code so that I could determine what the problem is?

    Thank you
    Rick

    Rick:

    A way to see the SQL code executed would be to allow "sql_trace" before the process of automatic processing of line. Create a process that fires off the coast before before that the process of automatic line with the following line of code

    alter session set sql_trace=true;
    

    and a process that fires off the coast after the process of automatic line to disable tracing

    alter session set sql_trace=false;
    

    Trace files will occur in the "bdump" or "udump" Directory depending on whether you are using the EPG or OSH.

    As for the error itself, I wonder if it is due to a column that you recently added to the form.

    CITY

  • Casting table PL/SQL for the type of existing table and back ref cursor

    Hello



    I have the problem of casting a pl/sql table for the type of an existing table and turning the ref cursor to the application. Casting a ref cursor back and number of pl/sql table works well.



    Declarant

    < strong > TYPE type_table_name IS TABLE OF THE package_name.table_name%ROWTYPE; < facilities >

    within the stored procedure, fill in a table of this type temp_table_name and returning the ref cursor help

    < strong > results OPEN to SELECT * FROM TABLE (CAST (temp_table_name AS type_table_name)); < facilities >

    generates an error. type_table_name is unknown in this distribution. According to me, this happens because of the declaration of the type locally.



    Statement type_table_name inside the package specification does not work neither. Incredible, cast to the said dbms_sql.number_table to specify ref cursor back and dbms_sql package works very well!



    < strong > CREATE TYPE type_table_name IS TABLE OF THE package_name.table_name%ROWTYPE; < facilities > deals without any error but creates an invalid type complain a reference to package_name.table_name



    I don't want to declare every column in the table in type_table_name, because any change the table_name table would result in an inconsistent type_table_name.



    Thanks in advance!

    Edited by: user6014545 the 20.10.2008 01:04

    In any case you are right that there is a problem around anchorage (or maintaining) types of objects persistent to match the table structures, they may represent.

    In the case you describe, you might be better off just open the refcursor immediately the using one of the techniques described in the http://www.williamrobertson.net/documents/comma-separated.html to manage the delimited list.

    In the more general case where the line of treatment is necessary, you may make the pipeline functions.

    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    
    SQL> CREATE TABLE table_name
      2  AS
      3     SELECT ename column_name
      4     FROM   emps;
    
    Table created.
    
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3     TYPE type_name IS TABLE OF table_name%ROWTYPE;
      4
      5     FUNCTION function_name_pipelined (
      6        parameter_name IN VARCHAR2)
      7        RETURN type_name PIPELINED;
      8
      9     FUNCTION function_name_refcursor (
     10        parameter_name IN VARCHAR2)
     11        RETURN sys_refcursor;
     12  END package_name;
     13  /
    
    Package created.
    
    SQL> CREATE OR REPLACE PACKAGE BODY package_name
      2  AS
      3     FUNCTION function_name_pipelined (
      4        parameter_name IN VARCHAR2)
      5        RETURN type_name PIPELINED
      6     IS
      7     BEGIN
      8        FOR record_name IN (
      9           SELECT table_alias.*
     10           FROM   table_name table_alias
     11           WHERE  table_alias.column_name LIKE parameter_name) LOOP
     12
     13           PIPE ROW (record_name);
     14        END LOOP;
     15
     16        RETURN;
     17     END function_name_pipelined;
     18
     19     FUNCTION function_name_refcursor (
     20        parameter_name IN VARCHAR2)
     21        RETURN sys_refcursor
     22     IS
     23        variable_name sys_refcursor;
     24     BEGIN
     25        OPEN variable_name FOR
     26           SELECT table_alias.*
     27           FROM   TABLE (package_name.function_name_pipelined (
     28                     parameter_name)) table_alias;
     29
     30        RETURN variable_name;
     31     END function_name_refcursor;
     32  END package_name;
     33  /
    
    Package body created.
    
    SQL> VARIABLE variable_name REFCURSOR;
    SQL> SET AUTOPRINT ON;
    SQL> BEGIN
      2     :variable_name := package_name.function_name_refcursor ('%A%');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    COLUMN_NAME
    -----------
    ALLEN
    WARD
    MARTIN
    BLAKE
    CLARK
    ADAMS
    JAMES
    
    7 rows selected.
    
    SQL> ALTER TABLE table_name ADD (new_column_name VARCHAR2 (1) DEFAULT 'X');
    
    Table altered.
    
    SQL> BEGIN
      2     :variable_name := package_name.function_name_refcursor ('%A%');
      3  END;
      4  /
    
    PL/SQL procedure successfully completed.
    
    COLUMN_NAME NEW_COLUMN_NAME
    ----------- ---------------
    ALLEN       X
    WARD        X
    MARTIN      X
    BLAKE       X
    CLARK       X
    ADAMS       X
    JAMES       X
    
    7 rows selected.
    
    SQL>
    
  • SQL for the interface of FILES with column headers

    Hi all

    I designed an interface to extract data from Oracle to flat (.txt file).

    (1) I get the column headers in the output of file(. txt file) but I don't want to see any header column

    (2) for the creation of the data source in data model if I give any type of Date column I get the null value in the output file, but if I give the column type as string date filed I am able to see the data in the output file.



    Thank you
    Patel.

    Hi Pierrot

    (1) I get the column headers in the output of file(. txt file) but I don't want to see any header column
    You can set GENERATE_HEADER = flase and flow properties.

    -approach step by step on how to load some data from an oracle to flat file table
    http://www.Oracle.com/WebFolder/technetwork/tutorials/OBE/FMW/ODI/odi_11g/odi_project_table-to-flatfile/odi_project_table-to-flatfile.htm
    http://odiexperts.com/Oracle-to-flat-file/

    (2) for the creation of the data source in data model if I give any type of Date column I get the null value in the output file, but if I give the column type as string date filed I am able to see the data in the output file.
    I don't think you can use a data type Date during loading in the flat file. You can go with string or number/integer (if the date has no special characters. Here, you can use a conversion function to convert the data type Date existing according to your needs, but make sure that you select "source or on the staging")

    Concerning
    KK

  • SQL for the datetime type

    Hello

    help me in this.

    I have a sql to the datetime of the user input value:

    Select * from master_table
    where time < = 9 April 09 ' + 1

    It seems that I can not add '+ 1' here...

    April 9 09 is the web-based user input...

    My question: How can I add a '+ 1' every time that the user key in the user input text box?

    Thank you.

    You can change in your date format or add

    Select * from deadline-1=to_date('09-apr-09','DD-MON-YY master_table');

  • SQL for the sum of a column while avoiding the repetition of values

    Dear all
    I have this table called Loans_installments that contains the client's loan payments.

    sample data:
    the client_id loan_no inst_mat_date inst_seq original_inst_amt int_amt currency management
    110 2 222 100 1/1/2013 1 0 50
    110 2 222 100 1/2/2013 2 0 52
    110 2 222 100 1/3/2013 3 0 54
    110 2 222 100 1/4/2013 4 500 90
    110 2 222 100 1/5/2013 5 0 50
    110 2 222 100 1/6/2013 6 0 51
    110 2 222 100 7/1/2013 7 0 50
    110 2 222 100 1/8/2013 8 600 105
    110 2 222 100 1/9/2013 9 0 50
    110 2 222 10 100 1/10 / 2013 0 54
    110 2 222 100 1/11 / 2013 11 0 50
    110 2 222 100 1/12 / 2013 12 700 120



    now what I want to do the sum of int_amt field based on original_inst_amt value (0 or a value) and put the result on the int_amt who has an orig_inst_amt value <>0.

    the result should be like this:


    the client_id loan_no inst_mat_date inst_seq original_inst_amt int_amt currency management
    110 2 222 100 1/1/2013 1 0 0
    110 2 222 100 1/2/2013 2 0 0
    110 2 222 100 1/3/2013 3 0 0
    110 2 222 100 1/4/2013 4 500 246
    110 2 222 100 1/5/2013 5 0 0
    110 2 222 100 1/6/2013 6 0 0
    110 2 222 100 7/1/2013 7 0 0
    110 2 222 100 1/8/2013 8 600 256
    110 2 222 100 1/9/2013 9 0 0
    110 2 222 100 1/10 / 2013 10 0 0
    110 2 222 100 1/11 / 2013-11 0 0
    110 2 222 100 1/12 / 2013 12 700 274


    any help please.

    With the help of the clause type

    SQL> with t
      2  as
      3  (
      4  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/1/2013','mm/dd/yyyy') inst_mat_date, 1  inst_seq, 0   original_inst_amt, 50 int_amt from dual
      5  union all
      6  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/2/2013','mm/dd/yyyy') inst_mat_date, 2  inst_seq, 0   original_inst_amt, 52 int_amt from dual
      7  union all
      8  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/3/2013','mm/dd/yyyy') inst_mat_date, 3  inst_seq, 0   original_inst_amt, 54 int_amt from dual
      9  union all
     10  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/4/2013','mm/dd/yyyy') inst_mat_date, 4  inst_seq, 500 original_inst_amt, 90 int_amt from dual
     11  union all
     12  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/5/2013','mm/dd/yyyy') inst_mat_date, 5  inst_seq, 0   original_inst_amt, 50 int_amt from dual
     13  union all
     14  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/6/2013','mm/dd/yyyy') inst_mat_date, 6  inst_seq, 0   original_inst_amt, 51 int_amt from dual
     15  union all
     16  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/7/2013','mm/dd/yyyy') inst_mat_date, 7  inst_seq, 0   original_inst_amt, 50 int_amt from dual
     17  union all
     18  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/8/2013','mm/dd/yyyy') inst_mat_date, 8  inst_seq, 600 original_inst_amt, 105 int_amt from dual
     19  union all
     20  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/9/2013','mm/dd/yyyy') inst_mat_date, 9  inst_seq, 0   original_inst_amt, 50 int_amt from dual
     21  union all
     22  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/10/201','mm/dd/yyyy') inst_mat_date, 10 inst_seq, 0   original_inst_amt, 54 int_amt from dual
     23  union all
     24  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/11/201','mm/dd/yyyy') inst_mat_date, 11 inst_seq, 0   original_inst_amt, 50 int_amt from dual
     25  union all
     26  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/12/201','mm/dd/yyyy') inst_mat_date, 12 inst_seq, 700 original_inst_amt, 120 int_amt from dual
     27  )
     28  select branch
     29       , currency
     30       , client_id
     31       , loan_no
     32       , inst_mat_date
     33       , inst_seq
     34       , original_inst_amt
     35       , decode(original_inst_amt, 0, 0, sum(int_amt) over(partition by cnt)) int_amt
     36    from (
     37            select branch
     38                 , currency
     39                 , client_id
     40                 , loan_no
     41                 , inst_mat_date
     42                 , inst_seq
     43                 , original_inst_amt
     44                 , int_amt
     45                 , cnt
     46              from t
     47             model
     48             dimension by
     49             (
     50                inst_seq
     51             )
     52             measures
     53             (
     54                branch, currency, client_id, loan_no, inst_mat_date, original_inst_amt, int_amt, 1 cnt
     55             )
     56             rules
     57             (
     58                 cnt[any] = case
     59                                   when original_inst_amt[cv()-1] > 0 then
     60                                      cnt[cv()-1] + 1
     61                                   else
     62                                      nvl(cnt[cv()-1], cnt[cv()])
     63                               end
     64             )
     65         )
     66  /
    
        BRANCH   CURRENCY  CLIENT_ID    LOAN_NO INST_MAT_   INST_SEQ ORIGINAL_INST_AMT    INT_AMT
    ---------- ---------- ---------- ---------- --------- ---------- ----------------- ----------
           110          2        222        100 01-JAN-13          1                 0          0
           110          2        222        100 02-JAN-13          2                 0          0
           110          2        222        100 03-JAN-13          3                 0          0
           110          2        222        100 04-JAN-13          4               500        246
           110          2        222        100 05-JAN-13          5                 0          0
           110          2        222        100 06-JAN-13          6                 0          0
           110          2        222        100 08-JAN-13          8               600        256
           110          2        222        100 07-JAN-13          7                 0          0
           110          2        222        100 09-JAN-13          9                 0          0
           110          2        222        100 11-JAN-01         11                 0          0
           110          2        222        100 10-JAN-01         10                 0          0
           110          2        222        100 12-JAN-01         12               700        274
    
    12 rows selected.
    
    SQL>
    
  • Need help with SQL for the following logic.

    I have a table with 3 columns and the following data:
    DATE NAME S_NO
    1 ABC1 JANUARY 1, 2001
    1 ABC2 JANUARY 10, 2001
    1 ABC3
    1 ABC4
    ABC1 2 1 DECEMBER 2010
    ABC2 2
    2 ABC3 DECEMBER 10, 2010
    2 ABC4 DECEMBER 5, 2010
    3 XYZ1 FEBRUARY 1, 2001
    3 XYZ2 FEBRUARY 2, 2001

    I need to retrieve the value of NAME for each S_NO corresponding to the maximum DATE. In the above example, it will be:
    1 ABC2
    2 ABC3
    3 XYZ2
    /* Formatted on 9/10/2012 2:50:13 PM (QP5 v5.139.911.3011) */
    WITH t AS (SELECT 1 S_NO, 'ABC1' NAME, '1-JAN-2001' dt FROM DUAL
               UNION ALL
               SELECT 1, 'ABC2', ' 10-JAN-2001' FROM DUAL
               UNION ALL
               SELECT 1, 'ABC3', NULL FROM DUAL
               UNION ALL
               SELECT 1, 'ABC4', NULL FROM DUAL
               UNION ALL
               SELECT 2, 'ABC1', '1-DEC-2010' FROM DUAL
               UNION ALL
               SELECT 2, 'ABC2', NULL FROM DUAL
               UNION ALL
               SELECT 2, 'ABC3', '10-DEC-2010' FROM DUAL
               UNION ALL
               SELECT 2, 'ABC4', '5-DEC-2010' FROM DUAL
               UNION ALL
               SELECT 3, 'XYZ1', '1-FEB-2001' FROM DUAL
               UNION ALL
               SELECT 3, 'XYZ2', '2-FEB-2001' FROM DUAL)
    SELECT *
      FROM (SELECT S_NO,
                   name,
                   RANK ()
                   OVER (PARTITION BY s_no
                         ORDER BY TO_DATE (dt, 'dd-mon-yyyy') DESC)
                      rk
              FROM t
             WHERE dt IS NOT NULL)
     WHERE 1 = RK
    
  • just curious, using pl.sql for the site

    Hello all;

    I have a small question, I made it using other tools, but I'm just trying to learn a few things again associated with pl/sql. If I have a site similar to below.

    http://www.BBC.co.UK/news/

    and I want to extract only the date of this site which is July 5, 2012 update at 14:38 HE and record that information in a table. Is this possible with pl/sql

    http://www.morganslibrary.org/reference/pkgs/utl_http.html

    If you use 11 GR 1 material or above you will also need this:
    http://www.morganslibrary.org/reference/pkgs/DBMS_NETWORK_ACL_ADMIN.html

Maybe you are looking for