Help: APEX - PL/SQL Function

Hello,
i need some help with a SQL statement.
I have the follwing Table "TABF":
ID Number,
B_Number varchar2(10),
G_Type varchar2(10),
Site varchar2(50),
Event varchar2(50),
Date varchar(10),
Dataset varchar2(50),
Mode varchar2(50),
Topic varchar2(10),
Parameter varchar2(10),
Value varchar2(10)The table is filled with records which, like this:
B Number | G-Type |Site       |Event  |Date     | Dataset   | Mode    | Topic    | Parameter | Value
800257   |   4.2  |  USA      | Test  |18.08.08 | Pre       |MBA      | Field    | F_C       | 73,9015 
800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_C       | 73,6951 
800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_C       | 73,71 
800257   |   4.2  |  USA      | Test  |18.08.08 | Post      |MBA      | Field    | F_C       | 73,7526 
800257   |   4.2  |  USA      | Test  |18.08.08 | Pre       |MBA      | Field    | F_C       | 4,5170 
800257   |   4.2  |  USA      | Test  |03.04.96 | BL        |MBA      | Field    | F_H       | 24,6074 
800257   |   4.2  |  England  | Test  |03.04.96 | BL        |MBA      | Field    | F_H       | 24,62 
800257   |   4.2  |  England  | Test  |18.08.08 | Post      |MBA      | Field    | F_H       | 24,4717  Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
And so on.....
The result should look like this for the example above:
B Number | G-Type |  Site     |Event  |Date     | Dataset   | Mode    | Topic    |Parameter   | Value    | Topic2   |  Parameter2  | Value2
800257   |    4.2 |  USA      | Test  |18.08.08 | Pre       | MBA     | Field    | F_C        | 73,9015  | -        | -            | -
800257   |    4.2 |  USA      | Test  |03.04.96 | BL        | MBA     | Field    | F_C        | 73,6951  | Field    | F_H          | 24,6074
800257   |    4.2 |  USA      | Test  |03.04.96 | BL        | MBA     | Field    | F_C        | 73,71    | Field    | F_H          | 24,62 
800257   |    4.2 |  USA      | Test  |18.08.08 | Post      | MBA     | Field    | F_C        | 73,7526  | -        | -            | -
800257   |    4.2 |  USA      | Test  |18.08.08 | Pre       | MBA     | Field    | F_C        | 4,5170   | -        | -            | -
800257   |    4.2 |  England  | Test  |18.08.08 | Post      | MBA     | Field    | F_H        | 24,4717  | -        | -            | -Hope you understand my problem and some1 can help me.
Thank you
Regards
Chris
Edited by: user11369135 on 09.07.2009 00:50

user11369135 wrote:
Hello,
i need some help with a SQL statement.
I have the follwing Table "TABF":
Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
And so on.....
Edited by: user11369135 on 09.07.2009 00:50if I understand correctly then you want a simple GROUP BY on B_number, Event, Date and Dataset.
But you want additionaly show 3 columns from one of the rows that was grouped.
This can be done using the little known KEEP syntax.
Documentation: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#sthref1389
Example from the docs
Aggregate Example
The following example returns, within each department of the sample table hr.employees, the minimum salary among the employees who make the lowest commission and the maximum salary among the employees who make the highest commission:
SELECT department_id,
MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) "Worst",
MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) "Best"
   FROM employees
   GROUP BY department_id;
DEPARTMENT_ID      Worst       Best
           10       4400       4400
           20       6000      13000
           30       2500      11000
           40       6500       6500
           50       2100       8200
           60       4200       9000
           70      10000      10000
           80       6100      14000
           90      17000      24000
          100       6900      12000
          110       8300      12000
                    7000       7000

Similar Messages

  • Help needed with sql function

    Hi,
    i have a function like below. basically what it does is, check whether first 2 places of a column_name is *'N_'*. if yes then i am replacing column_name which has *'N_' to ''*
    CASE WHEN SUBSTR(column_name,1,2) = 'N_' THEN
    *':NEW.'||REPLACE(column_name,'N_','')*
    i designed this based on the requirement. now i am facing a small issue. i have a column name 'RGN_ID'. so the above function replaces the RGN_ID as RGID as N_ comes in the middle of the column_name the above function accidentally replaces this as well. wherein i need to replace the first 2 position of column_name which starts like 'N_'
    can you please suggest any solution for this?
    Edited by: user13178284 on Jun 29, 2010 6:11 AM

    Thanks!. But i am afraid if this would help.
    there may be many column names having 'N_' at whatever position. for eg., TRAN_ID. here N_ comes at 4th and 5th position.
    i understand i need to place some kind of check above this function.so that if 'N_' comes anywhere in between the column_name i shouldnt replace it instead i should just replace column_name starting wtih 'N_'.
    any idea about this?

  • Need help with PL/SQL functions

    Hi,
    Is there a way to compare if a set of elements is present in another set using some function?
    Example: Is it possible to find out if all words present in 'BANQUE SAFRA SA' is present in 'BANQUE JACOB SAFRA (SUISSE) SA' using some function in Oracle 9i?
    Any suggestion would be appreciated.
    Thank you,
    Anushree

    Boneist,
    your solution would giv "false positives":
    SQL> with my_tab as (select 'BANQUE JACOB SAFRA (SUISSE) SA' col1 from dual union all
      2                  select 'BANQUE SAFRA (SUISSE) SB' col1 from dual union all
      3                  select 'BANQUE SAFRA SA' col1 from dual union all
      4                  select 'BANQUE SAFRANE SA' col1 from dual)
      5  -- end of mimicking your data. USE SQL below!
      6  select * from my_tab
      7  where col1 like replace('BANQUE SAFRA SA', ' ', '%');
    COL1
    BANQUE JACOB SAFRA (SUISSE) SA
    BANQUE SAFRA SA
    BANQUE SAFRANE SA  Here is a PL/SQL funcion that does not expect the words in the specific order:
    SQL> DECLARE
      2     FUNCTION strInStr(
      3        a   IN   VARCHAR2,
      4        b   IN   VARCHAR2)
      5        RETURN VARCHAR2
      6     IS
      7        i          PLS_INTEGER;
      8        startpos   PLS_INTEGER;
      9        endpos     PLS_INTEGER;
    10        word       VARCHAR2(4000);
    11     BEGIN
    12        FOR i IN 1 .. LENGTH(a) - LENGTH(REPLACE(a, ' ')) + 1 LOOP
    13           startpos := INSTR(' ' || a, ' ', 1, i);
    14           endpos := INSTR(a || ' ', ' ', 1, i);
    15           word := SUBSTR(a, startpos, endpos - startpos);
    16
    17           IF ' ' || b || ' ' NOT LIKE '% ' || word || ' %' THEN
    18              RETURN 'N';
    19           END IF;
    20        END LOOP;
    21
    22        RETURN 'Y';
    23     END;
    24  BEGIN
    25     DBMS_OUTPUT.put_line(strInStr('BANQUE SAFRA SA', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    26     DBMS_OUTPUT.put_line(strInStr('SAFRA BANQUE SA', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    27     DBMS_OUTPUT.put_line(strInStr('BANQUE SAFRA FRANCE', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    28     DBMS_OUTPUT.put_line(strInStr('QUE SAFRA SA', 'BANQUE JACOB SAFRA (SUISSE) SA'));
    29  END;
    30  /
    Y
    Y
    N
    N

  • Need help with a sql function...

    Hi.
    I have a year '2004' stored in a variable and I want to be able to add the rest of the date before this. How would I go about adding
    01-APR to the front of this year and then put it in a variable...
    thanks in advance.

    var number := 2004;
    dat date := to_date('01-APR-'||var, 'DD-MON-YYYY');

  • How to debug PL/SQL function in Apex

    Hi,
    I have a process in Apex that uses a PL/SQL function. When I compiled it in SQLPlus, it had no errors, yet when running it in Apex, I get an error.
    'Encountered unhandled exception in process type PLSQL' in the debug message. What's the best way to handle this? Thanks.

    Hi -
    Its hard to say without seeing the code of your process, but are you sure you are submitting any required paramaters to your process from the calling apge in Apex?
    Have you checked the Session to see what values it holds, and have you turned on Debug in Apex to see the code executing (or at least the call to your process)?
    Good luck.

  • Calling pl/sql function in CKM...pls help

    Hi,
    I have made a call to PL/SQL function in CKM customization. The code is :
    declare
    L_PMG_VALUE VARCHAR(3);
    begin
    L_PMG_VALUE:='PMG';
    VALIDATE_PMG_VALUE(L_PMG_VALUE);
    end;
    When i run it, it throws error which says:
    6550 : 65000 : java.sql.SQLException: ORA-06550: line 1, column 64:
    PLS-00221: 'VALIDATE_PMG_VALUE' is not a procedure or is undefined
    ORA-06550: line 1, column 64:
    PL/SQL: Statement ignored
    Function is compiled in the database and its working. I have selected the Technology as Oracle and correct Schema Name.
    Please help

    Hi,
    try the following way. i have not tried ....i think it helps you.
    In which schema you have created that procedure.
    Does the ODI user mantioned in topology have execute permissions on the procedure? if the ODI user have execute previlage on the procedure then in CKM customisation call the procedure like <schema>.<procedure>.
    Please let me know any issues.
    Thanks,

  • Help w/MaxDB Function; also: how does the "Debug SQL" function work?

    Hi there forum folks,
    In my former life, I was a Basis guy, but I haven't had the pleasure of working directly with SAP applications in a few months.  My current project is to attempt to use MaxDB in a real estate environment.  We're tracking home listings so that we can build statistical reports... such as "what agents are in the Top 100 in postal code X?"
    Anyway, as part of this project, I have attempted to construct my very first MaxDB database function.  Unfortunately, it doesn't give me the answers I'm hoping to see.  Here's the function:
    CREATE FUNCTION COUNT_LISTINGS (AGENTID CHAR(10)) RETURNS FIXED(6,1) AS
      VAR COLISTINGAGENTID CHAR(10);
          LISTINGAGENTID   CHAR(10);
          MLSNUMBER        CHAR(7);
          UNITS            FIXED(6,1);
      SET UNITS = 0;
      DECLARE FUNCTIONRESULT CURSOR FOR
        SELECT MLSNUMBER,
               LISTINGAGENTID,
               COLISTINGAGENTID FROM FREDDIE.GLAR_SOLDS
         WHERE LISTINGAGENTID = :agentid OR COLISTINGAGENTID = :agentid;
      IF $COUNT IS NULL THEN
        BEGIN
          CLOSE FUNCTIONRESULT;
          RETURN UNITS;
        END
      ELSE
        SET $RC = 0;
      WHILE $RC = 0 DO BEGIN
        FETCH FUNCTIONRESULT INTO :mlsnumber, :listingagentid, :colistingagentid;
        IF ( LISTINGAGENTID   = AGENTID AND COLISTINGAGENTID IS NULL ) OR
           ( COLISTINGAGENTID = AGENTID AND LISTINGAGENTID   IS NULL ) THEN
          SET UNITS = UNITS + 1
        ELSE
          SET UNITS = UNITS + 0.5;
      END;
    CLOSE FUNCTIONRESULT;
    RETURN UNITS;
    I've tried to follow the official MaxDB documentation.  My first deviation from that standard was the use of the "$COUNT" variable (instead of the "$RC" variable) immediately after the DECLARE/SELECT statement above.  When I tried to use $RC, for either a successful or unsuccessful query, $RC was always set to a non-zero value.
    I believe I'm past that, but now my issue is down around that FETCH statement.  The UNITS variable doesn't end up with the value I expect.  I know that it can be terribly confusing to try to analyze someone else's logic, but here's a brief narrative that describes what I'm trying to do...
    The GLAR_SOLDS table holds one line for each home sold.  It's keyed by the MLSnumber.  Each record also stores up to four agents who've been involved in the transaction: the listing agent, the co-listing agent, the selling agent, and the co-selling agent.  The database function I've written above pertains to the listing side only.  If I can get this to work, a separate function will process the selling side.  If no co-listing agent is involved in a given sell, that agent should get credit for 1 unit sold.  If he/she has help from a co-listing agent, the agent should only get credit for 1/2 unit sold.
    Also, does anyone know how the "Debug SQL" functionality is supposed to work within Database Studio?  When I right-mouse click on my function, and follow the path thru "Debug As...", after entering the connection & function arguments, I'm presented with an empty screen.  If you could point me to some documentation somewhere, I'd gratefully read it.
    I'm using MaxDB 7.7.06.09 on Windows XP (WIN32) with MaxDB Database Studio 7.7.06.09 (build 009-123-202-944).
    Thanks everyone for your help & advice.
    ~Fred

    Fred,
    please either provide the full SQL statements for your example or stick with mine.
    I'm not going to build it up myself a second time to suit yours now.
    >  But now, my issue is how do I store the resultant data in its own table?
    So where is the problem?
    INSERT INTO <target table> (field 1, field 2, ...)  (<your query>)  UDPATE DUPLICATES-
    With my tables this looks like this:
    create table sell_result (list_agent varchar(20) primary key, SUM_CREDIT fixed (10,2))
    insert
    into sell_result (list_agent,sum_credit)
        ( select list_agent, sum (credit) as SUM_CREDIT
          from ( select sh.object_id,lag.name as list_agent, 1 as credit
                 from soldhomes sh join agents lag on lag.id = sh.list_agent_id
                union all
                 select sh.object_id, lag.name as list_coagent, 0.5 as credit
                 from soldhomes sh join agents lag on lag.id = sh.list_coagent_id
          group by list_agent
    update duplicates
    Check what we have now
    sqlcli db770=> select * from sell_result
    | LIST_AGENT           | SUM_CREDIT        |
    | -------------------- | ----------------- |
    | Lars                 |              4.50 |
    | Lisa                 |              3.00 |
    | Mona                 |              2.50 |
    | Paul                 |              2.50 |
    4 rows selected (600 usec)
    Now add some sales data...
    Insert into soldhomes values (11, 1, 2, NULL, NULL)
    Insert into soldhomes values (12, 2, NULL, NULL, NULL)
    Insert into soldhomes values (13, 2, NULL, NULL, NULL)
    Re-run the INSERT command and you're done:
    sqlcli db770=> select * from sell_result
    | LIST_AGENT           | SUM_CREDIT        |
    | -------------------- | ----------------- |
    | Lars                 |              5.50 |
    | Lisa                 |              3.00 |
    | Mona                 |              5.00 |
    | Paul                 |              2.50 |
    4 rows selected (390 usec)
    Neat, isn't it?

  • SQL function help

    Hi, I am trying to write a sql query to replace the string starting with '<' with NULL. Right now I am using CASE statement to replace with NULLs. Is there any function to replace with NULLs for all the strings starting with '<%'.
    Example:
    CASE When field_name LIKE '<%' then NULL else field_name
    (before) After
    <NA> NULL
    <UK> NULL
    I want to replace the above sql suery with a single sql function without using CASE statements.
    I tried to use REPLACE function, but it replaces only single character. I want to replace the whole string
    Thanks in advance.

    Hi,
    Adam Martin posted a good solution. I hope that it is clear to you that you have to replace the string '<NA>' with your column(s).
    I.e.:
    SELECT REGEXP_REPLACE (a.col1, '^<.?+', '') AS col1
         , REGEXP_REPLACE (a.col2, '^<.?+', '') AS col2
      FROM table1 a;
    {code}
    You can use also the DECODE and SUBSTR functions to have the same result:
    The code below will get the first character with SUBSTR function and the DECODE function will return NULL if the value of the first character is "<" otherwise the value of the column.
    {code:sql}
    SELECT DECODE(SUBSTR(a.col1,1,1),'<', NULL, a.col1) AS col1
         , DECODE(SUBSTR(a.col2,1,1),'<', NULL, a.col2) AS col2
      FROM table1 a;
    {code}
    but using REGEXP_REPLACE is easier to write.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • LOOP in PL/SQL Function Body Help Needed

    I have a PL/SQL function that I'm trying to run and use a LOOP but I'm having some problems. I know the loop works since it output's two commas for me, which is how many records the query used for the LOOP returns, but I can't seem to find the right syntax to reference the column.
    DECLARE
    str VARCHAR2(2000) := "";
    BEGIN
    IF :P21_GLOBAL_ID IS NOT NULL THEN
    FOR q IN (
    SELECT
    ID,
    DRAW_DATE,
    ENTERED_BY
    FROM
    SAMPLE_T
    WHERE
    ID = :P21_GLOBAL_ID
    ORDER BY
    DRAW_DATE
    LOOP
    str := str || q.ID || ',' ;
    END LOOP;
    END IF;
    RETURN STR
    END;

    I just sent you the credentials.
    Interestingly, I have this same code for the source of a textarea on the page and the source for a report. I then modified the PL/SQL code as follows:
    DECLARE
         varSelect VARCHAR2(32767) := ''; --hold query SELECT definition
         varFrom VARCHAR2(32767) := ''; --hold query FROM clause definition
         varWhere VARCHAR2(32767) := ''; --hold query WHERE clause definition
         varOrderBy VARCHAR2(32767) := ''; --hold query ORDER BY clause definition
         varQuery VARCHAR2(32767) := ''; --hold query definition
    BEGIN
         IF TRIM(LOWER(TO_NUMBER(:P21_GLOBAL_TEMPLATE_ID))) IS NOT NULL THEN
              varSelect := 'SELECT SUBJECT_ID';
              varSelect := varSelect || ', SUBJECT_ID AS PHI';
              varSelect := varSelect || ', SUBJECT_ID AS ENTER_DATA';
              varSelect := varSelect || ', SUBJECT_ID AS LOGISTICA';
    for varTempQuery IN (
    SELECT
    stc.question_name as field_name,
    sti.read_security,
    sti.write_security,
    nvl(sti.validation_type,decode(stc.validation_rules,'None','TEXT_FIELD')) as validation_type,
    sti.html_caption,
    nvl(upper(sti.html_display_type),'TEXTFIELD') as html_display_type,
    sti.html_table_row,
    sti.html_table_column
    FROM
    rix.study_subject_templates sst,
    rix.study_subject_Template_items sti,
    rix.questions stc
    WHERE
    TRIM(LOWER(TO_NUMBER(sst.ss_template_Id))) = TRIM(LOWER(TO_NUMBER(:P21_GLOBAL_TEMPLATE_ID)))
    AND TRIM(LOWER(TO_NUMBER(sst.ss_Template_id))) = TRIM(LOWER(TO_NUMBER(sti.ss_Template_id)))
    AND TRIM(LOWER(TO_NUMBER(sti.phi_qid))) = TRIM(LOWER(TO_NUMBER(stc.qid)))
    AND TRIM(LOWER(TO_CHAR(sti.template_item_Status))) <> TRIM(LOWER(TO_CHAR('RETIRED')))
    ORDER BY
    sti.html_Table_row,
    sti.html_table_column
    LOOP
    varSelect := varSelect || ', ' || varTempQuery.field_name;
    END LOOP;
              varFrom := 'FROM     RIX.SUBJECTS';
              varWhere := 'WHERE STUDY_ID = ' || TRIM(LOWER(TO_NUMBER(:P21_STUDY_ID )));
              varOrderBy := 'ORDER BY';
              varOrderBy := varOrderBy || ' subject_label ';
    varQuery := varSelect || ' ' || varFrom || ' ' || varWhere || ' ' || varOrderBy;
         ELSE
    varQuery := 'SELECT SUBJECT_ID FROM SUBJECTS WHERE study_id = :P21_STUDY_ID;';
         END IF;
    RETURN varQuery;
    END;
    When I run the page now, the textarea has the SQL statement generated from the first IF block, but the report using the statement from the ELSE block. I thought it maybe was a timing issue, but both blocks reference other fields on the page, so it doesn't seem to be a timing issue. Shouldn't be a condition issue either with the IF block as the textarea and report use the same source, but are evaluating differently.
    Very odd (to me at least).

  • Problem with empty report parameters when passed to PL/SQL function

    Hi,
    We have come across what appears to be a bug in the JRC. When passing a report parameter to a PL/SQL function as a parameter, empty parameters are changed before being sent to the function. More specifically, an empty string "" ends up as the value "(')" in the PL/SQL function parameter. In our report we print the report parameters on the first page so we know that the parameters are OK before being passed to the database.
    The problem exists for version 12.2.203, 12.2.204 and 12.2.205 of the JRC.
    We have identified a workaround, but it is not exactly elegant: Before executing the report we modify all empty  parameters ("") to " " . In the PL/SQL function, we trim all parameters before using them.
    We call the function using a command object with a sql syntax like this example:
    select * from table (qa_batch_release.get_qa_br('{?p_report_id}','{?p_reg_set_number}','{?p_cr_number}','{?p_change_id_decode}','{?p_country_id}','{?p_mfg_item_no}','{?p_4_no}','{?p_5_no}','{?p_7_no}'))
    The PL/SQL function is a table returning function.
    Best regards, Thor

    Hi Kishore,
    using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
    What you can do to make it more generic is to use for example
    #CHECK_AMOUNT#
    in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
    SELECT NAME
         , BALANCE
         , BALANCE AS CHECK_AMOUNT
    FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
    Thope that helps
    Patrick

  • Passing #COLUMN_VALUE# as parameter to pl/sql function in column template

    Hi all,
    I want to color negative amounts in red in sql report using column template.
    I created a pl/sql function"isNegativeNum" which returns 1 or -1.
    create or replace function isNegativeNum(p_column_value varchar2) return number
    as
    l_dummy number;
    begin
          l_dummy := to_number(p_column_value,'999G999G990D00PR');
          IF l_dummy < 0
             THEN
                RETURN 1;
          else
                return -1;
          END IF;
    exception
    when others then
       RETURN -1;
    end;Below is column template.
    Column Template 1
    <td class="t3dataalt" #ALIGNMENT#><p color=red>#COLUMN_VALUE#</p></td>Column Template 1 Condition
    isNegativeNum('#COLUMN_VALUE#') = -1The issue is #COLUMN_VALUE# value is not being passed to the function, Insert statement in function reveals p_column_value as a string "#COLUMN_VALUE#". When I try without quotes like isNegativeNum(#COLUMN_VALUE#) = -1, I get below error.
    ORA-06550: line 1, column 48: PLS-00103: Encountered the symbol "#" when expecting one of the following: ( ) - + case mod new not null others select table avg count current exists max min prior sql stddev sum variance execute multiset the both leading trailing forall merge year month DAY_ hour minute second timezone_hour timezone_minute timezone_region timezone_abbr time timestamp interval date
         Error      ERR-1025 Error processing PLSQL expression. isNegativeNum(#COLUMN_VALUE#) = 1
    Any help is appreciated.
    Kishore

    Hi Kishore,
    using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
    What you can do to make it more generic is to use for example
    #CHECK_AMOUNT#
    in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
    SELECT NAME
         , BALANCE
         , BALANCE AS CHECK_AMOUNT
    FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
    Thope that helps
    Patrick

  • PL/SQL function body returning SQL - report error:ORA-01403: no data found

    Hi,
    I am working on Application Express 4.0.2.00.06, and 11G database.
    I have a problem with classic report area of type - PL/SQL function body returning SQL query. Query works if I define region area as - Use Generic Column Names (parse query at runtime only), and does not when I define it - Use Query-Specific Column Names and Validate Query.
    I am getting error:
    report error:ORA-01403: no data found
    This is my query that is returned from function, and displayed with htp.p, and it works ok and returns data in SQL Developer and SQL Workshop (in Apex).
    <code>
    /* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA
    </code>
    As you can see, I even tried with workaround that I found on the previous post on the forum, and that is to put /* select 1 from dual */ to start query.
    Any help would be appriciated.

    /* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA

  • Pass a value from a PL/SQL function to a javascript (html header) ? ?

    Hey Guys,
    Have a question regarding how to pass a value from a PL/SQL function to a javascript in the HTML Header.
    I have created a PL/SQL function in my database, which does looping.
    The reason for this is:  On my apex page when the user selects a code, it should display(or highlight buttons) the different project id's present for that particular code.
    example= code 1
    has project id's = 5, 6, 7
    code 2
    has project id's = 7,8
    Thank you for your Help or Suggestions
    Jesh
    The PL/SQL function :
    CREATE OR REPLACE FUNCTION contact_details(ACT_CODE1 IN NUMBER) RETURN VARCHAR2 IS
    Project_codes varchar2(10);
    CURSOR contact_cur IS
    SELECT ACT_CODE,PROJECT_ID
    FROM ACTASQ.ASQ_CONTACT where ACT_CODE = ACT_CODE1;
    currec contact_cur%rowtype;
    NAME: contact_details
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 6/25/2009 1. Created this function.
    BEGIN
    FOR currec in contact_cur LOOP
         dbms_output.put_line(currec.PROJECT_ID || '|');
         Project_codes := currec.PROJECT_ID|| '|' ||Project_codes;
    END LOOP;
    RETURN Project_codes;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    NULL;
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END contact_details;
    /

    Jesh:
    I have made the following modifications to your app to get it to work as I thing you need it to.
    1) Changed the source for the HTML Buttons Region(note use of id vs name for the Buttons)
    <script>
    function hilitebtn(val) {
    //gray buttons
    $x('graduate').style.backgroundColor='gray'
    $x('distance').style.backgroundColor='gray'
    $x('career').style.backgroundColor='gray'
    $x('photo').style.backgroundColor='gray'
    //AJAX call to get project-ids
    var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=GETPROJECTS',0);
    get.addParam('x01',val)
    gReturn = get.get();
    var arr=gReturn.split(':');  //dump into array
    get = null;
    for (i=0;i<arr.length;i++) {
    // alert('val=' + arr);
    if ( arr[i]==5)
    $x('graduate').style.backgroundColor='red';
    if ( arr[i]==6)
    $x('distance').style.backgroundColor='red';
    if ( arr[i]==7)
    $x('career').style.backgroundColor='red';
    if ( arr[i]==8)
    $x('photo').style.backgroundColor='red';
    </script>
    <table cellpadding='0' cellspacing='0' border='0'>
    <tr><td>
    <input type='button' id='graduate' value='Graduate'>
    </td>
    <td>
    <input type='button' id='distance' value='Distance'>
    </td>
    <td>
    <input type='button' id='career' value='Career/Tech'>
    </td>
    <td>
    <input type='button' id='photo' value='Photos'>
    </td>
    </tr></table>
    2) Defined the application process  GETPROJECTS as DECLARE
    IDS varchar2(1000);
    l_act_code varchar2(100) :=4;
    begin
    IDS:='';
    l_act_code := wwv_flow.g_x01;
    for x in(
    SELECT ACT_CODE,PROJECT_ID
    FROM ASQ_CONTACT
    where ACT_CODE = l_act_code)
    LOOP
    IDS := IDS || X.PROJECT_ID|| ':' ;
    END LOOP;
    HTP.PRN(IDS);
    END;
    3) Changed the 'onchange' event-handler on p1_act_code to be 'onchange=hilitebtn(this.value)'
    4) Added the JS to the HTML Page Footer <script>
    hilitebtn($v('P1_ACT_CODE'));
    </SCRIPT>

  • SQL Query ( PL/SQL function body returning query ) page

    Hello Friends,
    I have a page with type SQL Query ( PL/SQL function body returning query ).
    I have written a pl/sql block that returns a sql query - select statment.
    Some times i am getting no data found error - does it got to do with the variable that stores the query .
    =======================
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Error ERR-1101 Unable to process function body returning query.
    OK
    =====================
    When the query is returned with records where exactly the records are stored is it in the variable declared in pl/sql block or with the Oracle Apex implicit cursor.
    Here's the pl/sql block ..
    The query is generated while the user is navigating through pages ..
    ====================
    declare
    l_return_stmt varchar2(32767);
    l_select varchar2(32000);
    l_from varchar2(32000);
    l_where varchar2(32000);
    l_order_by varchar2(32000);
    l_stmt_recordcount varchar2(32000);
    l_recordcount number ;
    begin
    l_select := 'select '||:P10_VARLIST1||:P10_VARLIST2||:P10_VARLIST3
    ||:P10_VARLIST4||:P10_VARLIST5;
    l_from := ' from '||:P10_RELATION;
    if length(:P10_WHERE) > 0 then
    l_where := ' where '||:P10_WHERE;
    else
    l_where := '';
    end if;
    if length(:P10_ORDER_BY) > 0 then
    l_order_by := ' order by '||:P10_ORDER_BY;
    else
    l_order_by := '';
    end if;
    l_return_stmt := l_select||l_from||l_where||l_order_by;
    :P10_STMT := l_return_stmt;
    return l_return_stmt;
    end;
    =============================
    Appreciate your help in this regard.
    thanks/kumar
    Edited by: kumar73 on Apr 22, 2010 6:38 AM

    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. Then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?
    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?

  • How display result set of a PL/ SQL function call in a dialog box

    Hello,
    I am calling a PL/ SQL function from Apex, which returns - List of varchar.
    In Apex, it should show this list of varchar and "Yes" and "No" buttons on a message window.
    Can you please suggest a way to achieve the same.
    Thanks,
    Girish

    Hello,
    This application process "vrl_popup" is to get the values from PL/ SQL function. For popup window - confirm(). Also declared the LV_list as Application Item.
    Which is coded in the region part of the button. After pressing this button popup window should come with the list.
    <script type="text/javascript">
    <!--
    function doAjaxRequestParam( process, parameter)
    var ajaxRequest = new htmldb_Get(null,&APP_ID.,'vrl_popup='+process,0);
    ajaxRequest.add('lv_list', parameter );
    var jsonResult = eval('('+ ajaxRequest.get() +')');
    return jsonResult;
    var answer = confirm ("can try this?")
    alert (v_list)
    if (answer)
    alert ("done")
    else
    alert ("Unsuccessful")
    // -->
    </script>
    In apex I created following Application process by name = vrl_popup,
    declare
    lv_List varchar2(2000) := '';
    begin
    begin
    lv_List := select vrl_type_process_pkg.get_regd_reg_lste() from dual;
    exception when no_data_found then null;
    end;
    htp.prn(lv_List);
    end;
    Kindly help in fixing this.
    Edited by: Girish on Jun 17, 2010 12:57 AM

Maybe you are looking for

  • Why dont I see sqlplus in Windows 7 64 bit install

    I installed the 64 bit version of Oracle Client 11g install but I don't see sql plus under the BIN directory. So when I try to run sql plus from command prompt it fails.

  • Links to Word Templates

    I am trying to create links to Word templates but when someone clicks on them they become documents instead of the *.dot. I checked and someone said that the web server needed to be configured to have a MIME type assignment for *.dot files as "applic

  • Query views in CFMX

    Hello, I have recently migrated from MSAccess to MySQL. In CF 5 everything was working fine, but when we moved to CFMX 7, there is this one query that fails and I have tried many different ways (putting single quotes, parathesis etc.) I have created

  • Security problem? (ORA-00942 error when creating procedure)

    First, in SQL*Plus connect as system user: SQL>connect system/oracle Then, create table proctest for user scott and insert records: SQL>create table scott.proctest ( name varchar2(10)) ; SQL>insert into scott.proctest values ( 'bigboy' ) ; SQL>select

  • ImprovingSync messge response time?

    Hi all,           I have a sync scenario (RFC to JDBC) wherein the response time for the round about call is around 1.3 seconds... The JDBCsystem takes about 0.1 second to respond... so the Xi is taking the remain 1.3 seconds... Is the the best that