Using a function return in an "IN" statement

All,
I need to filter the records in a table based on the return value of a function. The function determines a person's group and then executes 2 separate select statements depending on the group.
CREATE OR REPLACE PACKAGE pkg_rolebased
AS
CURSOR all_dmn_cur
IS
SELECT dmn_id
FROM tomwojeck.pa_domain ;
CURSOR child_dmn_cur (role_id_in IN varchar)
IS
SELECT distinct r.dmn_id
FROM tomwojeck.pa_domain_restriction_domain r
WHERE r.dmn_restriction_id IN (
SELECT DISTINCT a.dmn_restriction_id
FROM tomwojeck.pa_role_wf_entity_fct_access a
WHERE a.role_id = role_id_in
                    AND a.workflow_entity_fct_id= 'View Student.Student.View'
                    AND a.dmn_restriction_id IS NOT NULL);
FUNCTION rolelookup (stud_email IN varchar)
RETURN roletable;
END;CREATE OR REPLACE PACKAGE BODY pkg_rolebased
IS
FUNCTION rolelookup (stud_email IN varchar)
RETURN roletable
IS
v_roleid varchar2(200);
v_returnval varchar2(200);
v_data roletable := roletable ();
dmn_rec all_dmn_cur%ROWTYPE;
BEGIN
-- Find out the role of the person
SELECT r.role_id
INTO v_roleid
FROM tomwojeck.pa_user_prfl p, tomwojeck.pa_user_prfl_role r
WHERE p.user_name = r.user_name
AND UPPER (p.email_addr) = UPPER (stud_email);
IF UPPER (v_roleid) = 'ALL'
THEN
OPEN all_dmn_cur;
LOOP
FETCH all_dmn_cur
INTO dmn_rec;
v_data.EXTEND;
v_data (v_data.COUNT) := dmn_rec.dmn_id;
EXIT WHEN all_dmn_cur%NOTFOUND;
END LOOP;
CLOSE all_dmn_cur;
ELSE
OPEN child_dmn_cur (v_roleid);
LOOP
FETCH child_dmn_cur
INTO dmn_rec;
v_data.EXTEND;
v_data (v_data.COUNT) := dmn_rec.dmn_id;
EXIT WHEN child_dmn_cur%NOTFOUND;
END LOOP;
CLOSE child_dmn_cur;
END IF;
RETURN v_data;
END rolelookup;
END;
The select statement to filter on this mess is:
select
lname,
fname,
dmn_id,
stud_id
from tomwojeck.pa_student p
where p.DMN_ID in (select * from table(cast(tomwojeck.pkg_rolebased.rolelookup('[email protected]') as tomwojeck.RoleTable)))
The problemm is this performs horribly! If I enter an email address that causes the first cursor to be used, it runs well, but if I use an email address that causes the second cursor to run, it takes forever.
Is there a better way to do this?
Thanks,
Tom Wojeck

<<The version of Oracle is 9i.>>
Could you specify the exact version? For example, 9.2.0.3.0.
<<I'm not sure of the query optimizer version. How do I find that?>>
SQL> show parameter optimizer_mode
NAME                                 TYPE
VALUE
optimizer_mode                       string
CHOOSE<<The interestin thing is that the function itself runs well; it's when I try to use the function as an "IN" clause that the performance degrades. It almost seems as though the database is retrieving each row from the student table, and then running the function to see if there are any matches. >>
Your query has to be tuned. The execution plan as well as the information on the indexes will certainly help.

Similar Messages

  • To use Boolean function in DECODE or CASE statement

    Hi all
    I have a scenario where i need to use a boolean function inside DECODE statement. When i tried this way iam getting "ORA-06553: PLS-382: expression is of wrong type".
    I doubt whether i can use boolean function inside DECODE or not?
    My query will be like this:
    select decode(my_fuction( ),'TRUE',1,'FALSE',0) from dual;
    Any help is highly appreciated.
    Thanks
    Sriram

    Overloaded functions must differ by more than their
    return type . At the time that the overloaded
    function is called, the compiler doesn't know what type
    of data that function will return. The compiler cannot,
    therefore, determine which version of the function to
    use if all the parameters are the same.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Function return boolean with combine query and validation

    Wondering how would you combine a query and the condition together...
    Right now i have a computation that would do a single sql query.
    and in my validation i would use a function return boolean call the result from the computation to do some if statements
    wondering how would you combine the two in the validation? ( tried pasting both in the validation but it doesn't seem to work.)
    Select count(NAME_ID)
    FROM table
    WHERE to_char(NAME_ID) = :P1_NAME_ID;
    IF :P1_results = 1 THEN
    RETURN TRUE;
    END IF;
    RETURN FALSE;

    OK, then does this work for you as validation on your item; P1_NAME_ID ?
    DECLARE
       l_rowcount   PLS_INTEGER;
    BEGIN
       SELECT COUNT (name_id)
         INTO l_rowcount
         FROM my_table
        WHERE TO_CHAR (name_id) = :P1_NAME_ID;
       IF l_rowcount = 1
       THEN
          RETURN TRUE;
       ELSE
          RETURN FALSE;
       END IF;
    END;Jeff

  • How to use group function in insert or update

    Hai All
    How can we use group function in insert or update statement
    I am generating an attendance so i have different set of timing for example
    0800,1200,1230, 1700 and i need to insert into these data into table with min value to intime and max value to
    outtime and othere to inertval time in or out
    Pls tell me with some example
    For example
    For INSERT
    insert into T2 (barcode,empcode,intime,attend_date)
                   values(r2.cardn,r2.enpno,MIN(r2.ptime),r2.pdate);
    For UPDATE
    update dail_att set outtime= MAX(r2.ptime) where empcode=r2.enpno and barcode=r2.cardn and
    attend_date=r2.pdate;
    Here instead of where i need to use having so pls tell how to use
    Thanks & Regards
    Srikkanth.M

    Hai Man
    R2 is not a table name its a record
    Let me explain clearly
    I have to generate daily attendance for lot of employees So i have two table t1 and t2
    T1 consist of three column empno,date,time
    T2 consist of empno,name,date,intime,outtime,intrin,introut
    So now i need to give the T1 Min value Of time to T2 Intime and T1 Max value of Time to T2 Outtime fields so there so many records while i am using
    max(time) it gives the max value of all so i seperated by group function so now i have an error in subquery ie it is an single row subquery so i need to use multiple row subquery how i can use multiple row subquery in update statement
    Thanks In Advance
    Srikkanth.M

  • Using Column Name returned by function in SELECT statement

    Hi
    Output from my function (RETURN data type is VARCHAR2) is column name. I want to use it directly in my SELECT statement. Below is simplified example of this:
    --- Function
    CREATE OR REPLACE FUNCTION simple RETURN varchar2 IS
    BEGIN
    RETURN ‘my_column’;
    END simple;
    --- Select
    SELECT simple FROM my_table;
    This does not work. It seems that output from function is passed in quotation i.e.
    SELECT ‘my_column’ FROM my_table;
    So the output from SELECT is a list of rows populated with values my_table:
    COLUMN     simple
    ROW1     my_column
    ROW2     my_column
    ROW3     my_column
    Can please someone help me with this?

    I'm not sure I got you right.
    In standard SQL everything must be known at compile time. If not dynamic SQL is required, but is a costly operation (usually requires parsing before each execution) so it should better not be used when standard SQL can do it.
    I provided a design time example where a function returns the column name from the given the table name and column id for a varchar2 column data type to make things simple. Then a query string is constructed and executed dynymically to return all column values of the chosen table_name.column_name.
    SELECT simple FROM my_tableAt compile time the simple function return value is unknown (any varchar2 value would do) you already find out you get the (same) return value (i.e column name) for each table row => dynamic SQL needed to get the column values
    The purpose of function would be to rename all columns for provided table.The table name would be provided, right? If yes => dynamic SQL
    What is the function supposed to return the column name (where would the new name come from?), the column alias (which table column would be renamed to the new name?)
    The user could use the new_column name as the column alias name submitting the query.
    Is it possible to do this?Maybe () using a pipelined function (different data types - number,date, ... not cosidered yet) but your simple query;
    <tt>SELECT simple FROM my_table</tt>
    might look like:
    <tt>select my_column_value new_column_name from table(get_column_value(table_name,column_name))</tt>
    Sorry, no Database at hand to provide a specific example.
    Regards
    Etbin

  • Which is better - SQL Statement in APEX or as a function returning a type?

    Hi
    I have a general question about best practices for APEX development.
    If we have say a report region based on a SQL statement, is it better (from a performance perspective) to have the SQL statement defined in the region in APEX OR have the actual select statement executed in the backend and have the result set returned in a type to APEX?
    As an example:
    In APEX region
    SELECT col1, col2, col3 FROM table_aOR
    In APEX region
    select col1, col2, col3 from TABLE(CAST(<my package>.<my proceduere > AS <my type >)) ;<my package>.<my proceduere > would obviously execute the statement
    SELECT col1, col2, col3 FROM table_ausing dynamic SQL and return the results to APEX in thy type <my type>.
    Apologies if this sounds to be a really stupid thing to ask.
    Kind regards
    Paul

    Denes Kubicek wrote:
    You should use a pipelined function only then when you can't use SQL. Otherwise SQL is the way to go.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    ------------------------------------------------------------------------------thanks Denes... but does it matter if:
    1. The SQL statement is actually defined in the APEX region
    or
    2: The select statement is stored in a packageD function and returned to APEX?
    I seem to recall an article I read stating that it is best for all client applications to call stored procedures and functions rather than have SQL statement embedded in the actual application?
    Kind regards
    Paul

  • Using java function in select statement

    Hi,
    I am trying to use java function in select statement.
    public class ClassA{
         private static String MyConst = "foo";
         public static String functionA(){
              return MyConst;
    in my query I have:
    select
         ClassA.functionA() AS id,
         groupId AS newID,
    from
         myChannel[now]
    ClassA is part of the application (no need to import).
    I get and error of Invalid Expression on ClassA.functionA().
    I also tried to declare the function in the processor element:
    <wlevs:processor id="proc">
         <wlevs:function function-name="A" exec-methode="functionA">
              <bean class="mtPackage.ClassA"/>
         </wlevs:function>
    <wlevs:processor>
    but then I get a different error in the processor XML file:  "An InvocationTargetException was encoutered while attemting to register the user defind function A. The message was null"
    What am I missing here?

    Hi,
    From the above description, you have tried two manners to call method functionA() in the user defined  class ClassA. One uses java cartridge manner directly and the other try to use user defined function manner.
    For the java cartridge manner, the following CQL query should work if the ClassA is really included in the OEP app. I have done similar test before, it works.
    select
         ClassA.functionA() AS id,
         groupId AS newID,
    from
         myChannel[now]
    For user defined function manner, I think two things you need to change:
    1. Need to declare the function in the EPN assembly file(under META-INF/spring/), not component configuration file(under META-INF/wlevs/). The following is an example:
    <wlevs:processor id="proc">
         <wlevs:function function-name="A" exec-methode="functionA">
              <bean class="mtPackage.ClassA"/>
         </wlevs:function>
    </wlevs:processor>
    2. Call the user defined function in the CQL query in the component configuration file under processor. For example:
    select A() from myChannel
    Regards,
    XiYing

  • Limitations in using a function within a select statement

    I have a function which retrieves various data elements from the
    database and formats it accordingly. The data (varchar2)
    returned could be in excess of 2,000 characters length.
    I need to use the returned data as part of a view. I am able to
    use the function in a "select" statement, but when I use it with
    returned data in excess of 2,000 chars, I get the following
    error:
    ORA-06502: PL/SQL: numeric or value error
    This error is occurring whenever the returned data is in excess
    of 2,000 characters.
    Is there an alternative method to what I am proposing, I have
    tried alternative data types but if I am able to use it in a
    "select" statement, I get the above error when the returned
    length exceeds 2,000 chars.
    Thanks
    Peter

    are u using oracle 7. varchar2 limit in 8 is 4000.

  • Use of boolean returning functions in a project

    Hello all gurus,
    in my project, we have a fairly important packaged functions that return boolean values. Working with these ones in pl/sql is very fine. But sometimes we need to reuse these functions in SQL, but no luck because bools are usable under pl/sql only and can't interact in any way in SQL statements. So the workaround should be to use these functions to return us some Y/N or 1/0 to emulate boolean behavior in SQL statements.
    Here what i tested with not luck:
    -- not work
    select r.role, sys.diutil.bool_to_int(dbms_session.is_role_enabled(r.role)) as is_role_enabled
    from   dba_roles r;
    -- not work
    select r.role
    from   dba_roles r
    where  sys.diutil.bool_to_int(dbms_session.is_role_enabled(r.role)) = 1;
    -- not work
    select t1.id,
           bool_to_char(my_bool_func(t1.x, t1.y, ...)) as is_something
    from   t1;
    -- not work
    select t1.id,
           sys.diutil.bool_to_int(my_bool_func(t1.x, t1.y, ...)) as is_something
    from   t1;The odd wrapping trick as a last resort solution is working....
    -- Works! Seems the only way, but a lot of wrapping work...
    create or replace function my_bool_func_wrap(p_x number, p_y number, ...) return varchar2 as
    begin
       return bool_to_char(my_bool_func(p_x, p_y, ...));
    end;
    select t1.id,
           my_bool_func_wrap((t1.x, t1.y, ...)) as is_something
    from   t1;I read a lot, but no elegant and working way.
    Is there a more standard, elegant universal way to call bool functions from SQL?
    Is creating a custom type visible and usable from both pl/sql and sql, if possible, a way to go?
    Any other pointers?
    For new development, is it good to make my boolean type returning functions using SQL compatible type like CHAR (Y/N) or NUMBER (1/0) ? It will make us less wrapping job, but more and less elegant bool handling code on the pl/sql side.
    What is the goal to have bool only in pl/sql and not usable in SQL? It's kind of a feature incompatibility in the same product. Strange...
    Thanks a lot
    Bruno

    brlav wrote:
    Finally, I'll have to dump the BOOLEAN return type to all our boolean functions and return char instead. With this I will be able to call then from SQL.... From this perspective, BOOLEAN is useless.I would not say that. Let's assume that you implement boolean in SQL as a single byte character string containing either Y or N, enforce that with a constraint and also add a not-null constraint to it.
    You simply define two PL functions (not usable from SQL) that deals with the conversion. You use the one function to change boolean to char before hitting the SQL engine, and the other to convert char to boolean when getting data from the SQL engine.
    As I/O routines are modularised, it means that you need to deal with these conversions once only when writing and once only when reading (per module).
    Simple example:
    SQL> create or replace function to_bool( c varchar2 ) return boolean is
      2  begin                                                            
      3          return( c = 'Y' );                                       
      4  end;                                                             
      5  /                                                                
    Function created.
    SQL>
    SQL> create or replace function bool_to_char( b boolean ) return varchar2 is
      2  begin
      3          if b then
      4                  return( 'Y' );
      5          else
      6                  return( 'N' );
      7          end if;
      8  end;
      9  /
    Function created.
    SQL>
    SQL> declare
      2          i       integer;
      3          b       boolean;
      4          flag    all_tables.temporary%type;
      5          tab     all_tables%rowtype;
      6  begin
      7          flag := bool_to_char(true);  
      8          select count(*) into i from all_tables where temporary = flag;
      9
    10          select t.* into tab from all_tables t where rownum = 1;
    11          b := to_bool( tab.temporary );
    12  end;
    13  /
    PL/SQL procedure successfully completed.
    SQL>

  • Using 'Function Returning SQL Query' with Flash charts

    I have created a pl/sql function that returns a SQL query as a varchar2 of this form:
    select null link
    <x value> value
    <Series1 y value> Series 1 Label
    <Series2 y value> Series 2 Label
    <Series3 y value> Series 3 Label
    from tablea a
    join tableb b
    on a.col = b.col
    order by <x value>
    If I now call the function from a Flash Chart Series SQL box with the Query Source Type set to 'Function Returning SQL Query' like this:
    return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'))
    it parses correctly and the page is saved; however, when I run the page I don't get any output - nor any error messages or other indication of a problem.
    Now, if I call the function in a SQL client, capture the SQL query output using dbms_output and paste that into the Flash Chart Series SQL box - changing the Query Source Type to SQL Query - and save the page it works fine when I run it and returns a multi-series flash chart.
    Can anyone suggest either;
    1. What have I might have missed or done wrong?
    2. Any way to usefully diagnose the problem...
    I have tried using the Apex debugger - which is very nice, by the way - but it doesn't provide any info on what my problem might be. I even tried writing my own debug messages from my function using the apex_debug_message package - got nothing...
    Thanks,
    Eric

    Hi Eric,
    Try expressing the source as this:
    begin
       return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'));
    end;That works fine for me, and if I take out the begin-end and the trailing semicolon from the return statement I get the same behavior as you.
    It does mention in the help for the source (only during the wizard though) that this source type has to be expressed that way, but I agree it would be helpful if the tool would validate for this format when 'Function Returning SQL Query' is used or give some sort of indication of the trouble. Anyway, this should get you going again.
    Hope this helps,
    John
    If you find this information useful, please remember to mark the post "helpful" or "correct" so that others may benefit as well.

  • Returning Mutliple Records using a function

    I followed the instructions as per askTom at http://asktom.oracle.com/~tkyte/ResultSets/index.html
    Created the package and created a fuction and it works if I do something like
    select find_dba_licenses('ALBERTSON') from dual;
    Now, the problem is that I want to use the function in the where clause and it's giving me an error.
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected - got CURSER
    Does anyone knows what it means?
    If I try casting like below I get the same error
    select license_id from t_license where license_id = (select cast(oda.find_dba_licenses('ALBERTSON') as number) from dual);
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got CURSER
    Thanks
    anyhelp will be appreciated.
    Juan

    I thought that using a function will be the easyest Wrong. The easiest is definitely a sub-query:
    SELECT * FROM licences
    WHERE licence_id IN
        (  SELECT licence_id FROM table_1
           WHERE trading_name = 'ALBERTSON'
           UNION ALL
           SELECT licence_id FROM table_2
           WHERE business_name = 'ALBERTSON')The above is a template, which you will need to tweak to fit your needs.
    If you really want to do that in a function you could consider using a PIPELINED function that returns an array of licence IDs and use a TABLE() function on that. But I wouldn't recommend it unless you have additional processing which cannot be done in a SELECT statement.
    What does it mean "between program units"?Between two discrete program, er , units. The canonical example is a database accessor for a web application. A Java bean (or whatever) passes parameters to a stored procedure (function) which executes a query and returns a resultset in the form of a ref cursor. Of course the program units can be two PL/SQL procedures but I think that is less common.
    Cheers, APC

  • Can I use the value returned from a Text Function in another Formula?

    I'm writing a report in Hyperion System 9 BI + Financial Reporting Studio version 9.2. I have 2 grids in my report.
    Grid1 Column A is set up as a text function using the function type - <<GetCell("Grid2", 1, a, 1)>>. I would like to use the values returned from this text function in Column A (Grid 1) in a formula in Column B (Grid 1).
    Is it possible to use the values returned in Column A of the text function in another formula? My report does not seem to recognize Column A as numerical values, even though the values to be returned are numerical.
    If so, how do I recognize the values in Column A Grid 1 as numerical values and not text?
    Thanks for any help you can offer!

    Hi Edson,
    Yes you need to use the CALC_ERROR macro function to be able to test whether the last macro function returned an error. CALC_ERROR will return an 'X' if there an error occured during the execution of the last macro function.
    You can use a macro similar to the following:
    IF
      CALC_ERROR( )
      = 'X'
          DO SOMETHING HERE
    ENDIF
    Let me explain how this works internally. The SAP system maintains a global variable g_flg_calc_error during the execution of macros in the planning book. The g_flg_calc_error variable will contain the value of f_calc_error that was set by the last macro function which executed. The ABAP coding of a planning book is something like this:
    data: g_flg_calc_error type /SAPAPO/FLAG.
    * SAP will pass g_flg_calc_error variable to all macro
    * functions. When SAP calls a macro function, it does
    * something like this.
    call function '/SAPAPO/MACRO_FUNCTION_HERE'
            exporting
              plob_values      = i_s_adv_plob_values
              sdp_book         = g_c_advf_sdp_book
              sdp_view         = g_c_advf_sdp_view
            tables
              cols_index       = i_t_cols
              value_tab        = l_t_value_tab
            changing
              f_calc_error     = g_flg_calc_error
    As you can see, the g_flg_calc_error variable
    is passed in the "changing" part of the call. The macro  function being called can then use the f_calc_error
    variable to change the value of the global
    g_flg_calc_error variable. In fact, the macro function being called can also check (by looking at the f_calc_error variable) if the last macro function reported an error.  The CALC_ERROR macro function just checks the value of f_calc_error parameter (w/c in fact is the value of the g_flg_calc_error variable) and returns "true/X" if the f_calc_error was set to true by the last macro function.
    Hope this helps in clearing things out

  • Using cursor function in sql statement

    hi all
    can anyone plss explain why and when we will use cursor function in a sql statement like this and what is the difference while executing this sql statement with cursor function in comparison of a simple sql statement----
    select
    department_name,
    cursor (
    select last_name
    from employees e
    where e.department_id = d.department_id
    order by last_name
    ) the_employees
    from departments d
    thnx in advance

    RTFM
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1452
    Cheers
    Sarma.

  • Problem in using aggregate functions inside case statement

    Hi All,
    I am facing problem while using aggregate functions inside case statement.
    CASE WHEN PSTYPE='S' THEN MAX(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ELSE SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) END,
    how can I achieve above requirement ? Con anyone help me.
    Thanks and Regards
    DG

    Hi All,
    Below is my query:
            SELECT
            CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT
            ELSE POS.PACCT || '-' || DECODE(POS.SYSTEMCODE,'GMI1','1', 'GMI2','2', 'GMI3','4', 'GMI4','3', '0') ||POS.PFIRM|| NVL(POS.POFFIC,'000') END,
            CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-')
            ELSE POS.PFIRM||POS.POFFIC||POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-') END,POS.SYSTEMCODE,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,POS.PEXCH||DECODE(POS.PSUBEX,'<NULL>',''),
            POS.PCURSY,
            CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) END ,
            NVL(POS.PSUBTY,'F') ,POS.PSTRIK,*SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ,SUM(DECODE(POS.PBS,2,ABS(POS.PPRTQ),0))* ,
            POS.PCLOSE,SUM(POS.PMKVAL) ,
            TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
            POS.UBS_ID,POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER ,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,TO_CHAR(POS.BUSINESS_DATE,'YYYYMMDD'),
            POS.SOURCE_GMI_LIB,
            --DECODE(POS.SYSTEMCODE,'GMI1','euro','GMI2','namr','GMI3','aust','GMI4','asia','POWERBASE','aust','SINACOR','namr',POS.SYSTEMCODE),
            DECODE(p_reportid,'RVPOS_SING','euro','RVPOS_AUSTDOM','aust','RVPOS_AUSTEOD','euro','RVPOS_GLBLAPAC','asia','POS_RV_SN','namr','POS_PB','aust',POS.SYSTEMCODE),
            POS.RIC,
            CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
            DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
            CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
            CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
            NVL(C.SSECID,POS.PCUSIP),
            NULL,
            POS.PYSTMV,
            POS.PMINIT,
            POS.PEXPDT,
            CASE WHEN POS.PSUBTY='S' THEN  SUBSTR(C.ZDATA2,77,1) ELSE NULL END,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
            FROM POSITIONS_WRK POS LEFT OUTER JOIN
            (SELECT * FROM CDS_PRODUCTS CP INNER JOIN FUTURE_MASTER FM ON
            (CP.STRXCH=FM.ZEXCH AND CP.SFC=FM.ZFC AND CP.BUSINESS_DATE = FM.BUSINESS_DATE )) C ON POS.PCUSIP = C.SCUSIP
            AND NVL(POS.PCUSP2,'X') = NVL(C.SCUSP2,'X')
            WHERE
            POS.PEXCH NOT IN ('A1','A2','A3','B1','B3','C2','D1','H1','K1','L1','M1','M3','P1','S1')
            AND (POS.PSBCUS IS NOT NULL OR POS.PCTYM IS NOT NULL OR POS.PSTYPE ='S')
            AND POS.BUSINESS_DATE = run_date_char
            GROUP BY
            POS.UBS_ID,POS.SYSTEMCODE,POS.RECIPIENTCODE,POS.BUSINESS_DATE,POS.PACCT,POS.PFIRM,POS.POFFIC,POS.PCUSIP,POS.PBS,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,
            POS.PEXCH,POS.PSUBEX,POS.PCURSY,
            CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2)  || SUBSTR(POS.PCTYM,1,4) END,
            NVL(POS.PSUBTY,'F') ,POS.PSTRIK,POS.PCLOSE,TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
            POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,POS.PSUBTY,POS.SOURCE_GMI_LIB,RIC,
            CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
            DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
            CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
            CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
            NVL(C.SSECID,POS.PCUSIP),
            POS.PYSTMV,
            POS.PMINIT,
            POS.PEXPDT,
            CASE WHEN PSUBTY = 'S'  THEN  SUBSTR(C.ZDATA2,77,1) ELSE NULL END;Now, could you plz help me in replacing the bold text in the query with the requirement.
    Thanks and Rgds
    DG
    Edited by: BluShadow on 16-May-2011 09:39
    added {noformat}{noformat} tags.  Please read: {message:id=9360002} for details on how to post code/data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Difficulty in creating a chart by using a function with a returned value

    Hi,
    I am having a problem in using own function to create chart a with a returned value as the chart. If not using the returned value, it works fine.
    Is this a known issue?

    If you share some code, we might be able to help you.

Maybe you are looking for

  • Create a PDF from a Flash page

    I need some help with a request from a client. I have created a form that a user fills out and the answers they give are added to a email as text. This works great but now the client wants the text answers in a PDF not just as text in an email. My qu

  • What software do i need to upgrade after leopard?

    I need to upgrade my software but am hesitant as to which one and if it will be costly. Please help.

  • Free adobe reader or compatible

    I have Bell fibe internet, windows 7, internet explorer 11 and am unable to open pdf files from the website in adobe free reader.  Could anyone explain this.  I was able to view pdf files before i got fibe internet.  Do you know any free readers that

  • Installing xcode 4.3.1 for lion is not working , it's opening the Xcode from the dmg file

    After installing the Xcode from the developer site for the lion and run it , the installation started perfect with out any problems , at the end a message pop to remove the old version of Xcode to trash , i have clicked OK , then clicked finish and t

  • After upgrade to lion iPhoto crashes

    Hi I have just upgraded to Lion.  When I try to edit a photo in iphoto (ilife) it crashes.  Here is the log.  I'd be grateful for any advice. Thanks Process:         iPhoto [965] Path:            /Applications/iPhoto.app/Contents/MacOS/iPhoto Identif