Standard SQL function not compiling in formula

I'm getting an error trying to use nvl2 inside a formula. It's returning an "identifier nvl2 must be declared" error. I'm connected to a database while trying to compile. What could be the problem?

I've got:
Report Builder 10.1.2.0.2
ORACLE Server Release 10.1.0.4.2
Oracle Procedure Builder 10.1.2.0.2
Oracle ORACLE PL/SQL V10.1.0.4.2 - Production
Oracle CORE     10.1.0.4.0     Production
Oracle Tools Integration Services 10.1.2.0.2
Oracle Tools Common Area 10.1.2.0.2
Oracle Toolkit 2 for Windows 32-bit platforms 10.1.2.0.2
Resource Object Store 10.1.2.0.2
Oracle Help 10.1.2.0.2
Oracle Sqlmgr 10.1.2.0.2
Oracle Query Builder 10.1.2.0.2 - Production
PL/SQL Editor (c) WinMain Software (www.winmain.com), v1.0 (Production)
Oracle ZRC 10.1.2.0.2
Oracle XML Developers Kit 10.1.0.4.2 - Production
Oracle Virtual Graphics System 10.1.2.0.2
Oracle Image 10.1.2.0.2
Oracle Multimedia Widget 10.1.2.0.2
Oracle Tools GUI Utilities 10.1.2.0.2
Connecting to an 11g database and it does not work.

Similar Messages

  • Bg_absence_duration sql function not working in Self Services

    I Have SQl Function registered and used in formula BG_ABSENCE_DURATION, it is working fine in the professional forms, but in "Leave management" form in self services it gives error:
    PER_EMP_NUMBER not found at line 231 of bg_absence_duration Cause: a sql select statement obtained from application dictionary return no rows when executed.
    Edited by: Elrefai on May 29, 2013 10:11 PM

    Hi Jay,
    were you finally able to access DFF in BG_ABSENCE_DURATION , did the following piece of code worked ?
    IF ABS_INFORMATION_CATEGORY = 'CA'
    THEN
    (If ABS_INFORMATION3 = 'Half Day'
    THEN
    ( IF date_start = date_end THEN
    (deduct_days = 0.5
    days_between = days_between - deduct_days
    duration = to_char(days_between) return duration, invalid_msg
    ELSE
    ( duration = 'FAILED'
    invalid_msg = 'Half day leave can be applied only for a day'
    return duration, invalid_msg

  • PL/SQL function not showing DMBS_OUTPUT.PUT_LINE result

    I have compiled a function and when I call it, the DMBS value is not shown.
    I have set serveroutput on
    I am using 9i.
    The function completes and provides a result:
    SQL> select textrawio.HEXTONUM('0D') from dual;
    TEXTRAWIO.HEXTONUM('0D')
    13
    The script:
    CREATE OR REPLACE PACKAGE BODY textrawio
    AS
      FUNCTION hextonum(v_hex VARCHAR2) RETURN NUMBER
      IS
        hex          VARCHAR2(4);
        num          NUMBER;
        num1         NUMBER;
        num2         NUMBER;
      BEGIN
    dbms_output.put_line ('hello');
        hex := SUBSTRB(v_hex,1,1);
        IF ( hex >= '0' and hex <= '9' ) THEN
          num1  := TO_NUMBER(hex);
        END IF;
        IF hex = 'A' TH...Any ideas from this snippet?
    I have never had a prob with DBMS_OUTPUT previously.
    There is no DMBS_OUTPUT_GET_LINE code.

    The full PL/SQL is
    CREATE OR REPLACE PACKAGE TEXTRAWIO
      IS
      FUNCTION tidblobchar(v_object_id char) RETURN VARCHAR2;
    END; -- Package Specification TEXTRAWIO
    SET SERVEROUTPUT ON
    CREATE OR REPLACE PACKAGE BODY textrawio
    AS
      FUNCTION tidblobchar(v_object_id char) RETURN VARCHAR2
      -- This function converts the long raw column of TIDBLOB to
      -- its character representation for manipulation.
      -- It can only be called for an object type of T.
      IS
        raw_data          LONG RAW;
        rawlen            NUMBER;
        hex_data          VARCHAR2(32760);
        char_data         VARCHAR2(32760);
        loop_counter      NUMBER;
      BEGIN
        -- Get the blob using the rowid passed in.
        -- Will always retrun only one row.
    dbms_output.put_line ('1');
        SELECT data
          INTO raw_data
          FROM ifsapp.client_profile_load
         WHERE v_object_id = rowid;
    dbms_output.put_line ('2');
        -- Convert the raw data to hex.   
        hex_data := rawtohex(raw_data);
        rawlen := length(hex_data);
        loop_counter := 1;
    dbms_output.put_line ('3');
        -- Loop through and convert the hex to characters.
        WHILE loop_counter <= rawlen LOOP
            char_data := char_data || CHR(to_number(SUBSTRB(hex_data,loop_counter,2),'xx'));
            loop_counter := loop_counter + 2;
        END LOOP;
        RETURN char_data;
      END;
    END;
    /Both parts compile but when I run it:
    SQL> select
      2  user_name, profile_name, data_length, textrawio.tidblobchar(rowid) data, timestamp
      3  from ifsapp.client_profile_load
      4  where data is not null
      5  ;
    user_name, profile_name, data_length, textrawio.tidblobchar(rowid) data, timestamp
    ERROR at line 2:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "IFSAPP.TEXTRAWIO", line 18I was hoping to use DBMS_OUTPUT to find which is the actual line having the error and later, what values it was dealing with.
    Thanks

  • Function not callable in formula column..

    Hi,
    I am getting one strange problem..when i call one function in a sql statment in report builder 6i from a formula column, it gives error that this function can not be called from sql but when i run the same sql from plsql dev, it runs fine..Oracle version 9i..
    Plz help..

    Hi,
    This is the code block used in the formula column..The formula cloumn datatype is character and size is 15..
    function FML_INT_LABLEFormula return Char is
    l_int_lable varchar2(15);
    begin
    select (DBK_C_ADVICES.DBF_C_RET_ADV_TEXT(:PRM_BRCH_CODE, NVL(:PRM_PROD_CODE,' '),'R01',1)||' Rate')into l_int_lable from dual ;
    RETURN(l_int_lable);
    end;

  • "Like" sql function not working  in Business Service

    Hi all,
    I have created a query with few Joins (Processing around 4-5 tables).It has Two scenarios, One with Equals and the other with Like function.
    SELECT
    ST.STREET,
    ST.DECOMPLEMENT,
    ST.STATE,
    LC.LOCALITY,
    DS.DISTRICT,
    ST.CDZIP,
    SP.street_type
    FROM
    STREET ST,
    DISTRICT DS,
    Locality LC,
    Street_Type SP
    WHERE
    ST.CDZIP LIKE ?
    AND ST.STARTDISTRICT = DS.DISTRICT (+)
    AND ST.LOCALITY = LC.LOCALITY (+)
    AND ST.STREET_TYPE = SP.street_type (+)
    When There is an Equal Sign after Where clause, The query gives desired output. But when there is a LIKE it does not give any output at all. How can i use this Query using perform operation.

    Hi Arun,
    How are you using it? Using DB Adapter / X-Query function? I have run similar SQL Queries easily through DB Adapter.
    Regards,
    Anuj

  • Packaged function not compiling

    This one is driving me mad as I cannot see any possible
    reason for it.
    I have two packages containing functions. They are both owned by one schema, different to the schema I am using to build my form. They are both granted execute to public and have public synonyms which are the same as the package name.
    The schema I am using to build my form can access the functions in sqlplus by specifying package.function.
    In my form I have:
    variable1 := package1.function1;
    variable2 := package2.function2;
    The first line compiles OK. The second comes up with function2 must be declared. If I prefix it with owner. it is OK.
    I cannot find any difference between the packages to explain this behaviour. Any ideas anyone please.

    Steve
    I had discussed it with someone else. He claimed afterwards that he had thought of that solution but it was so obvious he didn't like to insult me by suggesting it. I don't know if I believe him.
    Pavel
    Nice idea but we have too much code to retrospectively tidy up. Also with changes of personnel over the years we have such a mixture of different naming conventions that they are pretty meaningless. However, I do prefix my pll procedures with lib to give a clue where to look for them.

  • Are Sql functions different from user defined functions ?

    Hello,
    SQL functions are built into Oracle Database and are available for use in various appropriate SQL statements. Do not >confuse SQL functions with user-defined functions written in PL/SQL.according to first paragraph of this document Sql functions are different from user defined functions . How is that ?
    Is they really differ from each other ?

    bootstrap wrote:
    If you don't know what compilation is, please use Wikipedia or other online resources.I know what is compilation . But i was confused whether those sql functions are compiled in my machine when i install Oracle Database in my machine or they are pre-compiled .
    As you said these Sql functions are pre-compiled , it is clear now that they are pre-compiled platform dependent code .
    Can you provide actual source code of any SQL function , say SUM function .
    I want to see it, how they have defined . Eagerly waiting for any reply. please help .
    Edited by: bootstrap on Aug 19, 2011 11:50 AMYou can ask oracle if they give you their code. I doubt they will. However if you want to write you own user-defined aggregation function, there are examples in the documentation how to do that.
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17125/adfns_packages.htm#i1008575
    Edited by: Sven W. on Aug 19, 2011 9:24 AM

  • FOX forumla in IP: can I use Planing-functions in a FOX-formula ?

    Hi All,
    I know that there is a possibility to call an ABAP functions via a function modules within a FOX formula,
    but is it also possible to use a standard planning functions in a FOX formula ?
    I have some planing functions created like the copy-function, the delete-function or the repost-function.
    Now I would like to use the standard planing functions within a fox formula.
    If it´s possible, how do I call them within a FOX formula?
    Thanks a lot 

    Hi,
    You would be knowing that any planning function gets the data to operate on, based on the filter using which it is executed - it can give entirely different output in two cases if the filters are different. Thats why it does not mean much to call a planning function from inside another planning function - think about it, the situation will get messy if that was done. As I understand, you probably want to execute some standard functions after some part of your fox code and after that is executed, get back on with the code.
    For such a requirement, you can break your fox into multiple parts and then combine the parts and the std. pl. functions in a planning sequence in the order you need.
    But please also remember that depending on the complexity, many times it is advisable to create one fox (or exit) function rather than a sequence of many functions. Reason being that each function's execution in the sequence will include some overhead due to the planning framework (determining the transaction and reference data, lock server etc), so if you create just one function for the whole operation, this overhead will get significantly reduced.

  • SQL developer not showing compiler warnings

    I'm just testing out the new compiler warning contained in 11g related to the "when others" exception handler when it does not have a subsequent raise or raise_application_error.
    in SQL plus, this works fine:
    SQL> alter session set plsql_warnings='enable:all';
    Session altered.
    SQL>
    SQL> create or replace function do_stuff
      2  return number
      3  as
      4     v_return number;
      5  begin
      6
      7     v_return := 3;
      8     return v_return;
      9
    10  exception
    11  when others then
    12     return null;
    13  end;
    14  /
    SP2-0806: Function created with compilation warnings
    SQL> show errors;
    Errors for FUNCTION DO_STUFF:
    LINE/COL ERROR
    1/1      PLW-05018: unit DO_STUFF omitted optional AUTHID clause; default
             value DEFINER used
    11/6     PLW-06009: procedure "DO_STUFF" OTHERS handler does not end in
             RAISE or RAISE_APPLICATION_ERRORbut in SQL developer the output is:
    BANNER                                                                          
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production    
    PL/SQL Release 11.2.0.3.0 - Production                                          
    CORE     11.2.0.3.0     Production                                                        
    TNS for Linux: Version 11.2.0.3.0 - Production                                  
    NLSRTL Version 11.2.0.3.0 - Production                                          
    session SET altered.
    FUNCTION do_stuff compiled
    No Errors.Anyone experience this issue? is there some setting that makes SQL developer behave differently?

    it must be something I'm doing wrong, above, I was running under windows 7 pointing at the version above.
    I just tried it under an Enterprise Linux pointing at
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production          
    PL/SQL Release 11.2.0.2.0 - Production                                          
    CORE     11.2.0.2.0     Production                                                        
    TNS for Linux: Version 11.2.0.2.0 - Production                                  
    NLSRTL Version 11.2.0.2.0 - Production                                           and I get exactly the same script output and no compiler window....
    actually...... if I go into a procedure window from the schema browser and compile it there, then I get the correct warning messages..... the problem is I mostly develop from .sql files extracted from source control rather than directly from the schema browser, I just want the sql worksheet to be able to show me the same compiler log window.....

  • Standard Sql scripting Vs CE built-in functions ? Which one should I need to choose?

    Hello,
    My source is csv files and I need to load these source files into HANA after doing some Transformations based on multiple validations (for example , based on grade, some new column has to be populated with some relevant hikes i.e. need to use if/else logic, case logic, either insert or update in target table …etc. This validation should be done for each and every row).
    Assume some of the validations not possible through BODS and I need to implement this logic in HANA scripting (through procedures).
    I know HANA supports two kinds of writing scripts i.e. HANA standard sql statements and CE_functions and I’ve heard from HANA documentation that CE functions gives more performance than standard sql statements and we should not mix together in a single block of code.
    Please let me know which scenario should I go for?  (I doubt if we can do all the functionalities using CE functions?
    I am looking forward to your reply.
    Thanks,
    Sree

    Much awaited reply.
    Thanks a lot Jain !
    But just one more point to bring out, if some of requirements can be done through both CE functions and Scripting,  and some are possible through only scripting then we need to go for sql scripting only ..as we are not supposed to bring both the coding standards together, results in performance issues. ( Even your diagram shows either CE functions or Use SQL)
    am i right?
    Thanks,
    Sree

  • Newbie question: sql runs on sqlplus but not compile in pl/sql?

    I have the following two tables I would like to put a sql statement into pl/sql packages so I can use dbms_jobs automate it however, I keep getting compile time error. It seems to me that pl/sql does not like my sql that runs fine in sqlplus. Below is the error message and my test case?
    mdb_user@CMD> show error
    Errors for PACKAGE BODY DATA_QUALITY_REPORT_P:
    LINE/COL ERROR
    10/1 PL/SQL: SQL Statement ignored
    13/42 PL/SQL: ORA-00942: table or view does not exist
    create table S_ORG_EXT
    accnt_type_cd varchar2(100),
    cust_stat_cd varchar2(100)
    insert into s_org_ext
    select column_name,data_type from user_tab_columns where rownum <= 100
    select * from s_org_ext
    create table data_quality_report
    runid number not null,
    report_type number not null, --report type such as dup or not dup or other metrics
    org_level number not null, --organization level nsgn, sgn, shipto
    loc_level number not null,--locale level by city, by country, by region, grand_total
    name varchar2(100) not null,--the row output name of the agg
    value number not null,-- the row output value of the agg
    rundate date default sysdate
    create sequence data_quality_report_seq start with 1000
    INCREMENT BY 1
    NOCACHE
    NOCYCLE
    insert into data_quality_report
    select data_quality_report_seq.nextval,3,99,99,accnt_type_cd,cnt,sysdate from
    select accnt_type_cd, count (*) cnt from S_ORG_EXT where cust_stat_cd = 'VARCHAR2' group by accnt_type_cd order by 2 desc
    select * from data_quality_report
    truncate table data_quality_report
    CREATE or replace PACKAGE data_quality_report_p AS
    function pull_data return data_quality_report.runid%type;
    END data_quality_report_p ;
    create or replace package body data_quality_report_p as
    function pull_data return data_quality_report.runid%type is
    new_rid data_quality_report.runid%type;
    begin
    select data_quality_report_seq.nextval into new_rid from dual;
    insert into data_quality_report
    select new_rid,3,999999,999999,accnt_type_cd,cnt,sysdate from
    select accnt_type_cd, count (*) cnt from S_ORG_EXT where cust_stat_cd = 'VARCHAR2' group by accnt_type_cd order by 2 desc
    return new_rid;
    exception
    when no_data_found then
    DBMS_OUTPUT.PUT_LINE('Handling NO_DATA_FOUND exception.');
    when others then
    DBMS_OUTPUT.PUT_LINE('Handling OTHER exception.');
    end; --end pull_data
    end data_quality_report_p;
    /

    Hi,
    A very common cause for ORA-00942 in a stored procedure (here I'm including packages and functions) is that you have privileges only through a role. Roles don't count in stored procedures if they are compiled with the default "AUTHID DEFINER". Either
    (1) have whatever privileges you need (e.g. "INSERT ON data_quality_report" or "SELECT ON s_org_ext") granted directly to you (the package owner), or to the pseudo-user PUBLIC, and not merely to some role that you have, or
    (2) create the package in the same schema as the tables, or
    (3) create the package with "invoker's rights", like this
    CREATE OR REPLACE PACKAGE data_quality_report_p
    AUTHID CURRENT_USER       -- Added
    AS
        FUNCTION pull_data ...'AUTHID CURRENT_USER" goes right before the keyword "IS" (or "AS") in the package spec; you don't have to do anything to the package body.
    However, if you do this, then whoever runs the package will need to have those privileges, in addition to EXECUTE privileges on the package. Privileges granted through a role will be okay.
    Usually, (1) is the best solution. Have the table owner(s), or someone with the proper authority, grant privileges directly to you.
    By the way, there's no point in having an ORDER BY clause in a sub-query like you're doing, and there's no point in having ORDER BY in an INSERT statement. It's not causing the ORA_00932 error (or any other error), it's just wasting resources.
    Edited by: Frank Kulash on Mar 23, 2011 4:02 PM
    Change DEFINER to CURRENT_USER in a couple of places. (Bad mistake!)

  • Procedure compilation failed with SQL command not properly ended error

    Hi All,
    Kindly help me to fix this.
    I am compiling a procedure and getting an error. Procedure and error details are as follows:
    Procedure:
    CREATE or REPLACE PROCEDURE jiostore_new.auditReportCount (u_name IN VARCHAR2,stdate IN DATE,eddate IN DATE)
    IS
    BEGIN
    DECLARE Total Number;
    BEGIN
    SELECT COUNT(am.id) into Total FROM auditMaster_ AS am  INNER JOIN jioworld.deviceos_ dvos ON dvos.id=am.deviceOs WHERE am.updatedBy=u_name or am.updatedBy=ALL AND DATE(am.updatedDate)>=stdate OR DATE(am.updatedDate)='0000-00-00' AND DATE(am.updatedDate)<=eddate or DATE(am.updatedDate)='0000-00-00';
    dbms_output.put_line('Total Count:' || Total);
    END;
    END;
    Error:
    Error(6,1): PL/SQL: SQL Statement ignored
    Error(6,50): PL/SQL: ORA-00933: SQL command not properly ended
    Regards,
    Vishal G

    2922723 wrote:
    Hi All,
    Kindly help me to fix this.
    I am compiling a procedure and getting an error. Procedure and error details are as follows:
    Procedure:
    CREATE or REPLACE PROCEDURE jiostore_new.auditReportCount (u_name IN VARCHAR2,stdate IN DATE,eddate IN DATE)
    IS
    BEGIN
    DECLARE Total Number;
    BEGIN
    SELECT COUNT(am.id) into Total FROM auditMaster_ AS am  INNER JOIN jioworld.deviceos_ dvos ON dvos.id=am.deviceOs WHERE am.updatedBy=u_name or am.updatedBy=ALL AND DATE(am.updatedDate)>=stdate OR DATE(am.updatedDate)='0000-00-00' AND DATE(am.updatedDate)<=eddate or DATE(am.updatedDate)='0000-00-00';
    dbms_output.put_line('Total Count:' || Total);
    END;
    END;
    Error:
    Error(6,1): PL/SQL: SQL Statement ignored
    Error(6,50): PL/SQL: ORA-00933: SQL command not properly ended
    Regards,
    Vishal G
    The first thing, is that for your own sanity you should learn to format your code for readability.  And for the sanity of those from whom you seek help, you should learn to preserve that formatting when you post to a forum:
    CREATE OR REPLACE PROCEDURE jiostore_new.auditReportCount(
        u_name IN VARCHAR2,
        stdate IN DATE,
        eddate IN DATE)
    IS
    BEGIN
      DECLARE
        Total NUMBER;
      BEGIN
        SELECT COUNT(am.id)
        INTO Total
        FROM auditMaster_ AS am
        INNER JOIN jioworld.deviceos_ dvos
        ON dvos.id              =am.deviceOs
        WHERE am.updatedBy      =u_name
        OR am.updatedBy          =ALL
        AND DATE(am.updatedDate)>=stdate
        OR  DATE(am.updatedDate) ='0000-00-00'
        AND DATE(am.updatedDate)<=eddate
        OR  DATE(am.updatedDate) ='0000-00-00';
        dbms_output.put_line('Total Count:' || Total);
      END;
    END;
    What is the data type of am.updateDate?  It appears to be a varchar being passed to a function named DATE to convert it to a DATEfor comparison to your input parameters,  But you also compare it to strings. 
    Where are the variables 'u_name' and 'ALL'?  (and what kind of a name is that for a variable -- 'ALL'?)

  • PL/SQL function. ORA-00933: SQL command not properly ended

    This is my first attempt at pl/sql functions with dynamic sql. It will compile, but when I try to test it I get the ORA-00933 error at line 147. line 147 is OPEN retval FOR report_query;
    Please take a look and let me know what it wrong! thanks
    {CREATE OR REPLACE FUNCTION TSARPTS.Stats (v_Hub       IN VARCHAR2,
                                              v_type      IN VARCHAR2,
                                              v_subtype   IN VARCHAR2)
       RETURN SYS_REFCURSOR
    IS
       retval           SYS_REFCURSOR;
       report_query_a   VARCHAR2 (10000)
                           := '
      SELECT hub,
             CASE
                WHEN Total = 0 OR Pass_1st = 0 THEN 0
                ELSE ROUND (Pass_1st / (Total) * 100, 2)
             END
                AS Pass_1st_percent,
             CASE
                WHEN Total = 0 OR Pass_2nd = 0 THEN 0
                ELSE ROUND (Pass_2nd / (Total) * 100, 2)
             END
                AS Pass_2nd_percent,
             CASE
                WHEN Total = 0 OR Pass_3rd = 0 THEN 0
                ELSE ROUND (Pass_3rd / (Total) * 100, 2)
             END
                AS Pass_3rd_percent,
             CASE
                WHEN Total = 0 OR DNM = 0 THEN 0
                ELSE ROUND (DNM / (Total) * 100, 2)
             END
                AS DNM,
             CASE
                WHEN Total = 0 OR Incomplete = 0 THEN 0
                ELSE ROUND (Incomplete / (Total) * 100, 2)
             END
                AS Incomplete
        FROM (  SELECT hub,
                       SUM (DECODE (result, ''Pass_on_1st'', 1, 0)) Pass_1st,
                       SUM (DECODE (result, ''Pass_on_2nd'', 1, 0)) Pass_2nd,
                       SUM (DECODE (result, ''Pass_on_3rd'', 1, 0)) Pass_3rd,
                       SUM (DECODE (result, ''DNM'', 1, 0)) DNM,
                       SUM (DECODE (result, ''INCOMPLETE'', 1, 0)) Incomplete,
                         SUM (DECODE (result, ''Pass_on_1st'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_2nd'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_3rd'', 1, 0))
                       + SUM (DECODE (result, ''DNM'', 1, 0))
                       + SUM (DECODE (result, ''INCOMPLETE'', 1, 0))
                          Total
                  FROM employees_vw a, pse_vw b
                 WHERE     a.emplid = b.emplid
                       AND status IN (''S'', ''I'', ''N'')
                       AND TYPE = ''PSE''
       report_query_b   VARCHAR2 (10000)
                           := ' 
    SELECT hub,
           TYPE,
           subtype,
           CASE
              WHEN Total = 0 OR Pass_1st = 0 THEN 0
              ELSE ROUND (Pass_1st / (Total) * 100, 2)
           END
              AS Pass_1st_percent,
           CASE
              WHEN Total = 0 OR Pass_2nd = 0 THEN 0
              ELSE ROUND (Pass_2nd / (Total) * 100, 2)
           END
              AS Pass_2nd_percent,
           CASE
              WHEN Total = 0 OR Pass_3rd = 0 THEN 0
              ELSE ROUND (Pass_3rd / (Total) * 100, 2)
           END
              AS Pass_3rd_percent,
           CASE
              WHEN Total = 0 OR DNM = 0 THEN 0
              ELSE ROUND (DNM / (Total) * 100, 2)
           END
              AS DNM,
           CASE
              WHEN Total = 0 OR Incomplete = 0 THEN 0
              ELSE ROUND (Incomplete / (Total) * 100, 2)
           END
              AS Incomplete
      FROM (  SELECT hub,
       TYPE,
           subtype
                      SUM (DECODE (result, ''Pass_on_1st'', 1, 0)) Pass_1st,
                       SUM (DECODE (result, ''Pass_on_2nd'', 1, 0)) Pass_2nd,
                       SUM (DECODE (result, ''Pass_on_3rd'', 1, 0)) Pass_3rd,
                       SUM (DECODE (result, ''DNM'', 1, 0)) DNM,
                       SUM (DECODE (result, ''INCOMPLETE'', 1, 0)) Incomplete,
                         SUM (DECODE (result, ''Pass_on_1st'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_2nd'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_3rd'', 1, 0))
                       + SUM (DECODE (result, ''DNM'', 1, 0))
                       + SUM (DECODE (result, ''INCOMPLETE'', 1, 0))
                          Total
                  FROM employees_vw a, pse_vw b
                 WHERE     a.emplid = b.emplid
                       AND status IN (''S'', ''I'', ''N'')
                     AND TYPE = ''PSE''
       report_query     VARCHAR2 (10000);
    BEGIN
       IF v_hub <> '*'
       THEN
          report_query := report_query_a;
       ELSE
          report_query := report_query_b;
       END IF;
       IF v_hub <> '*'
       THEN
          report_query :=
             report_query || ' and hub = ''' || v_hub || ''' GROUP BY hub )
    GROUP BY hub,
             Pass_1st,
             Pass_2nd,
             Pass_3rd,
             Total,
             DNM,
             Incomplete';
       END IF;
       IF v_type <> '*' AND v_subtype <> '*' AND v_hub <> '*'
       THEN
          report_query :=
                report_query
             || ' and hub = '''
             || v_hub
             || ''' and type = '''
             || v_type
             || ''' and subtype= '''
             || v_subtype
             || '''
              GROUP BY hub,
                     TYPE,
                     subtype,
            GROUP BY hub,
                     TYPE,
                     subtype,
                     Pass_1st,
                     Pass_2nd,
                     Pass_3rd,
                     Total,
                     DNM,
                     Incomplete';
       END IF;
       OPEN retval FOR report_query;
       RETURN retval;
    END;
    Edited by: user10821012 on May 13, 2010 9:56 AM

    What you are seeing is pretty common. When I work with dynamic SQL I usually include some logic to put the dyanmic SQL into a string and a means to see what was generated, something like (untested here)
      v_sql_c := 'select * from dual';
      open refcur for v_sql_c;
    exception
      when others then
         insert into work_table (clob_column) values (v_sql_c);so I can later query the table to get to the generated SQL for debugging, something like
      select * from work_table;I also try to write dynamic SQL so I can paste it from the work table right into query execution without editing.

  • On Submit process not firing -report (PL/SQL function returning SQL query)

    Can anyone suggest possible causes / solutions for the following problem?
    I have a report region that uses a PL/SQL function returning SQL query. The report allows the user to update multiple fields / rows and then click a button to submit the page which should run the On-Submit process to update the database. However the process does not run and I get a 'HTTP404 page cannot be found' error; and when I navigate back using the Back button I cannot then navigate to any other page in my application without getting the same error. The button was created by a wizard selecting the options to submit the page and redirect to a (same) page. The button does not actually have a redirect in its definition but the wizard created a branch to the same page which should work and the button has the text 'submit as SUBMIT' next to it so it appears to be set up correctly.
    I have recreated this page several times in my application and I cannot get the On-Submit process to run. However I have created a cut down version of the same page in the sample application on apex.oracle.com at http://apex.oracle.com/pls/otn/f?p=4550:1:179951678764332 and this works perfectly so I am at a loss to understand why it does not work in my application. I cannot post any part of the application itself but if anybody would like to check out page 30 of the sample application (Customer Update Test tab) updating the surnames only, using credentials ja, demo, demo this is pretty much what I have got in my application.
    Any ideas would be much appreciated?

    Thanks for the suggestions guys. I have now identified that the problem goes away when I remove the second table from my report query. The original report query retrieved data from two tables and the process was updating only one of the tables. I thought I had approached the task logically i.e. first get the report to display the records from the two tables, then get the process to update the first table and finally to modify the process further to update the second table.
    Can anyone point me to an example of multiple row updates on multiple tables using a PL/SQL function returning an SQL query?

  • Item value not showing up in PL/SQL function on another item.

    Basically, I am trying to update a database field based on the vaule of 2 other fields, but the item value dow not seem to get stored. No errors, it just shows up as a null value in the database. Here is the code inside the default area as a FL/SQL Function.
    declare
    P14_TNUM varchar2(255);
    begin
    select concat(mname,id) into P14_TNUM from T1,T2 where mid=:P14_TID;
    return P14_TNUM;
    exception when others then
    return null;
    end;
    Note:
    id is in T1
    mname and mid is in T2
    :P14_TID is the item which points to the pk in table T1

    Anon,
    I'm still a little confused as to what you're trying to do. Could you please take a little bit to better explain?
    Regards,
    Dan
    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
    http://sourceforge.net/projects/plrecur

Maybe you are looking for