Procedure to take income data set and return the result set

Hi all

I have a situation where there will be a 'standard' set of data (source_data below), and I need to get information on outcomes for certain groups of customers (client_data for example). As SQL right it would be very easy (see below) - real world problem is a bit more complicated. However, what I would do is set up a procedure so that I can pass on my data of client variables and it will spit back on a set of data that is identical to the output of the given SQL.

A pointer in the right direction would be appreciated. If I could 'pass customer data' as a string that contains an SQL query, which would be even better, for example

GetResults ("select client_id, min (whatever_date) from some_client_data which...", MyOutputRefCursor?)
create table source_data
(client_id integer,
tdate date,
amount number(6,2));

create table client_data
(client_id integer,
critical_date date);

insert into source_data values(1,to_date('20090104','yyyymmdd'),1000);
insert into source_data values(1,to_date('20100104','yyyymmdd'),2000);
insert into source_data values(1,to_date('20110104','yyyymmdd'),3000);
insert into source_data values(1,to_date('20120104','yyyymmdd'),4000);
insert into source_data values(2,to_date('20090104','yyyymmdd'),5000);
insert into source_data values(2,to_date('20090604','yyyymmdd'),1000);
insert into source_data values(2,to_date('20100104','yyyymmdd'),2000);
insert into source_data values(3,to_date('20091004','yyyymmdd'),3000);
insert into source_data values(3,to_date('20091104','yyyymmdd'),4000);
insert into source_data values(4,to_date('20090104','yyyymmdd'),5000);
insert into source_data values(4,to_date('20090604','yyyymmdd'),2000);

insert into client_data values(1,to_date('20110104','yyyymmdd'));
insert into client_data values(2,to_date('20090604','yyyymmdd'));


select c.client_id,
  sum(CASE WHEN tdate < critical_date then amount else null end) used_before,
  sum(CASE WHEN tdate >= critical_date then amount else null end) used_after
from source_data s
inner join client_data c on s.client_id = c.client_id
GROUP BY c.client_id;
Thank you

Jon

Hello

You can do this with a view. Make settings of the view a global temporary table:

create GLOBAL TEMPORARY table client_data
(       client_id       integer
,     critical_date      date
)
ON COMMIT PRESERVE ROWS
;

Then, you can create a view based on your real of the table and the parameter array:

CREATE OR REPLACE VIEW     special_clients
AS
select c.client_id,
  sum(CASE WHEN tdate < critical_date then amount else null end) used_before,
  sum(CASE WHEN tdate >= critical_date then amount else null end) used_after
from source_data s
inner join client_data c on s.client_id = c.client_id
GROUP BY c.client_id;

Because the table of parameters is a global temporary table, each session will have its own private copy of the table of parameters and therefore his own private version of the view.

Tags: Database

Similar Questions

  • How can I take an anchored frame and return the paragraph tag used?

    I need to analyze through anchored frames and return the tag of paragraph that it is spotted. I can't find a property which returns the paragraph tag. Anyone have any ideas?

    Try this on the anchored frame selected:

    #target framemaker
    
    var doc = app.ActiveDoc;
    var aFrame = doc.FirstSelectedGraphicInDoc;
    var pgf = aFrame.TextLoc.obj;
    
    alert (pgf.Name);
    

    Rick

  • How to perform a function and return the result in a variable of liaison

    Hello

    I'm trying to calculate the sum of the salaries of all persons with a particular using a function JOB_ID TOTAL_INCOME (v_job_id).

    create or replace function total_income
    + (v_job_id in VARCHAR2) +.
    Number IS BACK
    v_total number (6);

    cursor get_sal is
    Select the pay of employees
    where job_id = v_job_id;
    BEGIN
    v_total: = 0;
    for emp in get_sal
    loop
    v_total: = v_total emp.salary; +.
    end loop;

    dbms_output.put_line (' Total salary ' | v_job_id |' is: ' | v_total);
    Return v_total;
    END;

    Now I woud like to perform this function and assign the value returned in a variable binding test_sal

    test_sal variable number (6)
    SELECT total_income ('AD_VP') in: test_sal FROM DUAL;
    dbms_output.put_line (' Sal Total :'||: test_sal);

    This returns the errors below:

    SELECT total_income ('AD_VP') in: test_sal FROM DUAL
    *+
    Error on line 0
    ORA-01036: illegal variable name/number

    dbms_output.put_line (' Sal Total :'||: test_sal);
    Error on line 3
    ORA-00900: invalid SQL statement

    Could someone help me what could be the problem? Thanks for your time...

    Hi Kiran and welcome to the forum,

    You mix SQL and PL/SQL

    It's the way in which SQL:

    SQL> SELECT total_income('AD_VP') FROM DUAL;
    
    TOTAL_INCOME('AD_VP')
    ---------------------
                      123
    1 row selected.
    

    It comes to PL/SQL in SQL * more

    SQL> variable test_sal number
    SQL> execute :test_sal := total_income('AD_VP')
    PL/SQL procedure successfully completed.
    SQL> exec dbms_output.put_line('Total Sal:'||:test_sal)
    Total Sal:123
    PL/SQL procedure successfully completed
    

    Concerning
    Peter

  • Decoding the date to sysdate and return the result as possible

    Hello

    I would like to create an expression that compares a date with the sysdate field and then he categorizes with decoding, this is what I tried so far but it through a mistake of the closing parenthesis.
    SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 31 16:51:21 2009
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    SQL> SELECT DECODE((date_expired < sysdate), date_expired, 'CURRENT')
      2    FROM tablename
      3  /
    SELECT DECODE((date_expired < sysdate), date_expired, 'CURRENT')
                                *
    ERROR at line 1:
    ORA-00907: missing right parenthesis
    
    SQL>
    The error corresponds to the 28 column that lies between date_expired and <.

    Thank you
    Ben

    Hi Ben,

    Decode is a function SQL and SQL ignores Boolean values. If the Analyzer does not provide the< sign="" and="" expects="" a="" right="" parenthesis="" at="" that="">

    You can use something like:

    case
      when date_expired < sysdate then ...
      when date_expired = sysdate then ...
      else ...
    end
    

    Kind regards
    Rob.

  • Plink and return the results

    I tried to find out if it was possible with plink to return data to powershell?  If so anyone got examples of that?

    You can find an example in 12 Re: get the details of the HBA hardware  

  • PLSQL function to return the result of the query

    Dear all,

    Oracle Database SE1 11.2.0.1

    I need to create a plsql function which should accept SQL as a parameter, execute it and return the result set.

    Is this possible?

    Madhu.149 wrote:

    I need to create a plsql function which should accept SQL as a parameter, execute it and return the result set.

    Be careful - results games indicate a set of data stored in memory. This is not what are sliders. This isn't how Oracle should be used.

    Imagine that you implement such a result set function - which, on average, requires 1 MB of memory (private server) to store the results of the SQL query. A 100 users mean a 100 MB of memory required server. This is not suitable. Not at all. Never.

    The correct back 'thing' is a handle to SQL cursor (called a ref cursor in this case). A SQL cursor is a "program" - that the appellant runs via the fetch command and generates one or more lines accordingly. Appellant repeatedly runs this slider through calls to fetch until this slider found and returns all rows affected (using consistent readings).

    If you want an abstraction interface that the client can call via PL/SQL code in the database, so this crafting optimal SQL interface, creates the SQL cursor and returns the handle of the cursor (via the ref cursor data type) to the client.

  • Reading number of XML nodes in a document &amp; amp; return the result in the text member

    Hi all

    I wonder if you can help me with the following:

    I want to read the number of nodes in an XML document and return the result in a text cast member. That's what I do so far, but he refuses to work

    Yes, my mistake. That should have been:
    --
    tList =
    nNodes = count(tList[1])
    sText = «»
    Repeat with i = 2 to nNodes
    tText = tList [1] .getPropAt (i)
    sText = sText & tText & RETURN
    end repeat
    -Remove rear BACK tank
    remove the last tank of sText
    -Place ALL the text in a text member
    Member ("test1"). Text = sText
    -- ...

  • ProBook 455 L3P93ES G2 #ABZ: installation without end and return the video driver AMD R6 and R7 M260DX and stop on a black screen system

    Hello, I'm in trouble with this problem. If anyone can help me, I appreciate a lot. Thank you in advance.

    Laptop: HP ProBook 455 G2 L3P93ES #ABZ

    Problem: windows back AMD R6 and R7 video driver to the old version of windows update install. Return process the screen come black and stop here.

    Procedure, I followed:

    1. updating the bios with the latest version (M75_0141.bin)
    2. new facility created by HP Cloud recovery customer USB boot disk
    3. Install the drivers and programs of the HPSoftwareSetup.exe util
    4. Connect the network cable and upgrade the drivers and the HP Support tool programs assistant
    5. Install the software
    6. Join the Organization's domain
    7. Force Windows Update to version 1607 by the upgrade of Windows tool
    8. Windows Update

    Item 4, at random, windows update 10 and return the driver from these versions:

    • 15.201.1301.0
    • 15.201.2301.0
    • 15.300.1025.1001

    I don't have install the AMD specific video driver (Radeon Crimson Edition 16.7.3 software) or drivers from the Chipset AMD (Crimson edition 16.7.3) because when I try in a previous installation of test I had the same problems

    To restore the display I have to start windows in safe mode and disable the two R6 and R7 display cards, and then restart. After that I can reactivate the cards one time.

    This device first question first time I install Windows 10 the year in August (Yes, after a few days Windows 10 out)

    Any help that will be much appreciate because I have to reinstall on 20 laptops for the school to start the day.

    Thank you

    ScuolaCarovana

    Hello;

    Let me welcome you on the HP forums!

    From your description, it seems that, after you have installed the correct video driver for your ProBook (15.201.1301) AMD, Windows Update is then by installing a different driver on top of that, right version?

    If this is the case, you must follow these instructions to STOP Windows update update drivers: how stop Windows 10 to update automatically the device drivers - windows Windows 10-10

    Once you do this, you should not see updates to the pilot after that.

    Good luck

  • my computer is connected to a new projector with a DVI and HDMI cable, and return the currency I installed correctly but I don't get a picture on the projector

    I connected my computer to a new projector with a DVI and HDMI cable, and return the currency I installed correctly but I don't get a picture of the projector, need HELP.

    Hi Bill,

    Thanks for asking this question to Microsoft Community.

    I will definitely help you to set up the projector, but before starting, I would ask you some troubleshooting questions.

    What version of the Windows operating system is installed on the computer? Do you get any error messages? Have you done a recent software or changes to the material on the computer?

    Here is a link that provides information on connecting to a projector. Go through it and check if it helps.

    Hope this information is useful and provide us with more information for further assistance. We will be happy to help you.

  • ESX3.5U4/VC2.5 - move vmdk to adequate data store and extend the drive on the virtual machine

    ESX3.5U4/VC2.5 - move vmdk to adequate data store and extend the drive on the virtual machine

    Objective: move vmdk to store data with adequate storage and then increase storage D: 20G to 100G

    Converter is not available on this architecture. Can I migrate cold vm to the different data store, no prob.

    Question: Without use of the converter, method 3 can be used without a secondary vm? In other words, just by using target vm offline, online, offline? Or is it a problem of signing/OS disk on the Windows Virtual PC?

    I need to move vmdk in different LUN and extend drive vm windows on D: (non-OS drive). Is this possible via the single procedure? Options?

    To use method 3 to http://communities.vmware.com/thread/81121 requires available vm 'secondary', I did not.

    Method 3? Using of vmkfstools and another VM of Windows to extend a drive

    o stop the VM to resize

    o log in the console ESX Server via Putty

    o Type? vmkfstools? X & lt; new size of drive & gt; vmfs/volumes / & lt; storage volume name & gt;. / & lt; virtual server name & gt;. / & lt; the virtual disk name & gt;? That is to say. /vmfs/volumes/Storage1/my_vm.VMDK new disk size can be specified in kilo, mega, or gigabytes and will be the total size of the new disk. So if you want to increase a virtual disk of 20 GB of 24GO you would put 24000 m or 24g

    o the second virtual machine to help stop

    o change the second virtual machine settings and add the first virtual machine hard drive

    o power on the second VM and load the disk management snap-in and verify that the first virtual machine disk has unallocated on it space

    o select Start, run and enter diskpart.exe

    o the command? the list of volume? This will show you all the volumes.

    o select your volume based on the results of the list volume command, IE. ? Select volume 1?

    o type the command? extend? to extend the volume

    o check again the disk management snap-in and the volume is expected to be expanded with a greater ability

    o stop the second VM and remove (do not remove) the record of it

    o turn your first VM and the new space should be there and ready to use.

    Also, I'm already aware of Dell extpar:

    http://www.RTFM-ed.co.UK/?p=1310

    http://support.Dell.com/support/downloads/download.aspx?c=us & CS = 19 & l = in & s = DHS & ReleaseID = R64398 & formatcnt = 2 & starts = 83929

    for VI3, vmoiton of storage is made by RCLI plugin or a 3rd party

    I prefer the plugin

    http://www.virtualizationadmin.com/articles-tutorials/VMware-ESX-articles/VMotion-DRS-high-availability/storage-VMotion-SVMotion-VI-plugin.html

    In addition, if the option to increase the size of the disk in the VIC is grayed out, it sounds like a permissions issue.  Finally, you can not extend the disc using the VIC, if the customer in question has a snapshot.

  • I need to return the result of a query on a stored procedure

    I need to return the result of a query to a stored procedure, I mean when I run a stored procedure it returns a result set in a select statement.
    Best regards...

    Hello.

    Do you really want a stored procedure for this?
    Why not just a script that contains the query?

    Assuming that you don't really want a stored procedure, you'll have to decide what to do with the results.
    An option is a slider.

    For example, you can write a procedure of this type to hold the query:

    CREATE OR REPLACE PROCEDURE USP_TEST
    (     out_cursor     OUT     SYS_REFCURSOR
    )
    IS
    BEGIN
         OPEN  out_cursor
         FOR     SELECT     *
              FROM     scott.emp;
    END  USP_TEST;
    /
    SHOW ERRORS
    

    You can move the cursor to another procedure for handling.

    You could test this in SQL * more by creating a variable blond:

    VARIABLE     usp_test_cursor     REFCURSOR;
    
    EXEC  usp_test (:usp_test_cursor);
    
    PRINT     :usp_test_cursor
    
  • How to compare data from the two table column by column and connect the result compared to the separate table

    Hello experts...

    I'm new to this forum and Oracle coding complex.

    I have a task in which I want to compare two tables with the same structure, same columns. My Oracle database is 11g Release 2. I want this column-by-column comparison and save the result in a separate table. (say result_table)

    The structure of the table would be as follows:

    SQL > desc emp;

    Name                                      Null?    Type

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

    EMPNO NOT NULL NUMBER 4

    ENAME VARCHAR2 (10)

    JOB                                                VARCHAR2(9)

    MGR                                                NUMBER(4)

    HIREDATE DATE

    SAL                                                NUMBER(7,2)

    COMM                                               NUMBER(7,2)

    DEPTNO NUMBER (2)

    SQL > emp_comp desc;

    Name                                      Null?    Type

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

    EMPNO NOT NULL NUMBER 4

    ENAME VARCHAR2 (10)

    JOB                                                VARCHAR2(9)

    MGR                                                NUMBER(4)

    HIREDATE DATE

    SAL                                                NUMBER(7,2)

    COMM                                               NUMBER(7,2)

    DEPTNO NUMBER (2)

    Both of the tables EMPNO is the primary key.

    I want to compare these two tables based on the EMPNO (EMPNO even is both tables).

    The result log table would be as follows:

    SQL > create table result_table

    2 (check_sr_no, number (5),)

    table_name 3 varchar2 (30),

    ROW_ID 4 varchar2 (20).

    column_name 5 varchar2 (20).

    6 column_data varchar2 (1000).

    compared_by 7 varchar2 (10));

    Table created.

    SQL > alter table result_table

    2 Add the constraint result_table_pk

    3 primary key (check_sr_no);

    Modified table.

    The name of the table and the name of the column will not be hardcoded (based parameter by user)

    I tried to use the dbms_comparison package, but do not find comparison of column to column.

    I also used by using the query operator LESS. It's showing the difference in rank.

    I also went to https://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:2151582681236

    Your help will be very appreciated.

    Thank you

    DK

    Tom Kyte has answered this question MANY times over the years. Here are links for its solution

    https://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:4934799800346640847

  • Petition for grant to display all objects in the DB in the data base and discovers the DOF for each.

    Dear administrators,

    I created the user but now I have a requirement for the granting of privileges to view all objects in the DB in the data base and discovers the DOF for each.

    Any help please

    Ritz

    Thanks to advise all the

  • Refcursor takes a long time to print the results

    Hi gurus,

    I have a table with name kemp with columns


    kemp_ID NOT NULL NUMBER (10)
    ACRONYM CLOB
    TERM CLOB
    DEFINITION of CLOB
    when I do a query on the table
    Select * Kemp; results will soon appear less than * 1.5 seconds *
    But when I write a procedure to return the results using refcursor

    Create procedure pr_retall (cv_1 in the sys_refcursor)
    as
    Start
    Open SELECT cv_1 * Kemp;
    end;
    set serveroutput size unlimited;
    var x 1 refcursor;
    exec pr_retall(:x1);
    print x 1;
    It takes around * seconds * 7 to appears.

    Please tell me know ways to tune. I want to reduce the time that it is to consume.

    Thank you and best regards,
    Vikas Krishna

    Vikas Krishna wrote:

    Please find the schedule.

    Using elapsed time (like you) to measure and benchmark performance is not going.

    Why? Because the test2 is given rarely, if ever how these tests are usually done, executed with the help of the same conditions that test1 was executed in.

    Conditions are different between the tests, the elapsed time is different. As conditions differ, you cannot compare test1 with test2. I gave an example of what a mistake it is thread {message identifier: = 4333700}-where physical i/o slows test1 and test2accelerates the logic I/O. And how this can be used to support the conclusion that the CBO does not exist hint warp_drive increased performance of test2.

    If you want to compare test1 against test2, you must know exactly in detail how each test works technically... you want to know how to ensure that the common point between two tests remain constant for all tests and how to measure only the elements that differ between tests.

    And no, the comparative analysis is not that complex. In fact, it is even more complex than that. It is best left to those who know how to compare... on behalf of those who can find significance in the result of this benchmark.

    For the majority of us work and development in the real world, comparative analysis makes a useless answer to a question meaningless for an absurd question. Totally useless...

  • Monitor the quality of my Internet service provider and document the results.

    OT: ping.

    I am trying to monitor the quality of my Internet service provider and to document the results.   I would like to create a ping file during the execution of the order would send ping results to the screen and a file.   I ran the file whenever the computer is turned on.  The batch file must run continuously until interrupted and view the results of ping on the screen without the statistics, and it looks something like:

    Reply from 173.194.115.4: bytes = 32 time = 19ms TTL = 52

    Reply from 173.194.115.4: bytes = 32 time = 17ms TTL = 52

    Reply from 173.194.115.4: bytes = 32 time = 12ms TTL = 52

    Request timed out.

    Reply from 173.194.115.4: bytes = 32 time = 25 ms TTL = 52

    Reply from 173.194.115.4: bytes = 32 time = 191ms TTL = 52

    ...

    In the file, it should write the results and look like:

    Wednesday, December 2, 2015 9:30:34.02 response from 173.194.115.4: bytes = 32 time = 19ms TTL = 52
    Wednesday, December 2, 2015 9:30:34.58 request has expired.

    ...

    The batch file should display the results of ping on the screen.

    In the file, it should write the results and look like:

    It is one or the other: write the result on the screen or write to a file.

    It seems that you forgot to ask a question. If you want to know how to do such a thing, so this batch file would do the trick. It will write the result in the desktop Ping.txt file.

    off @echo
    Set IP = 173.194.115.4
    value = Write date % echo %%d time % > ^ > '% UserProfile%\Desktop\Ping.txt '.

    : Loop
    for /F "delims =" % in (' ping-n 1% IP % ^ | findstr /i "demand response" ' "") do write %
    Timeout 5 > zero
    GoTo loop

Maybe you are looking for