How to report o create crosstab in plsql function?

Hello

I want to create a function that question of including pivot table. What should be included, I'm using (cursor, folder,...)?

I transformed under code in link below for my project, but I didn't know where to put a block.

Example,

where I put or write the pivot block?

where can I write declare function block?

Thank you for taking the time, have a good day

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

Sum of the PIVOT queryl online

SELECT decode(GROUPING(emea) + GROUPING(lad) + GROUPING(apac) + GROUPING(nas) + GROUPING(japan), 5, 'TOTAL', kn) kn,
       SUM(emea) emea,
       SUM(lad) lad,
       SUM(apac) apac,
       SUM(nas) nas,
       SUM(japan) japan,
       SUM(emea) + SUM(lad) + SUM(apac) + SUM(nas) + SUM(japan) AS total
  FROM ((SELECT kz.kz_name AS kn, rl.region AS re, kr.amount AS am
           FROM region_lookup rl, kz_name_lookup kz, kz_reg kr
          WHERE rl.region_id = kr.region_id
                AND kz.kz_name_id = kr.kz_name_id)
        pivot(SUM(am) FOR re IN ('EMEA' AS emea, 'LAD' AS lad, 'APAC' AS apac, 'NAS' AS nas, 'JAPAN' AS japan))) t
GROUP BY GROUPING SETS((kn, emea, lad, apac, nas, japan),())
ORDER BY GROUPING(t.kn), t.kn;

You can declare a function that returns a ref cursor, then get Java to navigate the cursor until there finishes

sys_refcursor function MyCursorFunc is

vCur sys_refcursor;

Start

Open vCur for

SELECT decode (GROUPING (emea) GROUPING (FDA) + GROUPING (apac) + GROUPING (SIN) + GROUPING (japan), 5, 'TOTAL', kn) kn.

Sum (EMEA) emea,

Sum (FDA) boy,

Sum (APAC) apac,

Sum (SIN) Sin,

Sum (Japan) Japan,

Sum (EMEA) + SUM (FDA) + SUM (apac) + SUM (SIN) + SUM (japan) AS total

OF ((SELECT kz.kz_name AS kn, rl.region LIKE re, kr.amount MOD

Region_lookup rl, kz_name_lookup kz, kz_reg kr

WHERE rl.region_id = kr.region_id

AND kz.kz_name_id = kr.kz_name_id)

Pivot (Sum (AM) FOR re IN ("EMEA" IN emea, 'BOY' AS a boy, "ACPA" AS apac, "SIN" AS nas "JAPAN" JAPAN))) t

GROUP BY GROUPING SETS ((kn, emea, lad, apac, nas, japan), ())

ORDER BY GROUPING (t.kn), t.kn;

return vCur;

end;

How to call here

or

Why not just define a view?

create or replace view V_MyData as

SELECT decode (GROUPING (emea) GROUPING (FDA) + GROUPING (apac) + GROUPING (SIN) + GROUPING (japan), 5, 'TOTAL', kn) kn.

Sum (EMEA) emea,

Sum (FDA) boy,

Sum (APAC) apac,

Sum (SIN) Sin,

Sum (Japan) Japan,

Sum (EMEA) + SUM (FDA) + SUM (apac) + SUM (SIN) + SUM (japan) AS total

OF ((SELECT kz.kz_name AS kn, rl.region LIKE re, kr.amount MOD

Region_lookup rl, kz_name_lookup kz, kz_reg kr

WHERE rl.region_id = kr.region_id

AND kz.kz_name_id = kr.kz_name_id)

Pivot (Sum (AM) FOR re IN ("EMEA" IN emea, 'BOY' AS a boy, "ACPA" AS apac, "SIN" AS nas "JAPAN" JAPAN))) t

GROUP BY GROUPING SETS ((kn, emea, lad, apac, nas, japan), ())

ORDER BY GROUPING (t.kn), t.kn

/

Then in Java just run a query:

Select * from V_MyData

Tags: Database

Similar Questions

  • How to create a dynamic RTF report that creates dynamic columns based on the selection of dynamic columns in a table?

    Hi all

    Suppose I have table, whose structure changes frequently on a daily basis.

    For example. / / desc my_table gives you after the name of the column the day 1

    SQL > my_table DESC;

    Output

    Name

    Age

    Phone


    Day 2, two other columns are added, viz, address and salary.

    SQL > my_table DESC;

    Output

    Name

    Age

    Phone

    Address

    Salary


    Now, I want to create a Dynnamic RTF report which made extracting data from all columns from my_table daily. For this, I have defined a simultaneous program with XML output type and include in annex a data/definition of data model that takes XML as input and gives the final result of the conc program in EXCEL layout. I am able to do that for a constant number of columns, but don't know how to do it when the number of columns to display dynamically changes.

    For 1 day my XML file should be like this.

    <?xml version="1.0" encoding="UTF-8"?>
    <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0">
    <dataQuery>
    <sqlStatement name="Q2">
    <![CDATA[
    SELECT Name
    ,Age
    ,Phone
    FROM my_table
    ]]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="G_my_table" source="Q2">
      <element name="Name" value="Name" />
      <element name="Age" value="Age" />
      <element name="Phone" value="Phone" />
    </group>
    </dataStructure>
    </dataTemplate>
    
    

    And my day 1, EXCEL output RTF model should be like this.
    Name age phone

    Swapnill 23 12345

    For 2 days my XML file should be like this. With 2 new columns selected in the SELECT clause.

    <?xml version="1.0" encoding="UTF-8"?>
    <dataTemplate name="XYZ" description="iExpenses Report" Version="1.0">
    <dataQuery>
    <sqlStatement name="Q2">
    <![CDATA[
    SELECT Name
    ,Age
    ,Phone
    ,Address
    ,Salary
    FROM my_table
    ]]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="G_my_table" source="Q2">
      <element name="Name" value="Name" />
      <element name="Age" value="Age" />
      <element name="Phone" value="Phone" />
      <element name="Address" value="Address" />
      <element name="Salary" value="Salary" />
    </group>
    </dataStructure>
    </dataTemplate>
    
    

    And my day 2, exit EXCEL model RTF should be like this.
    Name address telephone pay

    23 12345 Madrid 100000 Swapnill

    Now, I don't know below things.

    • Make the dynamic XML as we did in the day 1 there are 3 columns in the SELECT statement and the day 2, 5 columns. I want to create a dynamic XML which must not be changed if the new columns are added into my_table. I don't know how to create this query and also create their corresponding items below.
    • Make the RTF model dyanamic as day 1 there are 3 exit EXCEL columns and the day 2, 5 columns. I want to create a dynamic RTF model that would display all the columns selected in XML dynamic. I don't know how the RTF will create new XML tags and how it will know where to place them in the report. Means, I can create model RTF day 1, by loading the XML data for 3 columns and place 3 tags XML in the model. But how he will create and place the tags for the new columns the day 2?

    Hope so, you got my requirement, it's difficult. Please let me know how I can implement the necessary solution using the RTF dynamically without any manual intervention.

    Kind regards

    Patricia K.

    Post edited by: SwapnilK

    Hi guys,.

    I was able to solve above the requirement.

    I created a procedure that would create & update (attached to the data definition) XML file dynamically for each race. This dynamic XML contains the SQL statement for the data query that is built dynamically. I am updating this XML file using XDOLoader utility to the definition of data. Then run my program customized to generate the excel output.

    Exit excel retrieves correct number of columns dynamically (3 on Day1 and Day2 5), with corresponding data records.

    Kind regards

    Patricia K.

  • How to find so far how many virtual machines created. ?

    Hi all
    is there anyway in vfoglight, find so far how many virtual computers created.

    very much appreciate your help.

    Thank you
    amreddy

    You can create a drag and drop dashboard/report for this information table.

    Details:

    Create dashboard (right Menu)

    VMware, Virtual Center + name of the virtual centre (right Menu - data tab)

    Drag "virtualMachinesCount" on the dashboard

    Select a chart

    Set the time range you want. (Top right of the screen)

    FYI: County of VM is also avialable from a datacenter and cluster level.

  • How to transfer playlist created on itouch to itunes 5

    How to transfer playlist created the itouch5 to itunes

    Playlists on a synchronized device should copy in the library when you synchronize the device. However, it would be a pity to lose the list in question during the test. See ImportDevicePlaylists for a script that can import lists of your device.

    TT2

  • How to report a provider using unlicensed Microsoft products?

    How can report you a Microsoft Certified provider who is using unauthorized copies?

    Please see: report suspected piracy (in the United States) or report piracy outside the United States

  • How or can I create multiple new folders instead of doing one at a time?

    original title: create multiple new folders

    How or can I create multiple new folders instead of doing one at a time?

    The number of cases, where you want to create, and what you want to call them?

    You can create a group of folders by entering commands in a command prompt window.  For example, to create a folder for each day of the week in C:\Users\Public:

    CD /d c:\users\public
    for %d in (Mon, Mar, sea, game, Fri, sat, Sun) do mkdir %d
       Boulder computer Maven
    Most Microsoft Valuable Professional

  • I'm possitive that is illegal but don't know how to report it.

    I was looking for a cheap second hand computer Chair and keep coming across this guy adds. http://capebreton.Kijiji.ca/c-buy-and-sell-computer-accessories-fix-your-own-computer-today-or-allow-me-to-do-it-for-you-W0QQAdIdZ165752897 he said that he has a volume license and sells copies of XP for $20 to use. Now I'm a professional and positive that it's against the license agreement. Am I wrong? or is his claim that he is right. Also if I am how I report it. Such things are the reason small time sellers can get a foot in the door of the local market

    It seems certainly fishy to me, but I have no way of really knowing. Here is the link for reporting piracy:

    http://www.Microsoft.com/piracy/reporting/default.aspx MS - MVP - Elephant Boy computers - don't panic!

  • How to create a user-defined function?

    is there a substitute for the exe instsrv and srvany in Vista?

    I don't know what means your post, so here's how to create a user-defined function:
    1) click Start
    (2) select "Control Panel".
    (3) select "system and maintenance".
    4) click on "Administrative Tools".
    5) click on "Task Scheduler."
    (6) click on "create task" (right in the list pane under) "Actions") "
    "(7) opened in the general tab it will choose if it only works when the account that is used to implement is connected, or ' if that user is logged in or not" (leave the box ' do not store the... "empty password)
    (8) always in the general tab, check the box 'run with highest privileges '. (This will ensure that no program can block)
    (9) type a name for the task (in the general tab)
    (10) to set the job to run an awhile, use the "triggers" tab, if you want to set a task runs after xx min. temps_inactivite, choose the 'conditions' tab, then choose the desired time.
    (12) click on the 'actions' tab click on 'new '. in the program/script line, search for and select the program you want to run, and then click Open.
    13) click OK in the window "create a task".
    14) click OK again and you are done.
    I hope this helps.

  • How to report a phishing scam email?

    Why is it so darn difficult to report a phishing scam.  I wanted to just make a copy and send it to you, but I can't find an email address to do this.

    * original title - why is so darn difficult to report a phishing scam.  I wanted to just make a copy and send it to you but I can't find an email address to this.*

    Research on the Internet are great ways to locate things.  Using your query...

    Report phishing Microsoft

    Where notable successes are:

    The first has a link (How to report scams) which will take you to a party later on this page which States:

    How to report a scam

    You can use Microsoft tools to report an alleged scam.

    • Internet Explorer. While you are on a suspicious site, click on the gear icon, then tap on Security. Then click on Report Unsafe website and use the web page that is displayed to inform the Web site.

    • Hotmail. If you receive a suspicious email message that asks for personal information, click on the checkbox next to the message in your Hotmail Inbox. Click on mark as , then point to Phishing scam.

    • Microsoft Office Outlook. Attach the suspicious email message to a new e-mail message and send it to * address email is removed from the privacy *. To find out how to join an e-mail message to an e-mail message, see attach a file or other item to an e-mail message.

    You can also Download the Microsoft Junk E-mail Reporting Add-in for Microsoft Office Outlook.

    The second is a list of frequently asked questions where is the third frequently asked questions:

    How can I report a possible phishing scam?

    You can also use Microsoft tools to report a suspected phishing scam.

    • Internet Explorer. While you are on a suspicious site, click on the gear icon, then tap Security. Then click on Report Unsafe website and use the web page that is displayed to inform the Web site.

    • Windows Live Hotmail. If you receive a suspicious email requesting personal information, click on the checkbox next to the message in your Hotmail Inbox. Click on mark as , then point to Phishing scam.

    • Microsoft Office Outlook. Attach the suspicious email message to a new e-mail message and send it to * address email is removed from the privacy *. To find out how to join an e-mail message to an e-mail message, see attach a file or other item to an e-mail message. You can also download the Microsoft Reporting Add-in for Microsoft Office Outlook junk e-mail.

    A certain rehash of the first (or vice versa), but "the truth is there.  :-)

  • My question is: is there an approach appropriate to where and how files should be created and arranged, except directly in your main drive, in my case C:?

    I recently had a hard drive replaced requiring a new installation of Windows 7. When I went to get the system in place, the guy who set up Windows told me that he created the user directory specifically in a way so that new files to be created in a Documents folder that was created under the username. At least that's what, in my view, said.

    In any case, I always create new folders and their subfolders under Local C: drive.  My question is: is there an approach appropriate to where and how files should be created and arranged, except directly in your main drive, in my case C:? Thank you for your help.

    Windows 7 has been designed with the intention that user folders and files will be store in one of the folders under the users, that is to say the Documents, photos, etc.

    It is not recommended to store in the root, i.e. C:\ directory.

    If you have any other disks or partitions, you can store what you want there.

  • How to report spam to seller?

    PlayViet is spamming PIN of the people on this forum with messages on their applications.

    How we report to BlackBerry?

    Is it possible to add single firewall PIN numbers?

    Would report it to the moderators or community admin for your developer forum space.

    As in MSohm, for example. Send a private Message to this information and let him handle it.

  • Smartphones blackBerry how to report a bug in the operating system or HW?

    Hi all

    I would like to know how to report a bug in the operating system or a bug of the HW? Post a message here looks like post it anywhere... If there is a serious bug in the operating system, how can I report on BOARD?

    Boris

    borisporosin wrote:

    I would like to know how to report a bug in the operating system or a bug of the HW?

    [email protected]

    borisporosin wrote:

    Post a message here looks like post it anywhere...

    Correct - this forum is a support system-based user community. ON-BOARD staff rarely participate and check no reports of bugs here.

  • Anyone know how this graph is created?

    Hey, I found this, and I wondered if it's an effect... Anyone know how this graph is created?

    Thanks in advance

    Bildschirmfoto 2016-04-19 um 22.18.05.png

    Hello

    Some ideas (illustrator, photoshop):

    Writer III

    http://www.AlphaPlugins.com/products/products.php?menu=get_prod_id&prod_id=2

    Free effect action Illustration engraved for Photoshop

    oshop http://blog.spoongraphics.co.uk/Freebies/Free-Engraved-illustration-Effect-Action-for-phot

    https://www.YouTube.com/watch?v=-tNKVwJmjY0

    https://Dribbble.com/shots/1878287-engraved-effect-Photoshop-action

    Stone

  • How you report results by e-mail - 8 Captivate quiz?

    How you report results by e-mail - 8 Captivate quiz?

    More info...

    .. .on the send results by e-mail?

    I know not glib, but there are essentially two approaches:

    1 figure how do a "mailto:" link that passes the information you need (partitions, etc.) to the user's email client.

    Problem A: users will need TO have a client installed messaging, like Outlook, Thunderbird, etc.

    B problem: users will see that email content, editing and will have to manually click 'send '.

    2 set up a program of mailer on a Web server that your Captivate project can 'POST' the data to.

    Problem: you need a Web server, a program of mailer and a page that will receive the posted data (PHP, JSP, ASP, .NET)

    B problem: you will need some kind of security around this script mailer or spammers surely find and use it to send their own spam stuff.

    Do you REALLY need to send by e-mail?

    May be preferable to an internal server.

    http://blogs.Adobe.com/Captivate/2010/08/reporting-the-quiz-results-to-a-local-server.html

    (this is old, 2014, but gets the idea across)

  • How triggers can be created in the table?

    Hi all
    How triggers can be created in the table?
    is 12 or as far as we can?

    There is no technical limit to the number of triggers you set (or, at least, not one that any rational person has never touched). He usually would not make sense to have more than one trigger of a given type on a particular table, even if you can come up with situations where you can have multiple triggers of the same type on a single table.

    Normally, when people ask this question, it is because someone (foolishly) he asked in an interview. Frequently, the interviewer is trying to determine if you know how many types of triggers there is no if you know if there are some esoteric limit on the number of triggers.

    Justin

Maybe you are looking for