Usage SQL functions in View

Hi,
I need to create a SQL View in Java Dictionary component. Is it possible to use SQL functions like "UPPER", "LCASE" and so on in SELECT statement? For example I need to divide one column in table with type of TIMESTAMP on two columns in View with types DATA and TIME. But when I try to create a View in Java Dictionary like:
CREATE VIEW "Z_TMP_DOMAIN_VIEW"
    ("Z_TMP_DOMAIN_ID","NAME")
AS SELECT
    "a"."ID", left("a"."NAME",30)  "name"
FROM
    "Z_TMP_DOMAIN" "a"
The build failed with the error:
Z_TMP_DOMAIN_VIEW': View  is not generated
     [ddgen] [Error]   DtDbView 'Z_TMP_DOMAIN_VIEW': View statement is incorrect: CREATE VIEW "Z_TMP_DOMAIN_VIEW"
     [ddgen]     ("Z_TMP_DOMAIN_ID","NAME")
     [ddgen] AS SELECT
     [ddgen]     "a"."ID", left("a"."NAME",30)  "name"
     [ddgen] FROM
     [ddgen]     "Z_TMP_DOMAIN" "a"
Perhaps someone knows how can I work out  or work around this problem?

Hi,
I need to create a SQL View in Java Dictionary component. Is it possible to use SQL functions like "UPPER", "LCASE" and so on in SELECT statement? For example I need to divide one column in table with type of TIMESTAMP on two columns in View with types DATA and TIME. But when I try to create a View in Java Dictionary like:
CREATE VIEW "Z_TMP_DOMAIN_VIEW"
    ("Z_TMP_DOMAIN_ID","NAME")
AS SELECT
    "a"."ID", left("a"."NAME",30)  "name"
FROM
    "Z_TMP_DOMAIN" "a"
The build failed with the error:
Z_TMP_DOMAIN_VIEW': View  is not generated
     [ddgen] [Error]   DtDbView 'Z_TMP_DOMAIN_VIEW': View statement is incorrect: CREATE VIEW "Z_TMP_DOMAIN_VIEW"
     [ddgen]     ("Z_TMP_DOMAIN_ID","NAME")
     [ddgen] AS SELECT
     [ddgen]     "a"."ID", left("a"."NAME",30)  "name"
     [ddgen] FROM
     [ddgen]     "Z_TMP_DOMAIN" "a"
Perhaps someone knows how can I work out  or work around this problem?

Similar Messages

  • Using HANA SQL Functions in select list of CDS Views

    Dear Expert,
    Kindly please let me know if we can use the HANA SQL Function (Ex: ADD_DAYS, SECONDS_BETWEEN) in the select list of CDS Views?
    If I create a CDS like below I get error that timestamp is not supported.
    For Example:
    @AbapCatalog.sqlViewName: 'ZMR_H_CA'
    @EndUserText.label: 'CAG A'
    define view viewname
    with parameters start_ts:abap.dec( 15, 0 ) , end_ts:abap.dec( 15, 0 )
    as select from table {
    key resource_key,
    TO_TIMESTAMP(begtstmp) as start_tmp,
    TO_TIMESTAMP(begtstmp) as end_tmp
    where
    (begtstmp > $parameters.start_ts or endtstmp > $parameters.start_ts )
    and
    (begtstmp < $parameters.end_ts or endtstmp < $parameters.end_ts )
    Thanks,
    Giri

    Hi Giri,
    the list of provided features can be found in the ABAP Language Documentation (F1 in the CDS View).
    As CDS in ABAP is abstracted from the database layer, the database features are not directly accessible. That means, you cannot use any HANA or MaxDB feature available. So the answer to your question is no. The reason for this is, that ABAP CDS views can be created on all SAP-supported databases, hence, we can only provide those features, supported by all databases.
    Having said this, there are some exception, e.g. the CDS views with input parameters, which are not supported by all databases. In these cases, you'd have to additionally use the utility class CL_ABAP_DBFEATURES (see http://scn.sap.com/community/abap/blog/2014/10/10/abap-news-for-740-sp08--abap-core-data-services-cds) for more details.
    Best,
      Jasmin

  • Materialized View with column based on PL/SQL function returning object

    I have the following problem - it is known that materialized view wants PL/SQL functions used in it to be DETERMINISTIC. And it appears that a function which returns SDO_GEOMETRY cannot be DETERMINISTIC - I can add DETERMINISTIC modifier to my function which returns sdo_geometry based on USNG grid ID and save the package, and it compiles and runs fine with regular queries, but when it comes to materialized view (mview), the following error is thrown:
    ORA-12018: following error encountered during code generation for "SCHEMA"."MVIEW_NAME"
    ORA-00932: inconsistent datatypes: expected NUMBER got MDSYS.SDO_GEOMETRY
    Looks like DETERMINISTIC modifier is not fully supported for object types. I have tried to use SDO_CS.FROM_USNG Oracle's function, and it appeared that this function is also non-deterministic - I cannot refresh mview with P or F on-demand refresh method (see http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14223/refresh.htm#i1008349 for a list of on-demand refresh methods). Without that function I can refresh mview with P or F flags.

    Hi,
    Yes, the Chart Series can be based on "Function Returing SQL Query" and the "SQL" would be something like:
    DECLARE
    vSQL VARCHAR2(1000);
    BEGIN
    vSQL := 'SELECT NULL LINK, ENAME LABEL, SAL VALUE FROM EMP ORDER BY ENAME';
    RETURN vSQL;
    END;You should tick the "Save query without validation" underneath that. Without this, there is a validation error - the ; at the end is required to get the chart to function correctly but the validator sees this as an error.
    You would need to create this separately from the report. No matter how you did it, the chart would still run a SQL statement to generate the output. If you wanted to use the "same data", then you could create a collection using the PL/SQL and base both the report and the chart on the collection instead.
    Andy

  • How to find out PL/SQL function usage in Discoverer workbooks?

    We have to make changes to one PL/SQL function that has been registered in Administrator. Is it possible to find out in which reports the function is used? The function is called in calculations and it returns certain time information. We have to add one argument to the function and therefore have to change calculations where the function is called. We have too many workbooks to manually check them all.
    I am aware how to find out which folders and items are used in workbooks but can't find the same information about functions. We are using Discoverer 10.1.2.2
    Thanks in advance!

    Hi,
    If you calculation is in the EUL you can look at the item dependencies, but if your calculation is in the workbook there is no way other than using the workbook dump (d51wkdmp.exe) utility or opening the workbook and manually checking.
    You might want to consider overlaying the PL/SQL function definition so that there are 2 variants of the function. You can then add the extra parameter as an optional parameter in Discoverer. The correct variant will be called depending on how many parameters are used.
    Hope that helps,
    Rod West

  • Interactive Report with PL/SQL Function Source

    Is it possible to create interactive report with PL/SQL function source returing a query? If not, has anyone done any work to simulate the interactive reporting feature for a normal report using API?

    I haven't tried that before but you could:
    1. create a collection from your result set returned by a dynamic query,
    2. create a view on that collection,
    3. use the view in your interactive report.
    The usability of this proposal depends from a question how "dynamic" your query is - does it always have the same number of columns or not.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • 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

  • Using Sql Functions in Crystal Reports

    Can SQL table-valued functions be used in Crystal Reports?  The only options I see in the Database Expert are Tables, Views, and Stored Procedures.

    Hi Dan,
    Are you referring to user-defined SQL functions? If yes, then these are not accessible in Crystal Reports.
    You would need to create a stored procedure which calls the function and does the processing and use this procedure in CR.
    - Abhilash

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

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

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

  • Create sequence, function and view all at once -script or something similar

    Hi I would like to know in what way can I write a script or something like that which would define names for a sequence, function and a view in the beginning (for example TEST_SEQ, TEST_FJ, TEST_VIEW...) and after that create this sequence, function and view with definitions like
    CREATE SEQUENCE  TEST_SEQ
    MINVALUE 1 MAXVALUE 999999999999999999999999999
    INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE;
    create or replace FUNCTION TEST_FJ RETURN NUMBER AS
    tmp number;
    BEGIN
    select TEST_SEQ.NEXTVAL  into tmp from dual
    RETURN tmp;
    END TEST_FJ;
    and so on...
    In the end I would also like to grant some rights on these objects I just created:
    grant select on TEST_SEQ to public;
    grant execute on TEST_FJ to public;
    So my question is how to package all these things together so I can execute them from a single file in SQL Developer, and if i need to change the names of these tables I want do it in one place in the beginning of this script (or something like a script, I'm not sure what)...
    Thanks in advance!

    hi,
    hope help you...
    this is my basic generic solution...
    create or replace procedure createSequence( psequenceName in varchar2 ) is
    begin
    execute immediate 'create sequence ' || psequenceName ;
    execute immediate 'grant select on ' || psequenceName || ' to public ';
    end ;
    create or replace function getNextVal( psequenceName in varchar2 ) return number is
    queryText varchar2(100) := 'select <sequence_name>.nextval into :next_value from DUAL' ;
    next_value number ;
    begin
    queryText := replace(queryText,'<sequence_name>',psequenceName);
    execute immediate queryText into next_value ;
    return( next_value ) ;
    end ;
    Edited by: edogt on Nov 27, 2008 5:33 AM
    Edited by: edogt on Nov 27, 2008 5:35 AM
    Edited by: edogt on Nov 27, 2008 5:35 AM

  • 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

  • How to use sql call a pl/sql function

    Hi there,
    I have a pl/sql function package as below:
    Create or Replace package test10 as
    P_DESFORMAT VARCHAR2(10);
    DESFORMAT VARCHAR2(10);
    function m_tot_u1Formula(m_o_uns number,m_t_uns number,m_v_uns number)return NUMBER ;
         function m_tot_res1Formula(m_o_res number,m_t_res number)return NUMBER;
         function m_occ_u1Formula(m_o_uns number,m_t_uns number)return NUMBER ;
         function m_onrpun1Formula(m_o_uns in number,m_o_res in number)return NUMBER ;
         function m_tenpun1Formula(m_t_res in number,m_t_uns in number)return NUMBER ;
         function m_occpun1formula(m_occ_u in number, m_tot_res in number) return number ;
         function m_vac_rate1formula(m_v_uns in number,m_tot_u in number) return number;
         function m_onrpha1Formula(m_o_res in number,m_area in number) return NUMBER;
         function m_tenpha1Formula(m_t_res in number,m_area in number)return NUMBER ;
         function m_occpha1Formula(m_area in number,m_tot_res in number)return number;
         function P_DESFORMATValidTrigger return boolean;
    END test10;
    CREATE OR REPLACE PACKAGE BODY test10 AS
    function m_tot_u1Formula(m_o_uns number,m_t_uns number,m_v_uns number)return NUMBER is
    begin
    RETURN m_o_uns + m_t_uns + m_v_uns;
    end;
    function m_tot_res1Formula(m_o_res number,m_t_res number)return NUMBER is
    begin
    RETURN m_o_res + m_t_res;
    end;
    function m_occ_u1Formula(m_o_uns number,m_t_uns number)return NUMBER is
    begin
    RETURN m_o_uns + m_t_uns;
    end;
    function m_onrpun1Formula(m_o_uns in number,m_o_res in number)return NUMBER is
    begin
    IF m_o_uns > 0 THEN
    RETURN m_o_res / m_o_uns;
    ELSE
         RETURN NULL;
    END IF;
    end;
    function m_tenpun1Formula(m_t_res in number,m_t_uns in number)return NUMBER is
    begin
    IF m_t_uns > 0 THEN
    RETURN m_t_res/m_t_uns;
    ELSE
         RETURN NULL;
    END IF;
    end;
    function m_occpun1formula(m_occ_u in number,m_tot_res in number) return number is
    begin
    IF m_occ_u > 0 THEN
    RETURN m_tot_res / m_occ_u;
    ELSE
         RETURN NULL;
    END IF;
    end;
    function m_vac_rate1formula(m_v_uns in number,m_tot_u in number) return number is
    begin
    IF m_tot_u > 0 THEN
    RETURN 100 * m_v_uns / m_tot_u;
    ELSE
         RETURN NULL;
    END IF;
    end;
    function m_onrpha1Formula(m_o_res in number,m_area in number) return NUMBER is
    begin
    IF m_o_res > 0 THEN
    RETURN m_o_res / m_area;
    ELSE
         RETURN NULL;
    END IF;
    end;
    function m_tenpha1Formula(m_t_res in number,m_area in number)return NUMBER is
    begin
    IF m_t_res > 0 THEN
         RETURN m_t_res / m_area;
    ELSE
         RETURN NULL;
    END IF;
    end;
    function m_occpha1Formula(m_area in number,m_tot_res in number)return number is
    begin
    IF m_area > 0 THEN
    RETURN m_tot_res / m_area;
    ELSE
         RETURN NULL;
    END IF;
    end;
    function P_DESFORMATValidTrigger return boolean is
    begin
    DESFORMAT := P_DESFORMAT;
    return (TRUE);
    end;
    END test10 ;
    the package is compiled successfully.
    And my sql statement will call those function in this package such as:
    select test10.m_tot_u1Formula(m_o_uns ,m_t_uns ,m_v_uns) m_tot_u,
    test10.m_tot_res1Formula(m_o_res,m_t_res)m_tot_res,
    test.m_occ_u1Formula(m_o_uns ,m_t_uns)m_occ_u,
    test10.m_onrpun1Formula(m_o_uns ,m_o_res )m_onrpun,
    test10.m_tenpun1Formula(m_t_res ,m_t_uns )m_tenpun,
    test10.m_occpun1formula(:m_occ_u , :m_tot_res )m_occpun,
    test10.m_vac_rate1formula(m_v_uns ,m_tot_u ) m_vac_rate,
    test10.m_onrpha1Formula(m_o_res ,m_area ) m_onrpha,
    test10.m_tenpha1Formula(m_t_res ,m_area ) m_tenpha,
    test.m_occpha1Formula(m_area , :m_tot_res ) m_occpha
    from ..... where.....
    Is it right to call those functions? Thanks in advance.
    Appcat

    I spoke too soon on the impracticality of a function-based index on a view. My recollection was that the CBO wasn't smart enough to recognize that a FBI on an expression like (col1*col2) could be used to resolve queries that involved a simple transform (i.e. col2*col1), which tended to force you to have a user-defined function behind the FBI to make sure that someone cleaning up code didn't accidentally make the index unusable. Now that I've actually tested it, my recollection, at least on 10.2, is clearly incorrect.
    There's certainly a matter of personal taste here. If I knew what these variables were intended to represent, I'd have no problem maintaining either syntax because it should be relatively obvious whether either piece of code is suspect. I do have to confess that I had to look up the syntax for the NULLIF function yesterday in order to reply to this thread-- my wager is that if I had to look it up, a good fraction of the PL/SQL programmers out there would have had to look it up as well and might not immediately recognize this as an inverted division by 0 test.
    From a maintenance standpoint, I would personally rather have the package where I can zoom in on the particular function I'm interested in, rather than looking at a view that may be doing a dozen rather similar calculations. I'm a bit more confident that I (or some new maintenance programmer on my team) could change the logic in the function without inadvertently screwing up any of the other functions in the package than I would be that I (or they) would accidentally screw up the view. Clearly, robust test scripts and an automated test suite would help tremendously in either case, and neither change should be too difficult, but my experience is that the package is the easier construct to modify or add to. I certainly believe that other people/ organizations would have different experiences and other people might prefer the view approach. I certainly wouldn't oppose a view-based approach, just as I wouldn't oppose a package.
    There's also still the matter of having a table with every valid input if a view is to be practical. It's certainly possible that such a table exists, but it seems equally possible that there are either many such tables, that these functions are doing calculations on values that aren't stored in tables, etc., in which case a package would be the better solution.
    Justin

  • Pass a list of number values to a pl/sql function

    I would like to pass a list of number values to a pl/sql function where the list will be used in an IN clause. Ideally I would like to do the following:
    CREATE OR REPLACE FUNCTION ( dept_list in varchar2) is
    begin
    select ... where dept in (dept_list) ;
    usage: process_list ( '7730,7735,7740,7745') ;
    I can not find an example of doing this in pl/sql function but it seems feasible.
    Is there a way to do this?

    user12088323 wrote:
    I would like to pass a list of number values to a pl/sql function where the list will be used in an IN clause.
    usage: process_list ( '7730,7735,7740,7745') ;The first thing is you need an appropriate data type to store a list of numbers. A single character value that looks to you like a list of numbers, is not in fact a list of numbers but a single character value.
    This example uses the built in data type odcinumberlist in a procedure, you can do the same in function
    Re: Passing an array to an Oracle stored procedure
    If you have an old version of the database you may need to create your own type with the same definition of odcinumberlist.

  • Read consistency in query with pl/sql functions

    Not sure if this is a bug or feature, but a query containing a user-defined pl/sql function does not include tables accessed within the pl/sql function in the read consistent view of data, eg
    select myfunc from tableA
    myfunc is a stored function that queries tableB and returns a value
    If a change to tableB is committed in another session during fetch phase of select statement, then fetched rows reflect the changes. The database does not recognise tables accessed in the plsql function as being part of the query.
    This happens in 7.3.4 and 8.1.6. Don't have 9i so can't tell.
    Anyone know if this is a bug or feature?
    Aside: you can also drop the plsql function whilst the fetch is running. It will kill the fetch. No DDL lock taken on the plsql function whilst select is running! Seems wrong.

    I don't know Forms but I know SQL*Plus and Oracle database. Normally PL/SQL running on the database can only access files on the host where the database instance is running even if you start PL/SQL with a SQL*Plus connection from another host.
    PL/SQL runs only the database instance not on the client side even if you start the PL/SQL code from a remote connection with SQL*Plus.

  • Using Package to produce pl/sql function body returning sql query Report

    I have existing code that we want to use in building reports in APEX. We are needing to modify it slightly to handle some new requirements, but would like to use them in reports based upon SQL query (pl/sql function body returning sql query) functionality.
    Any suggestions as how to call these in an APEX report region?
    Thank you,
    Tony Miller
    UTMB/EHN

    Hi Tony-
    I am also v new to Apex and you may have answered a question I was in search of. I, however, now have a couple more. First a bit of background-- Like in your situation, my college has a lot of existing code (400 +) that we need to get into Apex. The majority of this canned code contains one/both: 1) many lines, sometimes containing multiple select statements 2) imbedded create table & view statements (temp user owned). Up until reading your post, I was unable to figure out an easy way of getting this existing code into the product. Thanks. Now the questions, do you know how I would go about dealing with the create tables/views. I've read some posts on this forum which suggest temporary tables being unstable in this environment. Also, do you know if there's a size limitation when passing sql code via a function?
    As you may/may not be able to tell, I'm a bit lost right now... so any info you can provide would be appreciated. Thanks.
    Don

  • SQL function column in drop down list's data provider's query

    Just wondering, if it is somehow possible to use SQL function column for drop down list through data provider.
    At the moment, I am using id column as return value and name as display value from this query through CachedRowSetDataProvider:
    SELECT ALL someTable.Id,
    someTable.Name,
    someTable.Postal_Code,
    FROM someTable
    However, I want to change display to use calculated column as display value, for example Name_PostalCode from below mentioned changed query:
    SELECT ALL someTable.Id,
    CONCAT(someTable.Name, ' - Pin Code: ',someTable.Postal_Code) Name_PostalCode ,
    someTable.Name,
    someTable.Postal_Code,
    FROM someTable
    But JSC doesn't seem to like this.
    Is it someway possible to achieve this?
    Thanks.

    >
    But JSC doesn't seem to like this. Can you explain more. When doesn't it like it, in the design view, in the query editor, when your run it? What is the error you are seeing?
    See http://blogs.sun.com/divas/entry/displaying_multiple_fields_in_a

Maybe you are looking for