SYS_GUID()  SQL functions within XQuery

Is there any simple way to invoke regular SQL functions from within XQuery?
I would like to create an identifier attribute, and set the value to SYS_GUID(), but when I try to directly embed the function, it comes back saying:
ORA-19237: XP0017 - unable to resolve call to function - fn:SYS_GUID
select XMLQUERY('
<AgeCmf dtm="{current-dateTime()}" id="{SYS_GUID()}"/>
' RETURNING CONTENT) from dual;
I could dump the value into a temp table, or make it an input parameter via another function, but I am looking for something simple within a SQL call.
Thanks,
HW

Maybe this?:
michaels>  select xmlquery('<AgeCmf dtm="{current-dateTime()}" id="{s}"/>' passing xmltype('<s>' || sys_guid() || '</s>') returning content) x from dual
X                                                                                                 
<AgeCmf dtm=" 2007-06-20T07:05:19.515000+02:00" id="6304A70F5C104ACB98C69EEB3D47891C"></AgeCmf>   

Similar Messages

  • How to use PL/SQL Function after registering

    Hi,
    I have successfully registered a PL/SQL Function within Discw Admin. But i don't know how to use it further??? Please let me know the steps to use it in folders (admin) or in plus.
    Actually i have a stored procedure which fetches the records from the base tables and i have to develop a report based on that data.
    Please reply ASAP.
    Thanks,
    Jay

    Hi Jay,
    If this function is a stored procedure in the right schema, you can access this function in your custom SQL like any other database functions (e.g. SUM, AVG, MAX, etc).
    If you are not using a custom folder (ie. your own SQL), you can access this function in the workbook (Tools --> Calculations --> New Button --> Select Function Radio Button --> All Functions or Database Folders.). This calculation wil become a new column in the workbook.
    Regards,
    John

  • Queries on pl/sql tables within a function

    hi,
    how can i execute regular sql-queries within a function on a pl/sql table which the function has recieved as a parameter ? i have tried quite a bit and always get type mismatches or internal errors. anybody has a good example on this ?
    thanks in advance,
    stephan

    hi,
    okay, i will not post the actual code i have, because it won't make too much sense out of the context, but here are the relevant parts...
    i have a few object definitions that represent the records of the three tables (two input and one output)...
    create type t1 as object (...);
    create type t2 as object (...);
    create type t3 as object (...);
    and a package with the table definitions
    create or replace package t_defs as
    type tab_t1 is table of t1;
    type tab_t2 is table of t2;
    type tab_t3 is table of t3;
    end t_defs;
    and here is a rough sketch what the function should look like later:
    CREATE OR REPLACE FUNCTION some_function (
    tab1 IN t_defs.tab_t1, tab2 IN t_def.tab_t2)
    RETURN t_defs.tab_t3 PIPELINED IS
    TYPE refcur IS REF CURSOR;
    cur0 refcur;
    curr_rec t3 := t3(NULL, ....);
    BEGIN
    open cur0 for 'here is the statement i could not do';
    LOOP
    FETCH cur0 INTO curr_rec.....;
    EXIT WHEN cur0%NOTFOUND;
    . -- (manipulate the record) --
    PIPE ROW(curr_rec);
    END LOOP;
    RETURN;
    END;

  • Function "xmlnamespaces" gives PL/SQL: ORA-19102: XQuery string literal....

    Below is my script that you can run successfully, and i have version Oracle 11g.
    Script has Xml namespace as constant at the moment there:
       xmlnamespaces(default 'http://elion.ee/webservices/Sales/Dynamics')I want to have a variable there instead, like this:
       xmlnamespaces(default    l_sSOAP_Namespace )But if i add such variable there i get such error:
    PL/SQL: ORA-19102: XQuery string literal expectedCan i avoid such error somehow and use still the namespace as variable somehow, not the constant?
    My script:
    declare
       l_resp varchar2(4000);
       l_sSOAP_Namespace varchar2(4000) := 'http://elion.ee/webservices/Sales/Dynamics';
    begin
      l_resp :=
      '<ns0:FindItemMetaDataResponse xmlns:ns0="http://elion.ee/webservices/Sales/Dynamics">
            <ns0:ItemMetaData>
              <ns0:ItemMetaData>
                <ns0:ItemGroupId>IT.LS.VS.DSL</ns0:ItemGroupId>
                <ns0:ItemGroupName>IT lisad võrguseadmed DSL</ns0:ItemGroupName>
                <ns0:ItemId>DSLGP603</ns0:ItemId>
                <ns0:ItemName>ADSL SIP ST546</ns0:ItemName>
               <ns0:ItemType>Item</ns0:ItemType>
               <ns0:MacAddressMandatory>No</ns0:MacAddressMandatory>
               <ns0:SalesUnit>tk</ns0:SalesUnit>
               <ns0:SerialNumMandatory>No</ns0:SerialNumMandatory>
               <ns0:TaxValue>20.00</ns0:TaxValue>
             </ns0:ItemMetaData>
             <ns0:ItemMetaData>
               <ns0:CurrencyCode>EUR</ns0:CurrencyCode>
               <ns0:ItemGroupId>KL.PS.HGW</ns0:ItemGroupId>
               <ns0:ItemGroupName>Ruuterid</ns0:ItemGroupName>
               <ns0:ItemId>DSLGP603NY</ns0:ItemId>
               <ns0:ItemName>ADSL stardikomplekt Thomson ST546 stardi</ns0:ItemName>
               <ns0:ItemType>Item</ns0:ItemType>
               <ns0:MacAddressMandatory>No</ns0:MacAddressMandatory>
               <ns0:PriceWithoutVAT>12.78</ns0:PriceWithoutVAT>
               <ns0:PriceWithVAT>15.34</ns0:PriceWithVAT>
               <ns0:SalesUnit>tk</ns0:SalesUnit>
               <ns0:SerialNumMandatory>Yes</ns0:SerialNumMandatory>
               <ns0:TaxValue>20.00</ns0:TaxValue>
             </ns0:ItemMetaData>
           </ns0:ItemMetaData>
         </ns0:FindItemMetaDataResponse>';
      for rec in
         with xml_doc (doc) as (
            select xmlparse(document
            l_resp)
           from dual
         select x.*
         from xml_doc t
            , xmltable (
                xmlnamespaces(default 'http://elion.ee/webservices/Sales/Dynamics')
              , '/FindItemMetaDataResponse/ItemMetaData/ItemMetaData'
                passing t.doc
                columns
                CurrencyCode varchar2(4000) path 'CurrencyCode',
                ItemGroupId varchar2(4000) path 'ItemGroupId',
                ItemGroupName varchar2(4000) path 'ItemGroupName',
                ItemId varchar2(4000) path 'ItemId',
                ItemName varchar2(4000) path 'ItemName',
                ItemType varchar2(4000) path 'ItemType',
                MacAddressMandatory varchar2(4000) path 'MacAddressMandatory',
                PriceWithoutVAT varchar2(4000) path 'PriceWithoutVAT',
                PriceWithVAT varchar2(4000) path 'PriceWithVAT',
                SalesUnit varchar2(4000) path 'SalesUnit',
                SerialNumMandatory varchar2(4000) path 'SerialNumMandatory',
                TaxValue varchar2(4000) path 'TaxValue'         
              ) x
      ) loop
        dbms_output.put_line('ItemId=' || rec.ItemId);
      end loop;
    end;
    /* Output:
    ItemId=DSLGP603
    ItemId=DSLGP603NY
    */Edited by: CharlesRoos on 11.04.2013 14:46

    How badly do you need the namespace to be dynamic ?
    Is it likely to change that frequently?
    The reason for having to hardcode namespace declarations and XQuery string in general is optimization.
    By doing so, the CBO is able to analyze the whole expression and apply optimization techniques such as XQuery rewrite.
    As said, use dynamic SQL if you really have no way around this requirement.
    The other solution I'm reluctent to expose here is to make the whole thing namespace-free by using construct such as "*:element-name" or "*[local-name()="element-name"]".
    Both will use XQ functional evaluation and perform worse.

  • Region source (PL/SQL function body returning SQL query)

    Hi, guys.
    Here is what i try to do:
    Create a region of type SQL Query (PL/SQL function body returning SQL query). In the source area i tried to put this:
    DECLARE
    v_new VARCHAR2(10);
    v_SQL varchar2(32000);
    BEGIN
    v_new := :P102_HDN_NEW;
    -- htp.p(v_new);
    IF v_new = 'N-Set' THEN
    v_SQL := 'select ' ||
    ELSIF v_new = 'Y-Set' THEN
    v_SQL := 'select ' ||
    END IF;
    RETURN v_SQL;
    END;
    And here is the reply from APEX:
    1 error has occurred
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. The query can not be parsed, the cursor is not yet open or a function returning a SQL query returned without a value.
    Now.
    1. Variable is set with the right value.
    2. Each statement (separately) returns SQL that works with no problems
    3. Problem occures if i try to put IF statement around the SQL creation.
    4. If i select "Use Generic Column Names (parse query at runtime only)" instead of "Use Query-Specific Column Names and Validate Query" then the script returns SQL properly, however report's column names are set to Col1, Col2,Col3 ......
    Thnks in advence
    Mike

    OK. Here is enire statement:
    DECLARE
    v_new VARCHAR2(10);
    v_SQL varchar2(32000);
    BEGIN
    v_new := :P102_HDN_NEW;
    htp.p(v_new);
    IF v_new = 'N-Set' THEN
    v_SQL := 'select ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
    'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
    'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
    'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
    'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
    'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
    'from ' ||
    'tbl1 c, ' ||
    'tbl2 ld ' ||
    'where c.code = ld.code ' ||
    'and c.type = ''TYPE1'' ' ||
    'and c.active = ''Y'' ' ||
    'order by c.sorting ';
    ELSIF v_new = 'Y-Set' THEN
    v_SQL := 'select ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(12,''All Categories'') level, ' ||
    'apex_item.checkbox(1, c.option_1, decode(c.option_1,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
    'apex_item.checkbox(2, c.option_3, decode(c.option_3,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
    'apex_item.checkbox(3, c.option_2, decode(c.option_2,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
    'apex_item.checkbox(4, c.option_4, decode(c.option_4,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
    'DECODE(c.code, ''AAA'', NULL,''Options by AAA'') link_change, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
    'from ' ||
    'tbl1 c ' ||
    'where 1 = 1 ' ||
    'and c.type = ''TYPE1'' ' ||
    'and c.active = ''Y'' ' ||
    'order by c.sorting ';
    END IF;
    RETURN v_SQL;
    END;
    If i put just this
    DECLARE
    v_new VARCHAR2(10);
    v_SQL varchar2(32000);
    BEGIN
    v_new := :P102_HDN_NEW;
    htp.p(v_new);
    v_SQL := 'select ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
    'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
    'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
    'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
    'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
    'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
    'from ' ||
    'tbl1 c, ' ||
    'tbl2 ld ' ||
    'where c.code = ld.code ' ||
    'and c.type = ''TYPE1'' ' ||
    'and c.active = ''Y'' ' ||
    'order by c.sorting ';
    RETURN v_SQL;
    END;
    it works fune...

  • Return value from function within package

    Hi,
    There is a function within a pl/sql package that I am trying to get data from. The problem is that the data returned can be up to 32,767 chars (varchar2 limit).
    It accepts 3 input parameters and returns on varchar2.
    The only way I can get it to work is using this syntax:
    ==================================
    variable hold varchar2(4000);
    call TrigCodeGenerator.GenerateCode(VALUE1', 'VALUE2','VALUE3') into :hold;
    print hold;
    =====================================
    However, if the data returned is greater than 4000 then I get this error:
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 1
    I can't increase the size of the variable (hold) as there seems to be a limitation on this type of variable.
    Also, I am running this in sql plus worksheet. Will it limit the display of the data (assuming, that someone can get the whole 32,767 chars displayed back) ?
    Thanks in advance,
    Ned

    Never mind,
    I declared the variable hold as clob and set the long and longchunksize parameters to 100,000 and it seems to work.

  • Function within package error

    Hi friends,
    I have a package called xxhw_ams_utils with a function in it get_salary
    When i tried to execute that function within the package like the below manner means, im getting error like
    ORA-00904: "XXHW_AMS_UTILS"."GET_SALARY": invalid identifier
    select apps.xxhw_ams_utils.get_salary(1072) from dualwhere 1072 is the assignment id that im passing for testing purpose.
    This is the actually the get_salary function which is inside the package xxhw_ams_utils coding
    FUNCTION get_salary
    (p_asg_id IN NUMBER)
        RETURN VARCHAR2 IS
    l_gross VARCHAR2(20);
    l_basic VARCHAR2(20);
    BEGIN
    select eev.screen_entry_value
    into l_basic
           from   pay_element_entry_values_f eev,
                  per_pay_bases              ppb,
                  pay_element_entries_f       pe
           where  ppb.pay_basis_id  +0 = 61
           and    pe.assignment_id     = 1072
           and    eev.input_value_id   = ppb.input_value_id
           and    eev.element_entry_id = pe.element_entry_id
           and    sysdate between
                            eev.effective_start_date and eev.effective_end_date
           and    sysdate between
                            pe.effective_start_date and pe.effective_end_date;
    EXCEPTION
    WHEN OTHERS THEN RAISE;
    END; Suppose if i executed like the below manner means, i getting the correct result
    select eev.screen_entry_value
    --into l_basic
           from   pay_element_entry_values_f eev,
                  per_pay_bases              ppb,
                  pay_element_entries_f       pe
           where  ppb.pay_basis_id  +0 = 61
           and    pe.assignment_id     = 1072------------------------------------>assignment id (that im passing)
           and    eev.input_value_id   = ppb.input_value_id
           and    eev.element_entry_id = pe.element_entry_id
           and    sysdate between
                            eev.effective_start_date and eev.effective_end_date
           and    sysdate between
                            pe.effective_start_date and pe.effective_end_date;Suppose if i execute like the below means it is returning error like invalid character.
    select apps.xxhw_ams_utils.get_salary(1072) from dualWhy might be the problem friends.
    Brgds,
    Mini

    Hi Giri,
    Thanks yes i didnt mentioned that function get_salary in the package specification and now the package is compiled successfully,
    But when i tried to execute i get the error like
    ORA-06503: PL/SQL: Function returned without value
    ORA-06512: at "APPS.XXHW_AMS_UTILS", line 177when i execute like
    select apps.xxhw_ams_utils.get_salary(1072) from dualBrgds,
    Mini

  • How to user HTMLDB_COLLECTIONS in a PL/SQL function?

    Hi!
    I am trying to validate/check that an item from an updateable report is not in a collection before I add the item. I wrote a PL/SQL function to do this. It appears that a "normal" PL/SQL function cannot correctly see the HTMLDB_COLLLECTIONS view. The idea for this was posted to the forum about using a decode statement and a function to detemine whether to display the link value or not for each row. If an item has been added to the collection I want to not display the link. If the item is removed from the collection I need to redisplay the link.
    I have tried validations but they depend on the page being resumbitted. And I tried to force that using a branch where the request was = 'ADD'. However everytime I set it up as a redirect to a URL it kept resetting the branch to a 'branch to a page within this application'.
    Any suggestions on how to check the HTMLDB_COLLECTIONS before it is updated?
    This is V2.0.
    Thanks! Dave Venus

    Hi!
    Yes things work much better when run from within the "application". I had been trying to test the code from both SQL*Plus and from the SQL WorkShop.
    The problem I was having even within the application was that I was getting back NULL return values. So I put some exception handling into the code and trapped the
    data_not_found and others exceptions. I also had SQL%NOTFOUND code in my function. It appears the SQL%NOTFOUND was not being processed and the exception code was. I can paste the code I was using here if you want.
    I went another way around the problem and rewrote the query (esp. the where clause) for the report and it seems to be doing what I need now. I would love to get the function working and understand how it should have worked so that I can use that functionallity in other applications.
    Thanks!
    Dave Venus

  • SQL Query (pl/sql function body returning Sql query)

    Hi All,
    I have created a region of "SQL Query (pl/sql function body returning Sql query)" type and it is working fine , but when I am migrating(export /import) this application from development to systest environment ,
    It gives error for this region :
    Error ERR-1101 Unable to process function body returning query.
    OK
    ORA-06550: line 1, column 52: PLS-00306: wrong number or types of arguments in call to 'FU_TRADE_REPORT_QUERY' ORA-06550: line 1, column 45: PL/SQL: Statement ignored
    Any pointer ...why this is happening.
    Thanks
    Dikshit

    If your function is a stored function that is called from within APEX (function body not coded into the app itself), have you made sure that the function has been created and compiles ok prior to installing your apex app.
    If there are some dependency issues between other PL/SQL units or database objects that are causing your function not to be compiled, you apex install will fail as you are trying to reference an uncompelled bit of pl/sql.
    Let me know how you get on
    Regards
    Duncan

  • Query on Reoprts-pl/sql function body returning sql query

    Hi,
    I am facing a starnge problem.. and would like to know the reason for it.
    The situation is as follows:
    I have a report (pl/sql function body returning sql query based). My query is as follows:
    declare
    l_query1 varchar2(2000);
    begin
    if (:P102_min_value is not null and :P102_max_value is null) then
    l_query1 := 'select decode(:P102_date,'1',date1) Transaction_Date, decode(:P102_first_name,'2',first_name) First_Name from (
    select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=:P102_min_value
    return (l_query1);
    end if;
    end;
    This returns the error as :
    1 error has occurred
    Function returning SQL query: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the generic columns checkbox below the region source to proceed without parsing.
    (ORA-06550: line 7, column 20: PLS-00103: Encountered the symbol "1" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset member SUBMULTISET_)
    How do i correct this? am i right in thinking that the single quotes indicating a string within a select query is creating the problem? Beacuse if i use an sql query report and use the following query, it is working fine...
    select
    decode(:P102_date,'1',date1) Transaction_Date,
    decode(:P102_first_name,'2',first_name) First_Name
    from (
    select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=:P102_min_value
    But i need to write pl/sql function, so that multiple report can be returned based on different conditions. Please guide me.
    Thanks,
    Sumana

    Does that mean that both in if and else we need to have same columns selected?
    if thats the case.. any idea how i can implement it in my code. The situation here is that the columns that need to be selected are dynamic and keep on changing...
    if i try to implement like this and run the page, it gives the following error:
    Query is:
    declare
    l_query1 varchar2(4000);
    begin
    if apex_application.get_current_flow_sgid(:APP_ID) = apex_application.get_sgid then
    if (:P102_min_value is not null and :P102_max_value is null) then
    l_query1 := 'select decode(' || :P102_date|| ',''1'',date1) Transaction_Date, decode(' || :P102_first_name || ',''2'',first_name) First_Name from (
    select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=' || :P102_min_value ||'
    elsif (:P102_min_value is null and :P102_max_value is not null) then
    l_query1 := 'select decode(' || :P102_date|| ',''1'',date1) Transaction_Date, decode(' || :P102_first_name || ',''2'',first_name) First_Name from (
    select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=' || :P102_max_value ||'
    else
    l_query1 := 'select date1,first_name from MORTGAGE_LOAN_LEADS where rownum = 1';
    end if;
    else
    l_query1 := 'select date1,first_name from MORTGAGE_LOAN_LEADS where rownum = 1';
    end if;
    return l_query1;
    --dbms_output.put_line( l_query1);
    end;
    The Error is:
    failed to parse SQL query:
    ORA-00936: missing expression
    If i try to run the same in command prompt, it always goes to the else part... (else of outer if)

  • SQL Query (PL/SQL function body returning SQL query) when using to_char

    we are trying to build a report page of Type SQL Query (PL/SQL function body returning SQL query).
    our query is so simple, we need to extract the month from the recording_date column.
    declare
    l_query varchar2(1000);
    begin
    l_query:='select to_char(recording_date,'MM')from re_productive';
    return l_query;
    end;
    but we are having the following problem for this query
    Function returning SQL query: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the generic columns checkbox below the region source to proceed without parsing.
    (ORA-06550: line 4, column 42: PLS-00103: Encountered the symbol "MON" when expecting one of the following: . ( * @ % & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like between || multiset member SUBMULTISET_ The symbol ". was inserted before "MON" to continue.)
    Notes:
    1-the query is correct and it was tested under Toad and SQL Plus.
    2- we tried Use Generic Column Names (parse query at runtime only) option but we get the same problem.
    any quick help please.

    Hi
    You haven't escaped your quotes in the string. Try this...
    DECLARE
    l_query VARCHAR2(32767);
    BEGIN
    l_query:= 'select to_char(recording_date,''MM'') from re_productive';
    RETURN l_query;
    END;Cheers
    Ben

  • SQL functions in Script Logic

    I want to build a script logic but the dimensions that I am testing do not have the fields I want in the format I want. In my case I would like to test the "Start" property in the Employee dimension. The property represents the employee start date but is a var char in the format dd.mm.yyyy rather thna a date field. I want to test whether it is five years prior to the date being processed.
    My time dimension has a year property and a monthnum property. Each of these are varchar. I can write SQL that would convert these to a date and compare them with the start property on the employee dimension.
    Can I  do iinsert SQL functions in the When statement. An example would be
    *When convert(datetime, substring(employee.start,4,2) + '/' + substring(employee.start,1,2) + '/' + substring(employee.start,7,4))
    Can I use  SQL functions in the Is statement? An example would be
    *Is <DateAdd(YY,-5 , convert(datetime, Time.Monthnum + '/01/'' + time.year)
    Finally when I use such techniques and look at the log by using "show log" in the logic debugger I see no reference to the SQL I used. It is as if the generated SQL has not made use of my functions. Instead all I seee are the extract statements from the three fact tables. Is this normal? Is there a way to see what SQL is really being generated and run?
    At the moment it seems my only option is to make changes, try running it and hope I get an output. If no records are written I can't be sure whether it is because embedding SQL function is not supported or because I have made some other error.

    No, the "BPC SQL" script logic doesn't allow for this extensive use of real SQL within the scripting syntax. As a concept, it's best to think of "BPC SQL" script logic as, "this unique BPC logic syntax will generate real SQL code when it's executed."
    There's very little real SQL that you can use within the syntax itself, and definitely not within the WHEN or IF statements.  Nothing like cast, convert, substring, etc. (Except you CAN use these, a little bit, in a *SELECT statement. But I don't see how that will solve your current problem.)
    Plus, when you consider how the logic engine processes a set of data, it's helpful to think of it in terms of selects & reading through a recordset. So in that regard, a SQL background can be helpful, in understanding the concepts. (Sort of helpful, except when it confuses you, or frustrates you since you don't have all the power you want.)
    Anyway, to solve your problem, you might be able to restate the problem, and then use something like this code, which is valid syntax:
    *WHEN TIME.TIMEID
    *IS >= VERSION.FirstPlanMonthTimeID
    In this case, FirstPlanMonthTimeID is set up in the version dimension as, for example, 20090400 (representing 2009.APR). This timeID is set by BPC automatically when processing the time dimension, and I need to ensure that my Version property value is set to match it.
    A key point is that in BPC fact tables, the time dimension is stored as TIMEID (not ID, unlike all the other dimensions), and can be used for comparative evaluation in script logic WHEN/IF. The comparison property needs to be stored as an 8-digit integer value. If your time dimension has days in it (along with months), check the TIMEID after processing, and you should see the pattern for assigning values to TIMEID for days and months, etc.
    Normally, TIMEID is assigned pretty sensible and stable values. If it doesn't meet your logic requirements, you can create another property (be careful of USERTIMEID, since that has a specific purpose in the system which I've never fully understood) and assign that whatever (integer) values make sense.

  • How to use Pl/Sql function in Discoverer report

    Hi Everybody,
    Would you be able to provide a workflow/guidance how to use sql function in Discoverer right from creating the function using PLSQL Developer.
    (I am new to Oracle environment... prev. worked as analyst with Microsoft Access... took PL/Sql class in school a few years ago)
    We are using Discoverer Desktop.
    a) Just emailed dba for permission to create pl/sql function.
    b) Recently got Discoverer Administrator installed on my pc.
    can you pls add to the list:
    c)....
    d)....
    etc.?
    tx for your help, sandra

    Hi Kranthi,
    Thx for your warm words....
    The links you provided are great! Thx soooo much!
    Thanks to you and the rest of forum members, am able to use what you've all taught me
    with other Discoverer reports.... so i was able to do more on my own....
    About a month ago, I got access to Discoverer Admin, and was able to paste SQL to create a custom folder.
    Then i joined the custom folder to an existing baseline folder.
    I have found that sometimes when I use calc within a calc when the calcs use analytic functions, that Discoverer
    just displays null in the column. I thought that maybe instead I could create my own function as a work-around.
    I wrote IT for permissions to create views, functions etc. Hopefully, they'll approve and can move toward learning
    pl/sql functions for Discoverer.
    tx again, sandra

  • 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?

  • How to use SQL function in Tabular Form

    Edited by: JuniorNewbi on 03-Nov-2009 08:15

    Hi
    I want to have a Tabular Form in which the Report Source sql statement is retrieved via an SQL function, so that the resulting report can show a variable number of columns and column names.
    The following great web site shows just the kind of thing i'm trying to do (Tabular Form Dynamic):
    http://htmldb.oracle.com/pls/otn/f?p=31517:195:518536699796436::NO:::
    However, as an Apex newbie, i don't know how to invoke the SQL function from within the page. The "Report Source" appears to only allow a static "select...." style of entry.
    I don't have access to the Denes Kubicek's workspace so don't know how he would have invoked his PL/SQL Function.
    Can anyone help?
    Thanks in advance!
    Edited by: JuniorNewbi on 03-Nov-2009 08:46

Maybe you are looking for