How can I write code that uses schemas returned by one query to run another

I need to use the data returned by this SQL
Select owner
From dba_tables
Where tablename = 'TRANSACT';
To run the following SQL for every schema in the database:
Select $vschema, count(*)
from $vschema..transact;
Where I am using $vschema as a variable to hold owners returned by the first statement.
I have tried using 1 cursor, 2 cursors, 1 coursor and an execute immediate command and either my code fails or I get a message that it ran successful but I cant see the data that I want returned by the second query.

I don't actually want to get the count on the transact table for each schema I just used that as an example to simplify... Maybe the code that I have written so far would be better... Here is one attempt:
SET SERVEROUTPUT ON SIZE 1000000
SET VERIFY OFF
DECLARE
v_schema Varchar2(50);
v_chgdate DATE;
v_debits NUMBER(14,4);
v_amount NUMBER(14,2);
/* First cursor */
CURSOR get_schemas (v_schema OUT char) IS
SELECT DISTINCT t.owner
FROM sys.dba_tables t
WHERE t.table_name = 'GERCVLOG'
ORDER BY t.owner;
/* Second cursor */
CURSOR get_stats (v_schema IN char) IS
SELECT MAX(g.chgdate),
SUM(g.debits),
SUM(g.totalamt)
FROM &&v_schema..gercvlog g
WHERE g.chgdate >= '01-Jan-07' or
g.chgdate = (SELECT MAX(g1.chgdate)
FROM &&v_schema..gercvlog g1);
BEGIN
/* Open first cursor*/
OPEN get_schemas (v_schema OUT char);
LOOP
FETCH get_schemas INTO v_schema;
EXIT WHEN get_schemas%NOTFOUND;
dbms_output.put_line('Schema: '||v_schema);
OPEN get_stats (v_schema IN char);
LOOP
FETCH get_stats INTO v_chgdate, v_debits, v_amount;
FETCH get_schemas INTO v_schema;
EXIT WHEN get_stats%NOTFOUND;
dbms_output.put_line('Latest Import: '||v_chgdate);
dbms_output.put_line('Total Debits: '||v_debits);
dbms_output.put_line('Total Dollars: '||v_amount);
dbms_output.put_line('______________________________');
END LOOP;
CLOSE get_stats;
END LOOP;
CLOSE get_schemas;
END;
/

Similar Messages

  • How can i write code in Inbound ABAP proxy method

    Hi,
    All
    Iam doing server proxy ascenario
    /people/siva.maranani/blog/2005/04/03/abap-server-proxies
    i have done
    steps:
    1:I have done inbound  proxy interface in xi
    2:i have created a inbound abap proxy in my SAP WEB AS6.4 using SPROXY.
    3:I need to write code in Z11_EMPDETAILS_IN~EXEXUTE_ASYNCHRONOUS method
    if i double click on that method it is not opening how can I write code.

    Hi,
    You have to goto the class
    <b>ZCL</b>_EMPDETAILS_IN~EXEXUTE_ASYNCHRONOUS not
    <b>Z11</b>_EMPDETAILS_IN~EXEXUTE_ASYNCHRONOUS
    Check on the third step.
    Regards
    Vijaya

  • How can i write code inside methods.

    Hi,
       I am new to wbdynpro. How can i write code in Webdynpro?
    I have created one layout in that two textboxes are there. After entering the details when i click on the button the datas should be saved into the database table. How can i write code in this.
    please help me.
    Shyja

    Hi,
    First in context create node for 2 input field. Then disign layout for input filds and do data binding. Then create button and assign ON action event to it. In action method use wizard to read the values from the node.
    DATA: Node type REF TO IF_WD_CONTEXT_NODE,
    elem_node1 TYPE REF TO if_wd_context_element,
    stru_node1 type ZEMP.
    Node = wd_Context->get_Child_Node( Name = `S_NODE2` ).
    get element via lead selection
    elem_node1 = node->get_element( ).
    get all declared attributes
    elem_node1->get_static_attributes(
    IMPORTING
    static_attributes = stru_node1 ).
    INSERT ZEMP FROM stru_node1.
    If helpful reward points.
    Regards,
    Karthick S

  • How can I open websites that use adobe flash ?

    How can I open websites that use adobe flash ?

    The website should open, but the Adobe Flash will not work as there's no Flash plug-in for mobile Safari.
    After some failed attempts by Adobe to work out Flash for iPad, Apple decided to forgo it, and Steve Jobs published a famous letter on the reasons why Apple would not be supporting Flash on iPad.
    The fall, Adobe announced that they were abandoning Flash on all mobile platforms, including Android, and they have deprecated the use of Flash as a plug-in on Desktop platforms. Flash will be moving to become a platform for development of cross-platform desktop applications and HTML5 will replace it for web and mobile purposes.
    Web sites that still use Flash will slowly move away from the technology in the next few months. Most web sites that expected traffic from mobile device users have already moved away from using Flash.

  • How can I remove the Apple ID authorization only on one computer and authorize another in his place?

    how can I remove the Apple ID authorization only on one computer and authorize another in his place?

    De-authorize the computer in question.
    Then authorize the new computer.
    Or de-authorize all computers and authorize only the ones that actually exist.

  • How can change my code without using if else in procedure

    Hai ,
    I have wrote code like this
    if RPTFORMNTH='M' then
    SELECT coalesce(SUM(IN_RWEEKS),0),
    INTO C2_COL1
    FROM HS_CASEDTA_DTLS_TB
    WHERE UPPER(VR_HAUNM) like NVL(case when HAUNM='0' then null else UPPER(HAUNM) END , UPPER(VR_HAUNM))||'%'
    AND IN_ULBOBJID=ULBOBJID AND CH_FLAG!='D'
    AND VR_RPTFORMNTH=VR_RPTFORMNTH
    AND IN_YEAR=IN_YEAR;
    ELSE
    SELECT
    coalesce(SUM(IN_RWEEKS),0),
    INTO C2_COL1
    FROM HS_CASEDTA_DTLS_TB
    WHERE UPPER(VR_HAUNM) like NVL(case when HAUNM='0' then null else UPPER(HAUNM) END , UPPER(VR_HAUNM))||'%'
    AND IN_ULBOBJID=ULBOBJID AND CH_FLAG!='D'
    AND
    TO_DATE(('01/'||VR_RPTFORMNTH||'/'||IN_YEAR),'DD/MM/YYYY')
    BETWEEN to_date('04/' || to_char(RPTYEAR-1),'MM/YY')
    AND add_months(to_date(RPTFORMNTH || to_char(RPTYEAR),'MonYYYY'),1)-1;
    END IF;
    My query is without using if else and replicate data in if and else how can i modify code.Observe that only where condition i want changes that's why i used if else without that how can i modify where clause with that two conditions.Please give me guidance.
    Regards ,
    rajendar.

    hi,
    I think you want your condition to change inside the where clause so you could have only one select statement. If that is so try this:
    SELECT coalesce(SUM(IN_RWEEKS),0),
    INTO   C2_COL1
    FROM   HS_CASEDTA_DTLS_TB
    WHERE  1 = CASE WHEN RPTFORMNTH='M' THEN
                    CASE WHEN UPPER(VR_HAUNM) like NVL(case when HAUNM='0' then null else UPPER(HAUNM) END , UPPER(VR_HAUNM))||'%'
                              AND IN_ULBOBJID=ULBOBJID AND CH_FLAG!='D'
                              AND VR_RPTFORMNTH=VR_RPTFORMNTH
                              AND IN_YEAR=IN_YEAR
                   THEN 1
                         ELSE 0
                    END
               ELSE --  RPTFORMNTH !='M'
                    CASE WHEN UPPER(VR_HAUNM) like NVL(case when HAUNM='0' then null else UPPER(HAUNM) END , UPPER(VR_HAUNM))||'%'
                              AND IN_ULBOBJID=ULBOBJID AND CH_FLAG!='D'
                              AND TO_DATE(('01/'||VR_RPTFORMNTH||'/'||IN_YEAR),'DD/MM/YYYY')
                              BETWEEN to_date('04/' || to_char(RPTYEAR-1),'MM/YY')
                              AND add_months(to_date(RPTFORMNTH || to_char(RPTYEAR),'MonYYYY'),1)-1
                         THEN 1
                         ELSE 0
                    END
               ENDMessage was edited by:
    Bobbydj
    hi Are, after belatedly reading Rob's post, I think his post is better. I was only looking at your highlighted code, but he took the most common conditions inside the where clause.

  • How can I identify reports that use specific tables

    Hi, is there a way that I can identify the reports that select from specific tables?  We have 3,000 reports in business object enterprise XI R2 SP5. and we're trying to identify all the reports that use a specific table.

    Or if you have a developer in Java or .NET available you can write one. Fairly simple to get the info.
    In .NET you would open each report, write the name of the report to a log file with the output of the SQL Statement:
    Using RAS as the report engine.
                GroupPath gp = new GroupPath();
                string tmp = String.Empty;
                rptClientDoc.RowsetController.GetSQLStatement(gp, out tmp);
                MessageBox.Show(tmp, "Data Source Set and SQL Statement", MessageBoxButtons.OK, MessageBoxIcon.Information);
    If you want more details is is available with a few more lines of code. The above would only show you what is used in the report.
    I don't believe there is a BOE tool that can do this but they may have one.
    Here's a link to the BOE Admin forum: BI Platform
    Thank you
    Don

  • How can i write code for close my application

    Hi,
    I m doing one apps in which i have 2 option and Agree and Quit. When user press Quit then my apps should be close and direct to main page of iphone. My apps should terminate.
    So anyone know that how can i do that?
    Thanks.

    Thank friend......... thanks a lot.... its working.......

  • How can u make sure that when you FaceTime it doesn't get to another apple product except for one?

    so me an brother both have ipod touches and he is connect to my account too and i dont recevie any facetimes from my friends but he does how can this stop? help please?

    You need to call Customer Service to help you with that: 888-294-6804

  • How can I write in Oriya using Oriya font?

    When I select Oriya font "Oriya Sangam MN" it does change the font but the font still stays in English. But I expect that to change into Oriya language fonts. The same thing happens when I select Kannada or Tamil.
    Is there a way through which I can write in regional Indian languages on iPad/iWork?

    Is there a way through which I can write in regional Indian languages on iPad/iWork?
    There is an app for some of them:
    http://m10lmac.blogspot.com/2010/12/indic-scripts-keyboards-available-for.html
    (It is important to understand that changing fonts does not change the language on any modern computer system. You must change the keyboard layout, and unfortunately it is not possible to add custom layouts to iOS devices yet.)

  • How can same vendor code be used for domestic & import purchases?

    Hi
    We have a vendor who was initially supplying domestic goods but now we are also going to import goods from him.
    The Client doesnt want two separate vendor codes since they cannot get composite balance for domestic as well as for imports under one vendor code.
    I do understand we cannot have two different Reconcilliation accounts for one vendor code even and if we have just one reconcilliation account we cannot bifurcate domestic and foreign purchases.
    Please suggest.
    Regards
    Kapil

    Hi,
    It is not possible to change the reconciliation account (SpGL or alternative account) in MIRO transaction. Of course you can make some modifications in MIRO in order to open for changes field "G/L account" on "Details" screen, but if you should not foget to modify MR8M.
    Another alternative is to repost the MIRO documents (vendor oen items) to the alternative reconcilation account with FB01.
    Regards,
    Svetlin

  • Can't build code that uses cpc_event_t

    Hello;
    I'm running on:
    69: uname -a
    SunOS chroma 5.10 Generic sun4u sparc SUNW,Sun-Fire-V490
    70: CC -V
    CC: Sun C++ 5.7 2005/01/07
    71:
    I can't think of why my program fails to build. This little test program has the same problem though:
    489: cat cpc_example.cpp
    #include <libcpc.h>
    main()
    cpc_event_t event;
    int cpuver = cpc_getcpuver();;
    char *setting = "pic0=EC_ref,pic1=EC_hit";
    cpc_strtoevent(cpuver, setting, &event);
    490: CC -lcpc cpc_example.cpp -o cpc_example -lcpc
    "cpc_example.cpp", line 5: Error: The type "_cpc_event" is incomplete.
    "cpc_example.cpp", line 7: Warning: String literal converted to char* in initialization.
    1 Error(s) and 1 Warning(s) detected.
    I greped under the /usr/include tree and my compiler installation tree and only found one reference for cpcevent.. It's used to define cpc_event_t in libcpc.h but doesn't seem to be defined any place.
    Thoughts?
    Kevin

    This seems a bug in Solaris 10 as the error didn't show up in Solaris 9. Please install all the recent Solaris 10 patches and see whether it goes away.
    Or try posting your question on Solaris OS forum at: http://forum.sun.com/category.jspa?categoryID=2
    Rose

  • How can I write more voices using the score editor?

    I'm writing a guitar piece with the score editor but I need to voices; the voice below should be a semibreve and the voice above a dotted minim and then a crotchet, how do I do it?

    Hi, here is one way to do this:
    http://help.apple.com/logicpro/mac/10/#lgcp8535c140
    …..let us know if you need more assistance.
    Cheers!

  • HT2204 how can i transfer the saved content in icloud from one apple ID to another?

    i forget my old apple ID account, and i have created new one
    and now, i want to transfer my old icloud to new one
    how to do in order to keep everything well?
    thanks so much

    Appple's policy states that Apple ID accounts including iCloud cannot be merged >  Frequently asked questions about Apple ID

  • HT201209 How can i move a redeemed itunes gift card from one apple id to another?

    I accidently redeemed two gifts card on one sons account instead of one on each of their accounts, can I move one of the gift cards to the other account?

    Welcome to the Apple Community.
    ......can I move one of the gift cards to the other account?
    Unfortunately not.

Maybe you are looking for