How do I query off a pl/sql funtion that returns an sql query in apex.

I built a function that a returns a good sql query. I verified the out put of my function works when I manually entered into the SQL Commands.
Is it possible to build a report off of this query. My attempt failed with the following error.
failed to parse SQL query:
ORA-00933: SQL command not properly ended
I am sure the query generated is correct. Like I mentioned, I was able to use in the sql command succesfully.
Thanks,
Edited by: greich on Nov 21, 2008 10:55 AM

This is the code for my function:
create or replace function f_act_proj_sched (i_facility varchar2, i_date varchar2, i_shift varchar2)
Return varchar2 is
o_query Varchar2 (32000);
BEGIN
-- function that will return the query used in main application
o_query := o_query || 'SELECT act_proj.DESTINATION,';
o_query := o_query || ' act_proj.SHIPPING_DATE,';
o_query := o_query || ' act_proj.SHIFT,';
o_query := o_query || ' act_proj.JOB_CLASS_GROUPING,';
o_query := o_query || ' act_proj."Actual Units",';
o_query := o_query || ' act_proj."Projected Units",';
o_query := o_query || ' act_proj."Actual Hours",';
o_query := o_query || ' act_proj."Projected Hours",';
o_query := o_query || ' NVL (sched."Sched_Hours", 0)';
o_query := o_query || ' "Scheduled Hours"';
o_query := o_query || ' From (SELECT P.DESTINATION,';
o_query := o_query || ' P.SHIPPING_DATE,';
o_query := o_query || ' P.JOB_CLASS_GROUPING,';
o_query := o_query || ' P.SHIFT,';
o_query := o_query || ' NVL (FACILITY_STATS.WORK_UNITS, 0) "Actual Units",';
o_query := o_query || ' NVL (P.WORK_UNITS, 0) "Projected Units",';
o_query := o_query || ' NVL (CASE FACILITY_STATS.JOB_CLASS_GROUPING';
o_query := o_query || ' WHEN ''Backhaul''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Selector''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.selector_goal';
o_query := o_query || ' WHEN ''Common''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Lift''';
o_query := o_query || ' THEN Facility_stats.work_units';
o_query := o_query || ' / Goal_destination_shift.forklift_goal';
o_query := o_query || ' ELSE Facility_stats.work_units';
o_query := o_query || ' END, 0) "Actual Hours",';
o_query := o_query || ' CASE P.JOB_CLASS_GROUPING';
o_query := o_query || ' WHEN ''Backhaul''';
o_query := o_query || ' THEN P.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Selector''';
o_query := o_query || ' THEN P.work_units';
o_query := o_query || ' / Goal_destination_shift.selector_goal';
o_query := o_query || ' WHEN ''Common''';
o_query := o_query || ' THEN P.work_units';
o_query := o_query || ' / Goal_destination_shift.backhauler_goal';
o_query := o_query || ' WHEN ''Lift''';
o_query := o_query || ' THEN P.work_units' ;
o_query := o_query || ' / Goal_destination_shift.forklift_goal';
o_query := o_query || ' ELSE P.work_units';
o_query := o_query || ' END "Projected Hours"';
o_query := o_query || ' FROM STAFFING.FACILITY_STATS,';
o_query := o_query || ' STAFFING.FACILITY_STATS P,';
o_query := o_query || ' STAFFING.GOAL_DESTINATION_SHIFT';
o_query := o_query || ' WHERE (GOAL_DESTINATION_SHIFT.DESTINATION = P.DESTINATION)';
o_query := o_query || ' AND (GOAL_DESTINATION_SHIFT.SHIFT_FLAG = P.SHIFT)';
o_query := o_query || ' AND (FACILITY_STATS.DESTINATION(+) = P.DESTINATION)';
o_query := o_query || ' AND (FACILITY_STATS.SHIPPING_DATE(+) = P.SHIPPING_DATE)';
o_query := o_query || ' AND (FACILITY_STATS.JOB_CLASS_GROUPING(+) = P.JOB_CLASS_GROUPING)';
o_query := o_query || ' AND (FACILITY_STATS.SHIFT(+) = P.SHIFT)';
o_query := o_query || ' AND (P.PROJ_ACTUAL_FLAG = ''P'')';
o_query := o_query || ' AND (FACILITY_STATS.PROJ_ACTUAL_FLAG(+) = ''A'')';
o_query := o_query || ' AND P.DESTINATION = ' || i_facility;
o_query := o_query || ' AND P.SHIPPING_DATE = ' || i_date;
o_query := o_query || ' AND (case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then P.SHIFT';
o_query := o_query || ' Else 1';
o_query := o_query || ' end =';
o_query := o_query || ' case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then to_number(' || i_shift || ')';
o_query := o_query || ' Else 1';
o_query := o_query || ' end)) act_proj,';
o_query := o_query || ' (SELECT Destination,';
o_query := o_query || ' schedule_date,';
o_query := o_query || ' shift,';
o_query := o_query || ' job_class_grouping,';
o_query := o_query || ' SUM ("Sched_Hours") "Sched_Hours"';
o_query := o_query || ' FROM (';
-- Loop to create bucket query
for idx in 1..20 Loop
o_query := o_query || '(SELECT EMP_SCHEDULE.EMPLOYEE_ID,';
o_query := o_query || ' EMP_SCHEDULE.SCHEDULE_DATE,';
o_query := o_query || ' EMP_SCHEDULE.DESTINATION,';
o_query := o_query || ' EMP_SCHEDULE.SHIFT, ';
o_query := o_query || idx || ' "Bucket_number",';
o_query := o_query || ' Bucket' || idx || '_class "bucket class",';
o_query := o_query || ' JOB_CLASS_GROUPING,';
o_query := o_query || ' NVL (EMP_SCHEDULE.BUCKET' || idx || '_SCHED_HRS, 0) "Sched_Hours"';
o_query := o_query || ' FROM STAFFING.EMP_SCHEDULE,';
o_query := o_query || '(SELECT DISTINCT FACILITY_CLASS_BUCKET.JOB_CLASS_GROUPING,';
o_query := o_query || ' FACILITY_CLASS_BUCKET.DESTINATION';
o_query := o_query || ' FROM STAFFING.FACILITY_CLASS_BUCKET';
o_query := o_query || ' WHERE (FACILITY_CLASS_BUCKET.BUCKET_ID = ' || idx || ')) A';
o_query := o_query || ' Where A.Destination = EMP_SCHEDULE.DESTINATION';
o_query := o_query || ' and EMP_SCHEDULE.DESTINATION = ' || i_facility;
o_query := o_query || ' and EMP_SCHEDULE.SCHEDULE_DATE = ' || i_date;
o_query := o_query || ' AND (case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then EMP_SCHEDULE.SHIFT';
o_query := o_query || ' Else 1';
o_query := o_query || ' end =';
o_query := o_query || ' case';
o_query := o_query || ' when to_number(' || i_shift || ') != -1';
o_query := o_query || ' Then to_number(' || i_shift || ')';
o_query := o_query || ' Else 1';
o_query := o_query || ' end))';
if idx < 20
THEN
o_query := o_query || ' UNION ';
Else
o_query := o_query || ')';
End if;
END Loop;
o_query := o_query || ' GROUP BY Destination,';
o_query := o_query || ' schedule_date,';
o_query := o_query || ' shift,';
o_query := o_query || ' job_class_grouping) Sched';
o_query := o_query || ' WHERE (act_proj.DESTINATION = sched.DESTINATION(+))';
o_query := o_query || ' AND (act_proj.SHIPPING_DATE = sched.SCHEDULE_DATE(+))';
o_query := o_query || ' AND (act_proj.SHIFT = sched.SHIFT(+))';
o_query := o_query || ' AND (act_proj.JOB_CLASS_GROUPING = sched.JOB_CLASS_GROUPING(+))';
o_query := o_query || ' ORDER BY SHIFT,';
o_query := o_query || ' job_class_grouping';
Return (o_query);
END;

Similar Messages

  • Analyze: PL/SQL function body returning an SQL query

    I need to obtain the final SQL returned by the PL/SQL function.
    I will be using this final SQL in a procedure.
    Please provide some advise on how to obtain the SQL. I have already looked in the DBMS_SQL package but I am not sure if that is the right place to look into.
    Regards,
    Sumit

    I am trying to modify the export_to_excel package from Denes kubicek to provide me an excel from PL/SQL function body returning an SQL query.
    Here is the simplified PLSQL code in the region source.
    declare
    l2 varchar2(2000) null;
    begin
    l2:= 'Select NAME,ORIGINATED,OWNER,ORIGINATOR,';
    l2:= l2 || 'DESIGNATED_UNIT,SOURCE,';
    l2:= l2 || 'REFERENCE';
    l2:= l2 || ' from MV_DETAILED_DATA';
    return l2;
    end;
    I would like to get the SQL returned from this PLSQL and use it in a procedure to get the Excel.
    As you mentioned earlier "copy the generated query string into an application item". [ +In the PL/SQL function body returning an SQL query, copy the generated query string into an application item. The app item value can then be passed as a parameter value to the procedure+ ]
    I do not know how to dynamically excute this PLSQL in the region source and obtain the returned value in my procedure.
    Best Regard,
    Sumit.

  • How can I turn off the images of avatars that post...

    how can I turn off the images of avatars that post in this forum? they are annoying.

    I think the avatar pictures help a lot to visually tell apart the different users participating. Pictures are way quicker to discern than user names are.
    Do you want them removed because they distract you or you find certain ones disturbing (You can easily flag those to the moderation team)?
    Follow the latest Skype Community News
    ↓ Did my reply answer your question? Accept it as a solution to help others, Thanks. ↓

  • Deploy resulset of PL\SQL function, that returns ANYTABLE%TYPE

    How can deploy resulset of PL\SQL function, that returns ANYTABLE%TYPE in SQL?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by angelrip:
    Hello everyone,
    I've come through the following problem:
    1.- I created an PL/SQL stored procedure which returns a REF CURSOR element, definition looks like this:
    PACKAGE PKG_LISTADOS AS
    TYPE tuplas IS REF CURSOR;
    /* Procedimientos exportados por el paquete */
    PROCEDURE inicializarModuloListados;
    FUNCTION recaudacionUltimoMes(medioPago DEF_MEDIO_PAGO.MEDIO_PAGO%TYPE)
    RETURN tuplas;
    2.- Now I would like to call the stored procedure and retrieve the PL/SQL cursor as a ResultSet Java Object. The code I wrote is this:
    Connection conn;
    XmlDocument paramDef;
    conn=poolMgr.getConnection str_poolDBConnection);
    try
    CallableStatement cstmt=conn.prepareCall("{?=call PKG_LISTADOS.recaudacionUltimoMes(?)}");
    cstmt.registerOutParameter(1, java.sql.Types.OTHER);
    cstmt.setString(2, "MONEDA");
    cstmt.executeQuery();
    ResultSet rs=(ResultSet)cstmt.getObject(1);
    catch(SQLException sqlE)
    3.- However, I can't make it OK, all the time I get the following error:
    SQL Error(17004), java.sql.SQLException: Non valid column type
    May anyone help me with this, thanks in advance:
    Miguel-Angel<HR></BLOCKQUOTE>
    Do something like the following:
    cstmt = conn.prepareCall("{call customer_proc(?, ?)}");
    //Set the first parameter
    cstmt.setInt(1, 40);
    //Register to get the Cursor parameter back from the procedure
    cstmt.registerOutParameter(2, OracleTypes.CURSOR);
    cstmt.execute();
    ResultSet cursor = ((OracleCallableStatement)cstmt).getCursor(2);
    while(cursor.next())
    System.out.println("CUSTOMER NAME: " + cursor.getString(1));
    System.out.println("CUSTOMER AGE: " + cursor.getInt(2));
    cursor.close();
    null

  • How do I turn off alerts to a calendar that I have turned off in iCloud?

    I have added my iCloud account to my son's iPod and only have the Family Calendar turned on but he keeps receiving alerts for every appointment in my Personal Calendar....how do I turn off the alerts for the calendar that he doesn't even have turned on?

    Csound1, he does have his own account and I added my iCloud account as a second one with only the Family Calendar turned on however he is still receiving alerts for all of my events in the Personal Calendar.  I'm wondering if 'sharing' the calendar rather than having him logged into my iCloud calendar would help?  He's not the only one either, my daughter and husband have the same set up and I keep getting calls from my husband saying "oh, are you going to pick up the drycleaning now?" hahaha!  Even though that Personal Calendar is turned off, they keep getting the alerts..argh!!

  • Need a Dynamic SQL statgement that returns multiple values.

    Hi,
    I'm using Oracle 10.1.0.5.
    In an anonymous block I have a dynamic SQL statement that finds the table name and column name that a string value resides in.
    It looks like this:
          l_sql := 'SELECT 1 FROM dual WHERE exists (SELECT 1 FROM '||
                   r.owner||'.'||r.table_name||' WHERE '||r.column_name||
                   ' = :b1)';
             EXECUTE IMMEDIATE l_sql INTO l_res USING l_contents;
             DBMS_OUTPUT.Put_Line(l_contents||' exists in '||r_owner||
                                  r.table_name||'.'||r.column_name);I'd then like to do a 'Select Distinct' to list all the other values in that column in the anonymous block,
    preferably as another dynamic SQL statement.
    How can I do this?

    user10382685 wrote:
    Hi,
    I'm using Oracle 10.1.0.5.
    In an anonymous block I have a dynamic SQL statement that finds the table name and column name that a string value resides in.
    It looks like this:
    l_sql := 'SELECT 1 FROM dual WHERE exists (SELECT 1 FROM '||
    r.owner||'.'||r.table_name||' WHERE '||r.column_name||
    ' = :b1)';
    EXECUTE IMMEDIATE l_sql INTO l_res USING l_contents;
    DBMS_OUTPUT.Put_Line(l_contents||' exists in '||r_owner||
    r.table_name||'.'||r.column_name);I'd then like to do a 'Select Distinct' to list all the other values in that column in the anonymous block,
    preferably as another dynamic SQL statement.
    How can I do this?Well, it would be nice for you to post the whole context of your present solution so we know what's going on. I'll assume r comes from a loop referencing user_tab_cols or some equivalent view.
    If so, you'll likely need to check the DATA_TYPE column.
    Keeping in mind, doing something like this is going to be pretty ridiculous if you have a large amount of distinct values ... I'm hoping/assuming this is a one off type of thing.
    declare
      type        l_date is table of date;
      v_date      l_date;
      type        l_char is table of varchar2(4000);
      v_char      l_char;
      type        l_numb is table of number;
      v_numb      l_numb;
      l_distinct_ set sys_refcursor;
    begin
      <current_code>
      open l_distinct_set for 'select distinct ' || r.column_name || ' from ' || r.owner||'.'||r.table_name;
      --expand on the data types you care about as needed, this is a BASIC set
      if r.data_type = 'DATE'
      then 
        fetch l_distinct_set bulk collect into v_date;
        <process_collection_as_wanted>
      elsif r.data_type in ('VARCHAR2', 'CHAR')
      then
        fetch l_distinct_set bulk collect into v_char;
        <process_collection_as_wanted>
      elsif r.data_type = 'NUMBER'
      then
        fetch l_distinct_set bulk collect into v_numb;
        <process_collection_as_wanted>
      end if;
      close l_distinct_set;

  • EBS ISG using custom PL/SQL functions that return XMLType

    Hi,
    We have a custom PL/SQL package that we use for interfacing systems and some of the functions in this package ruturn an XMLType. We want to deploy the package functions as web services through the ISG, but it is not working as expected. When deployed through the ISG, the functions with XMLType return type produce a null response from the ISG (they work fine when called in SQL or PL/SQL; functions with non-XMLTypes work fine).
    If we change the return type to CLOB (and use getClobVal() on the XMLType) then we get a response from the ISG, but it changes all the angle-brackets in the CLOB (which is still arbitrary XML text) to &lt; &gt; ...
    What is the proper way to get the complex XMLType output through the ISG? Anyone have any more experience?
    Thanks,
    --Walt                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Alex,
    For the predicate groups that are indexed/stored, the exact operator types (as in equality, inequality, like etc) that are indexed are specified while assigning the default index parameters. In the following example, exf$indexoper is used to specify the list of indexed operators.
    BEGIN
      DBMS_EXPFIL.DEFAULT_INDEX_PARAMETERS('Car4Sale',
        exf$attribute_list (
           exf$attribute (attr_name => 'HorsePower(Model, Year)',
                          attr_oper => exf$indexoper('=','<','>','>=','<='),
                          attr_indexed => 'FALSE')    --- stored predicate group
    END;
    /You can find more information about exf$indexoper at
    http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/t_expfilobj.htm#ARPLS153
    Could you confirm that you chose to index 'is null' and 'is not null' while assigning the default index parameters ? This information is available in OPERATOR_LIST column of the USER_EXPFIL_DEF_INDEX_PARAMS view.
    Hope this helps,
    -Aravind.

  • How can I turn off the pop up message that shows up 3 times everytime I print

    Every time I print whether a new cartridge has been installed or not, I get three pop up windows telling me the black, then the tri-color and the black again have been installed successfully. i have to click thru each one to be able to print.  How can I turn this off.

    What printer are you using?
    What OS do you have?
    Does it give a program name when it pops up, or does it just give you that message and a couple of options to choose from?
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------

  • How do I cut off my ipod nano so that I can save the battery

    I have a ipod nano gen 6. I did an update a few months back that stated that we would be able to turn it off somehow. I can not find anything out about that and I have forgot how to go in and turn it off. I think that it had something to do with the settings but not sure. If anyone knows I would appreciate any help that can be given. I am tired of having to charge this thing all the time.

    Hello Beth,
    Here is a link to the update article, which describes how to turn off the Nano.
    http://support.apple.com/kb/HT4531
    B-rock

  • How can I turn off the annoying yellow boxes that have started appearing?

    It seems that recently I have started having annoying yellow boxes appearing when I hover over thing in the finder window. This is something that I didn't have going on in the previous 3 versions of Mac OS X.
    Here's an example...
    How can I get rid of them?

    This appears to be a third party extention of some sort with the bright yellow background?  Start there if you modified.
    Might look at the following:
    https://discussions.apple.com/message/3515011?messageID=3515011#3515011
    or
    http://www.macworld.com/article/1055202/termtooltips.html

  • How do yoou turn off the audio voice commands that monitor every move made.?

    Mt droid has a feature that monitors every move I make in loud audio format. How to you disable this feature?

    Are you able to modify the settings in Touchless Control in your app drawer?

  • How do I turn off pop-up blockers so that I can access my school website account?

    I am currently in school and I have to access my school accounts daily but I cannot do that at home because an error message keeps appearing that says I need to turn off my 'pop-up' blockers. I need to somehow disable this function so that I can utilize my school accounts. What can I do to disable this pop-up blocker function?

    See this support article. <br />
    https://support.mozilla.org/en-US/kb/pop-blocker-settings-exceptions-troubleshooting#w_pop-up-blocker-settings

  • How do I switch off Calendar Notifications in OSX that I no longer want to see?

    I have several Calendars that I want to view but I do not want to see Notifications for all of them, only my main Calendar. I have tried all sorts of settings changes to try to stop the notications that I don't want from appearing but nothing I do makes any difference. Help please. What am I missing?

    Hi stevefromorpington,
    If you'd like to turn off alerts for a specific calendar, please see the information outlined below.
    Turn off alerts for a calendar
    Control-click the name of the calendar in the calendar list, then choose Get Info.
    If you don’t see the calendar list on the left, choose View > Show Calendar List.
    Select “Ignore alerts,” then click OK.
    Set event alerts and receive notifications - Calendar Help
    Take care,
    Alex H.

  • Sql query format involving a funtion that returns multiple/array of values

    Lets say u have two types of functions...
    FUNCTION 1
    function my_name ---- in package spec
         return varchar2;
    function my_name -----in package body
    return varchar2
    is
    begin
    return 'this is my name';
    end my_name;
    select package.my_name from dual; -- get the output as "this is my name"
    ====================================
    FUNCTION 2
    Type my_table is table of varchar2(25);
    function my_phone_numbers
    return package.my_table;
    function my_phone_numbers return package.my_table
    is
    mt package.my_table:= package.my_table('0000-000-0000','111-111-1111');
    begin
    return mt;
    end my_phone_numbers;
    select package.my_phone_numbers from dual; --- output errors -- looks like the syntax is wrong
    please help...thanks

    Oh you are right. I thought the OP had the types in place. Here is the correct one:
    SQL> create type my_table is table of varchar2(25);
      2  /
    Type created.
      1  create or replace function my_phone_numbers
      2  return my_table
      3  is
      4  mt my_table:= my_table('0000-000-0000','111-111-1111');
      5  begin
      6  return mt;
      7* end my_phone_numbers;
    SQL> /
    Function created.
    SQL> select * from table(my_phone_numbers);
    COLUMN_VALUE
    0000-000-0000
    111-111-1111
    No (user defined) sql types and no pipelined function.
    User defined types are needed for this to work, but it works without pipelined functions either.
    Message was edited by:
    Yas

  • How do I turn off the feature in iTunes that automatically starts up iTunes when I press the mic button on my headphones?

    Okay, so I guess the mic button in my headphones is broken and so it acts like I have pressed it even though I have not. So everytime I have my head phones plugged in itunes shows up and everytime I try close out or pause iTunes, it just starts right back up again and I have to do this constantly. My temporary solution was to just turn my iTunes volume all the way down but it still pops up with notifications that says a song is playing. It is gettin annoying because I cannot watch Netflix or anything else without getting itunes pop ups.  I was just wondering if there was any way to disable the feature?

    The mic button is probably sending a signal (or command) that works like a keyboard shortcut to open the app.
    System Preferences>Keyboard - under the Shortcuts tab, clear ANY iTunes shortcuts that appear in the list.

Maybe you are looking for

  • Using iTunes to burn a CD

    I'm trying to convert some ACC files form my iTunes library into MP3 files to burn on a CD and, have run into a problem. I created a new playlist of 130 songs from my library to burn on to the CD. 27 of the 130 songs need to be in MP3 format. So, I c

  • PopUp LOVs in tabular forms

    Hi, I've discovered a problem using Popup LOVs in tabular forms, whereby on selecting a value from the LOV the key value is displayed on the form instead of the display value. Having searched this forum it would appear I'm not the only one who has en

  • What are the required settings to enable HTTP Compression?

    I am running into download speed issues with some of my clients.  I am looking for ways to improve download response without having to rewrite my system(s). On the server side, I am using CF 8.01 on a W2003 system.  I have enable HTTP Compression for

  • Quality of .nef LR files Degrading after Edited in CS4 and saved as .tif?

    After I edit a .nef picture in LR, I right click  and select "edit in CS4".  I do my edits in CS4 (usually cloning) and I choose to save the image in CS4, it automatically appears as a .tif in Lightroom with the same rating/color coding that I gave t

  • MSI DVD DR4-A OK with MEGA PC ?

    Hi, Is the MSI DVD DR4-A compatible with the Hi-fi mode of the MEGA PC ? = does it work (open/close/read) when the PC is off and the Hi-fi mode is on for listening to music (CD-Audio & MP3 CD) Thanks !