PL/SQL Ad-hoc Reporting Implementation Questions

Recently, I have been put on a development team that is developing a small reporting module for one of our applications.
I'm trying to mask the underlying structure from the application by having the application run PL/SQL procedures which return REF CURSORS to the client with the requested data. Right now I'm struggling with how to implement the PL/SQL in the best fashion.
Since this is a reporting tool the user has many combinations of selections. For example at a high level this application has a combination of multiple dropdowns (4-6), radio buttons, and check boxes. As you can see this results in a high amount of possible combinations that have to be sent to the database.
Basically, the user chooses the following:
1. Columns to receive (ie different SELECT lists in the PL/SQL)
2. Specific conditions (ie different WHERE clauses in the PL/SQL)
3. Aggregate functions (SUMS, TOTALS, AVERAGES based on #1 and #2)
4. Trends based on #3.
So... with that said I see two possibilities:
1. Create a static query for each combination of parameters (in this case that would most likely result in at least 300 queries that would have to be written, possibly 600+).
The problem I see with this is that I will have to write a significant amount of queries. This is a lot of front end work that, while is tedious, could result in a better performing system because it would be a parse once, execute many scenario which is scalable.
The downside though is that if any of the underlying structure changes I have to go through and change tens of queries.
2. Use DBMS_SQL and dynamically generate the queries based on input conditions.
This approach (possibly) sacrifices performance (parse once, execute once situation), but has increased maintainability because it is more likely that I'll have to make one change vice a number of changes in scenario 1.
A downside to this is that, it may be harder to debug (and hence maintain) because the SQL is generated on the fly.
My questions to all is:
1. Which is the approach that would best manage maintainability / performance?
2. Is there any other approaches to using PL/SQL as a reporting tool that I am not thinking of?
The database is 10.2.0.3, and the 'application' is PHP 5.1 running on IIS 6.
If you need me to provide any additional information please let me know.
Thanks!

Ref cursors are an ugly solution (different though in 11g).
You build a dynamic SQL. It must/should have bind variables. But a ref cursor does not allow you to dynamically bind values to bind variables. You need to code the actual bind variables into the code as part of the open cursor command. And at coding time you have no idea how many bind variables there will be in that dynamic SQL for the ref cursor.
The proper solution is DBMS_SQL as it allows exactly this. Also one of the reasons why APEX uses this for its report queries.
The only sensible way to implement this type of thing in PL/SQL is by not trying to make it generic (as one could with DBMS_SQL). Instead use polymorphisms and have each procedure construct the appropriate ref cursor with bind variables.
E.g.
SQL> create or replace package query as
2 procedure Emp( c in out sys_refcursor );
3 procedure Emp( c in out sys_refcursor, nameLike varchar2 );
4 procedure EMp( c in out sys_refcursor, deptID number );
5 end;
6 /
Package created.
SQL>
SQL> create or replace package body query as
2
3 procedure Emp( c in out sys_refcursor ) is
4 begin
5 open c for select * from emp order by 1;
6 end;
7
8 procedure Emp( c in out sys_refcursor, nameLike varchar2 ) is
9 begin
10 open c for select * from emp where ename like nameLike order by 1;
11 end;
12
13 procedure EMp( c in out sys_refcursor, deptID number ) is
14 begin
15 open c for select * from emp where deptno = deptID order by sal;
16 end;
17 end;
18 /
Package body created.
SQL>
SQL> var c refcursor
SQL> exec query.Emp( :c, 'S%' )
PL/SQL procedure successfully completed.
SQL>
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
SQL>

Similar Messages

  • How to do Ad-hoc reports with SSRS 2012 (Report Builder 3.0) for the database SQL Server 2012

    <p>Hi,</p><p>Please could anybody help me how to do ad-hoc reports by using SSRS 2012.</p><p>I am able to create ad-hoc reports using Report Builder3.0 and SQL Server 2008 R2. </p><p>I have built the report Model
    in for the instance 2008 R2&nbsp;</p><div class="t-paste-container">Using Report Manager 2012 </div>

    Hi Gowri,
    From your description, you can create create ad-hoc reports using Report Builder 3.0 and SQL Server 2008 R2, and now you want to know how to how to do ad-hoc reports by using SSRS 2012, right? In SQL Server 2012, the default version of Report Builder is
    3.0, so you can create create ad-hoc reports using Report Builder 3.0 as before.
    If you have any questions, please feel free to ask.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Generic ad-Hoc report tool like Database Browser

    1) Are there any plans for making the Database Browser functionality in the SQL Workshop reusable in HTML DB applications? I am in the very beginning stages of building a generic ad-hoc report page in HTML DB. What I mean by this is the user can select a table from a restricted list of tables, select columns from that table, and execute the query. This is all I have working at this point. I will add other features obviously like WHERE clause criteria, results ordering, column ordering, and saving query in database for future use. I was wondering if this could be accomplished by utilizing the Application Builder's Database Browser without having to give the users developer access, all but the saving the query to the database of course.
    2) Has anyone else built a generic ad-hoc query type tool in HTML DB? If so, what type of functionality did you implement or not implement? I am also interested in what measures had to be taken to prevent SQL Injection.
    3) Is there much interest out there for an HTML DB ad-hoc query report tool that could be incorporated into an HTML DB application?

    Hi Scott,
    There's definately interest. I have 30 data tables (and 17 lookups), and the users will need the ability to query any column in any (data) table, and maintain the parent-child relationships to build up all of the where clauses.
    I've downloaded you QBE and Quick QBE, and have a couple questions/comments/problems.
    With QBE, I try to add it with the Upload Script feature, and it keeps dying on me with "Error: ORA-20000: Unable to get the block of code: ORA-06502: PL/SQL: numeric or value error: character string buffer too small" message.
    With Quick QBE, in the readme.txt file, under "Definition of Each File", you refer to code.sql and quick_qbe.sql. Under "Order of Execution", you refer you code.sql and people.sql. And then in the zip file, you have ddl.sql and quick_qbe.sql. It gets a little confusing. :^)
    Anyway, thanks.
    Bill Ferguson

  • SAP NetWeaver BI with Microsoft SQL Server 2012 Reporting Services using XMLA

    I am currently implementing SAP BW and am trying to connect the Microsoft SQL Server 2012 Reporting Services product.  I am able to connect to SAP BW but there is one problem when i click on Query Designer after adding a DataSet the screen just displays the dialog prompt saying '' NO CUBES WERE FOUND. VERIFY THAT YOU HAVE SELECTED A VALID CATALOG''.
    The advanced information depicts the following:

    Hi Raunak T,
    Just a very basic question from my end:
    I believe that "Microsoft SQL server Report Builder" is the 3rd party which uses MDX as interface.
    Have you set the property using OLE DB for OLAP in your queries?
    BR
    Prabhith

  • SQL Query (updateable report) Region - Conditionally Hide and Set Values

    SQL Query (updateable report) Region - Conditionally Hide and Set Values
    Outline of requirement :-
    Master / Detail page with Detail updated on same page using SQL Query (updateable report).
    The detail region has the following source
    SELECT item_id,
           contract_id,
           CASE WHEN hardware_id IS NOT NULL THEN
                   'HA'
                WHEN backup_dev_id IS NOT NULL THEN
                   'BD'
                WHEN hardware_os_id IS NOT NULL THEN
                   'HS'
           END item_type,
           hardware_id,
           backup_dev_id,
           hardware_os_id
    FROM   "#OWNER#".support_items
    WHERE  contract_id = :P26_CONTRACT_IDThe table support_items implements arced relationships and has the following columns
    CREATE TABLE SUPPORT_ITEMS
      ITEM_ID         NUMBER                        NOT NULL,
      CONTRACT_ID     NUMBER                        NOT NULL,
      HARDWARE_ID     NUMBER,
      BACKUP_DEV_ID   NUMBER,
      HARDWARE_OS_ID  NUMBER
    )A check type constaint on support_items ensures that only one of the fk's is present.
          (    hardware_id    IS NOT NULL
           AND backup_dev_id  IS NULL
           AND hardware_os_id IS NULL
    OR    (    hardware_id    IS NULL
           AND backup_dev_id  IS NOT NULL
           AND hardware_os_id IS NULL
    OR    (    hardware_id    IS NULL
           AND backup_dev_id  IS NULL
           AND hardware_os_id IS NOT NULL
          )    Hardware_Id is a FK to Hardware_Assets
    Backup_dev_id is a FK to Backup_Devices
    Hardware_os_id is a FK to Hardware_op_systems
    The Tabular Form Element based on item_type column of SQL query is Displayed As Select List (based on LOV) referencing a named list of values which have the following properties
    Display Value     Return Value
    Hardware Asset    HA
    Backup Device     BD
    Computer System   HSThe Tabular Form Elements for the report attributes for hardware_id, backup_dev_id and hardware_os_id are all Displayed As Select List (Based on LOV).
    What I want to do is only display the Select List for the FK depending on the value of the Select List on Item Type, e.g.
    Item_Type is 'HA' then display Select List for hardware_id, do not display and set to NULL the Select Lists for backup_dev_id and hardware_os_id.
    Item_Type is 'BB' then display Select List for backup_dev_id, do not display and set to NULL the Select Lists for hardware_id and hardware_os_id.
    Item_Type is 'HS' then display Select List for hardware_os_id, do not display and set to NULL the Select Lists backup_dev_id and hardware_id.
    There are properties on elements to conditionally display it but how do we reference the values of the SQL query Updateable region? they are not given a page item name?
    Also on the Tabular For Elements there is an Edit tick against a report item - however when you go to the Column Attributes there is not a property with which you can control the Edit setting.
    What's the best way of implementing this requirement in APEX 3.1?
    Thanks.

    >
    Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "user13515136".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I have a multi-row region that displays values and allows entries in a number of fields.Provide exact details of how this has been implemented. (An example on apex.oracle.com is always a good way to do this.)
    I should like the fields to be conditional in that they do not permit entry, but still display, if certain conditions apply (e.g. older rows greyed out). Can this be done? Almost anything can be done, often in multiple ways. Which are appropriate may be dependent on a particular implementation, the skills available to implement it, and the effort you're willing to expend on it. Hence it's necessary to provide full details of what you've done so far...

  • Update Field On Change For A SQL Query (updateable report)

    Hi,
    I'd like to request help from anyone with ideas on how to solve this.
    We are using APEX 4.2, 10GR2, RedHat5.
    I have a report that comes from SQL Query (updateable report).
    I'm using the apex_item.text and apex_item.hidden on fields.
    I'm using a button to submit and after submit process to add some logic that I need.
    There could be 1 - 10 records in the report.
    There is only 1 field that is needed to enter a value, but the value of this field determines the value of another field.
    I think that I can do this with a submit button and an after submit process where I loop through all the records. I think I have this handled.
    This is the question
    When the value of that field is changed then the value of another field in the same row changes immediately.
    Is this possible?
    All the examples I've seen so far are for a single record and that doesn't work for us.
    I guess this is a MRU process but I haven't seen an example where a dynamic action is possible on a Multi Row Update.
    Could anyone direct me to where I can see an example or help me get directions?
    I appreciate all your help an comments and I thank you in advance.

    Yes why not...what you looking for is a ajax call
    See {message:id=10390979}
    Please note:-you can also do this as a dynamic action as shown below
    Event: Change
    Selection type: jQuery Selector
    jQuery Selector: input[name="f01"]
    True action with Execute JavaScript Code and put all code inside the test funtion, you may need to amend the code to use this.triggeringElemnt in place of this

  • How to write SQL in crystal report that can reuse SQL execution plan cache?

    I write the following SQL with crystal report parameter fields, and it is connecting to SQL 2005
    Select Name from Customer where CustID = '{?CustID}'
    The SQL profiler show that It is an ad-hoc query, how to write parameterized SQL which can reuse Execution Plan.
    Edited by: Chan Yue Wah on May 14, 2009 3:17 AM

    Since there are too many report, it is not possible rewrite all. Is that crystal report do not have option to change how it query the database ?

  • Generating Dynamic Query for Ad-Hoc Reports

    Hello,
    What is the best way to create a dynamic query to generate ad-hoc reports? I have a couple of ideas but not sure which would work best and be most flexible.
    I would like our users to be able to check checkboxes for what data they would like returned in their report. The data would be pulled from a number of tables, 10+, depending on what pieces of data they checked.
    Should I write one dynamic query, with a bunch of IF statements in it?
    Should I write many individual queries and then join them together in a temp query?
    Should I create a temp table on our SQL server which contains the data from all of the tables; then query that? (I am worried about data being out-of-date with this option.)
    Which one of these solutions should I go with or is there a better solution that I am not considering?
    Thanks for the help.
    Josh

    Do you mean a Stored Procedure? Would the Stored Procedure then have one query on it with a bunch if IF statements? Maybe a bad example, but something like this?
    Yep.
    I haven't written a proc for a coupla years (I have DB people to do that for me now, bless 'em), but every DB is different, so the approach will vary depending on what DB you have.  It's perhaps time to buy a book or do a google or something.
    Adam

  • Sql Query(Updateable Report) with pagination

    Hi,
    We're on APEX 3.2 I have a question on Sql Query(Updateable Report) and pagination. I have an updateable report which we have set to show 20 rows. When the userwhi has more than 20 rows enters the data and clicks next the data disappears. I have been reviewing other posts, but haven't come to a clear conclusion on how to prevent this from happening. I have been trying to use javascript to show a save popup when clicking 'Next' Any help is appreciated.
    Thanks,
    Joe

    any ideas?

  • Share Data Source between multiple report projects in Microsoft SQL Server 2012 Reporting Services

    I have a reports solution in 2012 which contains multiple report projects one each for target deployment folder and we use TFS 2012 for report deployment.
    We have a template project which has a bunch of template reports and all the datasources used in different reports.
    When I develop a report, I cannot "Preview" in TFS but, for deploy this used to work fine util the reports solution was in TFS 2010 & Visual Studio 2008 R2. Since we moved to TFS 2012 & SSRS 2012 not being able to deploy till I create all
    the necessary datasources for each project and now all the developers complaining that they cannot develop reports in TFS itself as they cannot preview (this problem was existing previously) and now not being able to deploy as it errors for each report "Could
    not find specified rds file". I tried messing around with the .rptproj file DataSources tag that did not help either by modifying it like below.
    <DataSources>
    <ProjectItem>
    <Name>DB.rds</Name>
    <FullPath>Template\Data Source\DB.rds</FullPath>
    </ProjectItem>
    </DataSources>
    Is there a way I could share a Data Source between multiple projects in Microsoft SQL Server 2012 Reporting Services?
    Thanks in advance.............
    Ione

    Hi ione721,
    According to your description, you want to create a shared data source which works for multiple projects. Right?
    In Reporting Services, A shared data source is a set of data source connection properties that can be referenced by multiple reports, models, and data-driven subscriptions that run on a Reporting Services report server. It must be within one project.
    We can't specify one data source working for multple projects. In this scenario, we suggest you put those reports into one project. Otherwise you can only create one data source for each project.
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • SQL Server 2012 Reporting Services, Report Manager - Page not found

    Hi all,
    I am working on migrating reports to a new server so we can upgrade to a new machine and to SQL Server 2012 SP2.  The machine is up and running on Windows Server 2012 and I have installed SQL Server EE 2012 SP2.  I have imported the three databases
    from 2008R2
    * Report Server
    * ReportServer TempDB
    * RSSubscribers
    I have re-applied the encryption keys and I was thinking that everything was good to go until I went to try and manage the subscriptions on a report.  I select a report, use the drop arrow to get to manage
    and then try to select any of the options such as subscriptions and I get a "Page Not Found Error"
    If I take the URL and paste it in another browser, putting the previous server name in, it works fine.  So, the URL works fine...  I have no idea as to what I should do to figure out the problem.  I am considering rebuilding the whole install
    just to see if that would fix it.
    Thanks

    Hi SqlDude,
    According to your description, you have bind SSL to a Reporting Services URL Reservation. Now you find in your Report Manager, the Subscription page still start with "http://". Right?
    In this scenario, we need to change setting in rsreportserver.config file. Go to rsreportserver.config in "\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportServer". Find <Add Key="SecureConnectionLevel" Value="0"/>.
    Change the value into "3".
    Acceptable values are: 
    3 Most secure—Use SSL for absolutely everything.
    2 Secure—Use SSL for rendering and methods that pass credentials but don't insist on it for all SOAP calls.
    1 Basic Security—Accepts http but rejects any calls that might be involved in the passing of credentials.
    0 Least Secure—Don't use SSL at all.
    Besides, if you want to submit a feedback to Microsoft, please feel free to submit
    your situation on our product to the following link:
    https://connect.microsoft.com/SQLServer/Feedback.
    If you have any other questions, please feel free to ask.
    Regards,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • VCM installation help needed on SQL DB and Reporting server

    Hi All,
    I'm new to VCM and now i got stuck at the SQL DB and Report server portion.
    I'm running the vcm server on VM and the SQL is a physical server, both are sitting on the same LAN.
    I have create the SQL DB but VCM just fail to validate the DB and report server.
    I login to VCM using a Domain account for installation, and i tried to testing the DB using ODBC from the window, result fail.
    Error message as attach.
    I'm now totally lost on SQL portion.
    My Question:
    Is there any configuration needed on SQL DB?
    How to get the reporting server to working?
    What port is needed to it all working??
    VCM server Ms Win2012.
    SQL version 2012.
    Many thanks to all who reply.

    Hi Simonhoo79,
    For SSRS,   first check whether the report server link is accessible from your browser : "http://s01-fes-vcm1:80/ReportServer" . If you continue to get 404 error there also, then you need to reconfigure you report server first before proceeding to vcm installation. Follow the steps on below link on how to reconfigure report server using report services configuration Manager for 404 error.
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/75910bcb-a879-4eb7-9757-acc45201fa3a/can-not-connect-to-reportserver-http-404-file-not-found?forum=sqlexpress
    For SQL server ODBC connection,
    Dont create ODBC connection for SQL Native Client. Create ODBC connection for SQL Server.
    1. Open ODBC Data Source Administrator
    2. Click User DSN tab and Click Add button.
    3. Select SQL server and click finish
    4. Give name and description and Give the SQL server name (with instance name if your using named instance) or IP in the Server text box.
    5. Click Next and select either Windows authentication or sql authentication based on your SQL server authentication mode and click next.
    6. If the details given are correct then it will proceed further and  check "Change the dafault database to" to your VCM database
    7. Click next and finish and try test data source.
    VCM 5.7.2 and below will support installation only on windows server 2008 R2  and it doesn't support windows server 2012  but it support both 2008 and 2012 sql servers.

  • Sql server 2012 reports

    If i develope reports using SQL server 2012 reporting services, can i upload the reports on SQL server 2005 report server and SQL server 2008 Report server ??
    h2007

    Generally
    higher to lower deployment is not supported.
    Try to change the properties of the ReportServer Project in Visual Studio and set the target server version as mentioned in below thread.
    http://stackoverflow.com/questions/13798289/reporting-services-built-in-2012-deploy-in-2008
    Please click the Mark as answer button and vote as helpful if this reply solves your problem

  • SQL SERVER 2000 - REPORTING SERVICES DATABASE ?

    Hi!
    A very basic question, how to know where reporting services points to the database and server ?
    miga

    For versions above than SQL 2000, you can refer to sql reporting services configuration tool.
    For SQL server 2000, reporting services view the database deatils as mentioned in below thread
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e4263367-600d-4bb1-94e7-6b66e5df295d/how-do-i-find-configuration-details-on-sql-server-2000-ssrs?forum=sqlreportingservices
    To find the SQL Server name that host the report server database, please check the server name of the “ReportServerURL” in the RSWebApplication configuration file. The configuration file is located in the following folder:
    <drive>:\Program Files\Microsoft SQL Server\MSSQL\Reporting Services\ReportManager
    By default, the report server database name is ReportServerDB, and the report server temporary database name is ReportServerTempDB. To check the report server database name the SSRS 2000 uses currently, we can try to join a report server
    instance to a Web farm by using different database. If the target database is not validated during the setup, it cannot be the report server database. Besides, we can also expand the tables of the databases; a report server database has different tables with
    common databases.
    For more information, please see:
    RSWebApplication Configuration File
    Installing a Report Server Web Farm
    Please click the Mark as answer button and vote as helpful if this reply solves your problem

  • Validation of a Region defined as type SQL QUERY (Updateable Report)

    Hi,
    I am trying to perform some validation on a Region defined as type SQL QUERY (Updateable Report). The report has two columns.
    One of the columns is a Select List and I would like to insure that a user cannot select the same value twice
    in the report. For example, if the select list has 5 values, A, B, C, D, E, I don't want a user to be able to select
    B twice in the report. I am assuming that I will need to incorporate javascript
    into my validation logic in order to perform this task. If so, could someone provide some guidance? Or are there
    other alternatives.
    Thanks in advance,
    Michael

    Dan,
    Sorry, I didn't mean to post the question twice. I was trying to edit my original question. Thanks for the link to the website. I am new to APEX development so the website you gave me will be extremely useful to learn new development techniques.
    Thanks again,
    Michael

Maybe you are looking for

  • Issue with Export To Excel Feature

    Hi, I have a OAFramework Page, which is having a table region. Have also created an 'Export Button' as table action for this table, to export the data to csv file. The View Instance that is associated with this table has a query already set/defined i

  • Develop node.js on Lion, but not install mysql-libmysqlclient

    I am developer, my apple is MacBook Pro MD313CH/A, system is Mac OS X Lion 10.7.3, Xcode 4.3.2, installed Command Line Tools, mysql is 5.5.21. I installed Node.js on MacPorts, node -v 0.6.17, npm -v 1.1.21, I want to install mysql-libmysqlclient(http

  • Boot camp XP on mac Pro with Leopard

    I have tried to load windows xp onto my new Mac Pro. The firmware is up to date. The files load but the startup disk never ejects. The computer says that it is starting up windows, but never enters into the windows start up screen. The computer conti

  • Adobe Media Encoder CS4 crash on startup

    Hello, I've been using and troubleshooting with the help of Adobe forums for quite a few years now (thank you to everyone), but I don't recall actually ever posting anything, as of yet. Problem:  Adobe Media Encoder was working fine yesterday and tod

  • Mount a USB Flash Drive

    I am running a 1998 iMac with a PowerPC Processor. It has MacOS 8.5.1. I have a PNY 2 GB USB Flash Drive. How do I mount this.