PL/SQL returning a Sql query in a report form

I am producing a simple form to display the number of non-conforming items produced per shift. I use some PL/SQL code to generate the appropriate start and end dates for the shift then build up a query to return.
I am having problems when I use a date mask (DD-MM-YYYY HH24:MI:SS), the :MI section of the date mask is seen as bound variables. If I restrict the time to HH24 without minutes or seconds, it works fine.
Does anyone have any thoughts on how to overcome this problem?

This is the code I am using. As the shifts actually starts at 07:15 and 19:15, I need to add the minutes for it to be correct but they fail.
DECLARE
startDateStr VARCHAR2(25);
endDateStr VARCHAR2(25);
midniteStr VARCHAR2(25);
sqlQuery VARCHAR(1000);
BEGIN
-- Set up the start and end dates
startDateStr := to_char(sysdate, 'DD-MON-YYYY') || ' 07:15:00';
endDateStr := to_char(sysdate, 'DD-MON-YYYY') || ' 19:15:00';
midniteStr := to_char(sysdate, 'DD-MON-YYYY') || ' 00:00:01';
if (sysdate > to_date(startDateStr, 'DD-MON-YYYY HH24:MI:SS')
and sysdate < to_date(endDateStr, 'DD-MON-YYYY HH24:MI:SS'))
then
startDateStr := to_char(sysdate, 'DD-MON-YYYY') || ' 07';
endDateStr := to_char(sysdate, 'DD-MON-YYYY') || ' 19';
else
if (sysdate > to_date(midniteStr, 'DD-MON-YYYY HH24:MI:SS')
and sysdate < to_date(startDateStr, 'DD-MON-YYYY HH24:MI:SS'))
then
startDateStr := to_char(sysdate - 1,'DD-MON-YYYY') || ' 19';
endDateStr := to_char(sysdate, 'DD-MON-YYYY') || ' 07';
else
startDateStr := to_char(sysdate, 'DD-MON-YYYY') || ' 19';
endDateStr := to_char(sysdate+1, 'DD-MON-YYYY') || ' 07';
end if;
end if;
sqlQuery := 'select count(*), defectsource_s, disposition_s
from [email protected] ncr
where creationdate_t > to_date('
|| q'#'#' || startDateStr ||
q'#', 'DD-MON-YYYY HH24')
and creationdate_t <= to_date('#' || endDateStr ||
q'#', 'DD-MON-YYYY HH24')
and disposition_s in ('Scrap', 'Rework'#' ||
') group by defectsource_s, disposition_s
order by disposition_s, defectsource_s;' ;
return sqlQuery;
END;

Similar Messages

  • See sql query from crystal report without crystal report

    see sql query from crystal report without crystal report 

    Hi,
    Depends on datasource type but you could have a look at ODBC trace or if you have access to the SQL Server you could use profiler to monitor the session.
    Regards,
    Craig
    And this will only be of use if you know which Server/Insstance/Database the Report is connecting to...
    Please click "Mark As Answer" if my post helped. Tony C.

  • How to enable show SQL Query in Crystal report tool

    Hi,
    How can we enable the show SQL Query under Database tab in crystal report...
    We have a requirement to modify the SQL query in Crystal reports.
    Thanks,
    Gana

    Gana,
    CR has an "Add Command" feature that will allow you to use hand-coded SQL as your data source.
    Look at Defining an SQL Command in CR's online help (F1).
    If a command was used in the original report creation, it's a simple matter to go in and edit that SQL.
    If the report was not originally built w/ a Command you may find it difficult to switch over. In most cases it easier to start over from scratch, creating a new, blank report, that uses the command.
    Jason

  • Modify SQL query in Crystal Reports 2013

    Bonjour,
    Je voulais savoir s'il était possible de modifier la requête SQL dans Crystal Reports 2013, car les bases de données de notre application pour bibliothèque utilise un format de date particulier qu'il nous faut corriger directement dans la requête SQL.
    Merci pour vos informations.
    Cordialement
    Claude Marcilly
    Cannes - France
    Hello,
    I wanted to know if it was possible to modify the SQL query in Crystal Reports 2013. Databases of our application library indeed use a particular date format that we need to fix directly into the SQL query.
    Thank you for your information.
    Best regards
    Claude Marcilly
    Cannes - France

    Hi Claude,
    If you are creating reports using tables then go in Database menu and click on show SQL query, this will show the SQL generated by crystal reports.  Now go in database expert and expend your connection and double click on Add Command and past the query which was generated by Crystal and try to modify the date format and click OK.
    Now you need to redesign your reports based on Add command.
    or
    If your reports datasource is Add command you can directly go in add command and change it.
    -Sastry

  • How to use SQL Query in OBIEE Reports

    Hi all,
    I need to use direct sql query in report function column.. How can I implement that.
    For example
    Our report name is /shared/Automotive/Vehicle Services/Most Serviced Vehicle Models
    we have to eliminate /shared/Automotive/Vehicle Services/ part from above report name.. I have done this in sql using the Query SUBSTR(COL,INSTR(COL,'/',1,4)+1).
    So kindly help how to implement above sql query in Obiee.. Urgent.
    Thanx in advance

    796797 wrote:
    Hi all,
    I need to use direct sql query in report function column.. How can I implement that.
    For example
    Our report name is /shared/Automotive/Vehicle Services/Most Serviced Vehicle Models
    we have to eliminate /shared/Automotive/Vehicle Services/ part from above report name.. I have done this in sql using the Query SUBSTR(COL,INSTR(COL,'/',1,4)+1).
    So kindly help how to implement above sql query in Obiee.. Urgent.
    Thanx in advanceArrggh. I wish people wouldn't just answer a question without taking the time to actually think about what the user is asking for and if it makes sense. I like Diney's response best: Why not use the Title View? (i.e., asking questions until it is clear what is needed.) So along those lines, why are you trying to put the name of your report in a column of your report?? And why do you need to use direct sql to do this??
    Kindly or not, urgent or not, state what you are trying to achieve and why you need it (if the obvious answer like "using the Title View" doesn't work for you), instead of simply assuming your method is right and you need to know how to do what envision. Your method may not be correct or necessary.

  • Access APEX_APPLICATION.G_F01 in an SQL query for a report

    APEX 4.0.2.00.07
    I've got a standard report with checkboxes. The SQL is along the lines of:
    SELECT APEX_ITEM.CHECKBOX(1,empno,'CHECKED') " ",
           ename,
           job
    FROM   empThen I have another report below this, which I want to drive based on the items checked in the first report. I know that the checkbox values will go into the APEX_APPLICATION.G_F01 collection. Normally these are accessed using pl/sql such as:
    FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
        DELETE FROM emp WHERE empno = to_number(APEX_APPLICATION.G_F01(i));
    END LOOP;But is there any way I can access the collection from the sql for my second report.
    i.e. I want my sql to be something like:
    SELECT empno, day_of_service
    FROM   emp_timesheet
    WHERE emp_no in <get access to the collection here>I was hoping that the check box collection would be available from the APEX_COLLECTIONS view, but it doesn't seem to be there.
    Thanks,
    John

    John,
    If the goal is to hold onto the checked values for some other processing then you could add them to a collection yourself.
    create a process on your page which looks something like this:
    This will create your collection if it does not exist or delete everything currently in it if it does exist and then insert your new selections.
    DECLARE
       l_col_name varchar2(30) := 'EMP_SELECTED';
    BEGIN
        apex_collection.create_or_truncate_collection(l_col_name);
        FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
            apex_collection.add_member(
                l_col_name,
                to_number(APEX_APPLICATION.G_F01(i))
        END LOOP;
    END;your second query could look something like this:
    SELECT empno, day_of_service
      FROM emp_timesheet
    WHERE empno in (select C001 empno
                       from apex_collections ac
                      where ac.collection_name = 'EMP_SELECTED')
    Edit
    some people choose to create a view ontop of certain collection queries which will be reapeated throughout the application so you could also just
    create view selected_emps as
    select C001 empno
      from apex_collections ac
    where ac.collection_name = 'EMP_SELECTED'   and your new query would look like:
    SELECT empno, day_of_service
      FROM emp_timesheet
    WHERE empno in (select empno
                       from selected_emps)Cheers,
    Tyson Jouglet
    Edited by: Tyson Jouglet on Apr 6, 2011 10:37 AM

  • Where clause in sql query for updateable report

    Why is the following not working as source for an updateable report ?
    select customer_name from temp_customers
    where customer_type = :my_field;
    How can I make a filter for an updateable report that is based on a field on my page ?
    Greetings Bernd

    Howard,
    The htmldb_item API package allows you to display column values in a report as HTML form fields. You have a choice of different types of form fields. In your example for instance you get a select list by using the function select_list_from_lov. But by simply placing form fields in an HTML page, you don't specify that those fields are actually supposed to update data in a database. You need an after submit process that is actually performing the update.
    You can implement this type of process manually using your own PL/SQL code. Or you can have HTML DB do this for you. If for example you were using the tabular form wizard, you would get an updateable report, including the update process and even including checksum functionality to make sure that you don't overwrite another person's changes (lost update detection).
    If you use the wizard, the report form items use the build-in display types. This means you don't have to do your own calls to htmldb_item as part of your query. It is generally advisable to use the build-in types as they are easier to work with and are only rendered for the rows actually shown as opposed to be rendered for the entire result set.
    If you do choose to use htmldb_item, you'll have to code your own PL/SQL code to perform the updates and you should also include some logic for lost update detection. The HTML DB documentation provides information on how to manually process data from tabular forms.
    Hope this clarifies your question about updateable reports,
    Regards,
    Marc

  • Executing a column which has a sql query in a tabular form

    Hi,
    I have a tabular form which contains a column named as SQL which has sql statements in it. Without going to the SQL workshop in Apex i want to execute that query in the tabular form itself. For that i've created a page item which fetches the particular rows sql query and created a button 'EXECUTE'. When i click the execute button it should run the query and should display whether the query is correct or not and should show the error message.
    Can any one provide solution for this or whether there are any other ways to achive this scenario.
    With Regards
    Balaji.P.K

    Balaji P.K wrote:
    Can any one provide solution for this or whether there are any other ways to achive this scenario.Difficult as we have no idea what this "scenario" actually is. Go back several steps and explain in detail the problem this is supposed to solve.
    I have a tabular form which contains a column named as SQLBad idea. <tt>SQL</tt> is a PL/SQL reserved word. Using any token from Oracle namespaces as a database identifier is confusing/problematic.
    which has sql statements in it.Why? Where does this SQL come from? What is the source of the tabular form?
    Without going to the SQL workshop in Apex i want to execute that query in the tabular form itself.Explain the "execute that query in the tabular form itself" concept. Where do the results go?

  • Using SQL Query Values as Report Parameters

    Why can I not use a page item to pass a value to a report when that page item is populated by a SQL query? If the item is populated as a database item, it can be passed, but not otherwise. Is there a way to work around this problem so that I can pass parameters to a report?

    Hi, Jeff
    Thanks for asking about this problem. This issue involves two tables mainly and others peripherally. I have a person table with borrower names and addresses, and each record in this table has an identifier in a column called IDENT. There is also a loan table with essential data on the loan, e.g.., loan identifier (DKTNR), the amount, interest rate, maturity date, etc., and also the IDENT linking to the person table. The borrower can be identified from any table that has the DKTNR in it by querying the borrower's name from the person table via the IDENT in the loan table. E.g., select borrower's name from loan_table, person_table where loan_table.ident = person_table.ident and the dktnr here equals the dktnr in the loan table.
    I put the borrower's name on each APEX page using this query. I have one table, for example, which stores default accountings (i.e., accountings on loans that have defaulted and, generally, on which the lender has had to expend money to maintain the loan's maritine collateral). The records in this table are identified by the DKTNR. So on the reports page which shows this accounting, there is a non-database_column field (page item) populated via this query. If I want to use the value of this page item on an Oracle report that can be printed, I cannot do so. I place it into a variable (I forgot the name of the variable type, but it is the &PX_ITEM_NAME. type) in the URL which calls the report, but it will not be placed in the report. It is as if I have put a null value into the variable.
    Ideas?

  • Passing SQL query at runtime - Report

    Hi,
    There is some way to pass a sql query at runtime from a Form to report? I need to set some report object property?
    Thanks
    Sandro

    You can pass the parameter same as you pass the other parameters. Define a variable that will hold the Query and then pass that parameter from form to report.
    Regards,
    Eric.

  • Show the SQL query on the report itself

    I'd like to show the entire SQL query in print at the end of a report, say in the Report Footer section so that the user could review it let me know what edits are needed to meet their needs.  Thanks

    Since the query itself doesn't really change (except for parameter values passed to selection criteria), you can just open the Show SQL Query and paste it into a text box.
    Beyond that, there isn't a way to add via a "Special Field".
    HTH,
    Jason

  • Finding sql query in statspack report

    Hi;
    I have 11.5.10.2 and db version is 9iR2.. i took one statspack report and i should find one sql query... But admin is kill session and i cant see complite query under SQL ordered by Gets for DB...
    so the question is can i find this query whihc is kiiled by admin?
    thanks

    Hi,
    Its bad news to cant find this sql.. If normaly it istn killed by admin, i could find it from stats$sql_summary or v$sql_text??It is possible.
    Note: 153507.1 - Oracle Applications and StatsPack
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=153507.1
    And one other question... If i suspect from one sql is eating my cpu or my server resource, how i can find this sql? Under which title i can find in statspack reportRefer to:
    Note: 232443.1 - How to Identify Resource Intensive SQL for Tuning
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=232443.1
    Regards,
    Hussein

  • Complete novice needs help getting SQL Query into Crystal Reports XI

    Post Author: MissMarnie
    CA Forum: Data Connectivity and SQL
    So I was given an intro level web course and a monster reference guide in prep to format a report. One of our developers wrote me everything I need for the report into a SQL Query and now I'm supposed to format it in CR XII literally do not know what to do from here. I'm able to set up the correct server as a datasource, if that's useful, but I don't know how to make the querey into a bunch of formattable fields in  CR. If anyone can walk me through this, I'd be so grateful. I've attempted to look up SQL query in both the help and the book but I keep hitting a wall. The help dialog says things like "press this button" with no reference to what "this button" is. I'm sure it's obvious to the knowledgeable but I'm in a complete fog. Thanks in advance   

    Post Author: synapsevampire
    CA Forum: Data Connectivity and SQL
    IF you're trying to get assistance with setting up a query as the source for a report, try posting your Crystal version and the database type.
    Different software works differently.
    In CR 9 and above, under the connection to the database you'll see Add Command. Select that and you can paste the query in.
    As for not knowing how to generate a report, that requires experience, there's no generic solution of course..
    -k

  • Giving SQL query in jasper reports

    hi
    can i execute sql query via ireports scriptlets

    yes u can do just like u r doing in java programs

  • Display records returned for a query in the Report Region Title

    Hi,
    Is there any variable set that can be referenced to indicate how many records have been returned for a specific query. I have several hide/show regions dealing with various reports, and I would like to add a little info into the region title to display how many records there were returned for the report in this region.
    Thx in Advance,
    cliff

    Hi,
    addendum
    These are simple sql queries BTW. I've seen posts alluding to the SQL%ROWCOUNT when using cursors. Is there any variable we can reference when using a simple sql query?
    thx
    cliff

Maybe you are looking for

  • Why can't I find my external hard drive?

    After installing Maverick I can't get my external back-up  hard drive (LaCie) to load. Any suggestions?

  • My Story, what should be my next steps?

    I have been working for a pharmaceutical company for nearly 2 years in a transport/inventory control role. My company was in the middle of an integration project (take over from a larger company) when I arrived, immediately I was thrown into the worl

  • Service products  saritha reddy

    Hi I am trying to work with service products. I created service products, in CRM standalone and trying to create number for product . Its saying that  no group is available . Can  anyone tell me how to create numbering for service product.  I know ho

  • Change in BOM tracking

    Hi, Is there any report available which can give various changes occurred in BOM. How we can track the changes in BOM. In BOM always last change is update but to track various changes for particular period say last 6 months, is there any report or me

  • Cropping the physical frame of the clip?

    Hey. So, I recently got iMovie 08, only to realise that it didn't have half the features of HD 6. So I swapped the software (having to edit everything again, grr). Thing is, now I discover that 08 has a feature that I can't find anywhere on HD 6, and