Materialized view, based on the stored procedure

Hi all

is it possible to create a materialized view on the results returned by a stored procedure?

If this is not the case, do you think that any other way except for filling a table with data from the stored procedure and then founded the MV on it?

Thanks in advance.

MichaelTsilikidis wrote:

Sorry I don't speak properly. In fact the procedure does not return a value, it fills one of its parameters (of the ref cursor type) of data. That's what I wanted.

No it's not.

REF CURSOR don't store data, so it's not possible.

A Ref cursor is just a pointer to a query... and you can't "select from" a ref cursor, you can retrieve only one open.

PL/SQL 101: Understand the Ref Cursor

As correctly stated above, you can't question from a procedure to a function, and a materialized view is based on a query, you cannot use a procedure in a materialized view.

You could use a function pipeline instead of a procedure, or have the pipeline function obtain the results of the procedure and pipelines, and then the materialized view could be based on the results of this function in the pipeline.

example of function pipeline:

SQL > CREATE or REPLACE TYPE AS OBJECT num_descript (num number, descript varchar2 (30))
2.

Type of creation.

SQL >
SQL > CREATE or REPLACE TYPE tbl_num_descript AS TABLE OF THE num_descript
2.

Type of creation.

SQL >
SQL >
SQL > CREATE or REPLACE PACKAGE AS-reftest
2 FUNCTION pipedata (number p_choice) tbl_num_descript RETURN PIPELINED;
3 END;
4.

Package created.

SQL >
SQL > CREATE or REPLACE PACKAGE BODY AS-reftest
2 FUNCTION pipedata (number p_choice) tbl_num_descript RETURN PIPELINED IS
3 v_obj num_descript: = num_descript (NULL, NULL);
4 v_rc sys_refcursor;
5 BEGIN
6. IF p_choice = 1 THEN
7 v_rc OPEN to SELECT empno as num, ename like descript FROM emp;
8 ELSIF p_choice = 2 THEN
9 OPEN v_rc to SELECT deptno as num, dname as descript OF THE Department;
10 END IF;
11 LOOP
12 FETCH v_rc INTO v_obj.num, v_obj.descript;
EXIT 13 WHEN v_rc % NOTFOUND;
14 PIPE ROW (v_obj);
15 END LOOP;
16 v_rc NARROW;
RETURN 17;
18 END;
END 19;
20.

Package body created.

SQL > select * from table (reftest.pipedata (1));

DESCRIPT NUM
---------- ------------------------------
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
KING 7839
7844 TURNER
7876 ADAMS
JAMES 7900
7902 FORD
7934 MILLER

14 selected lines.

SQL > select * from table (reftest.pipedata (2));

DESCRIPT NUM
---------- ------------------------------
10 ACCOUNTING
SEARCH 20
30 SALES
40 OPERATIONS

Tags: Database

Similar Questions

  • Block based on the stored procedure cannot modify Default_where clause

    Hi all

    I tried to create a block based on the stored procedure that it works very well with the result set for the refcursor. But if I need to add filters on the block using where clause in the palette of goods or

    using the property block set in where clause, it does not error but does not review filters .

    tried everything to you please let me know. This is a restriction whereby we can set filters on the block when we create the block based on the stored procedure.

    Thank you

    Check in Form Builder Help:

    Creating a block of data from a procedure that uses a ref cursor

    ... You can't pass a WHERE or ORDER BY clause clause in a stored procedure.

    But you can send your WHERE condition using the query Source Arguments.

    If the procedure is on the side of the database (not in the forms module), ensure that the procedure is not vulnerable to injection of SQL code.

    Kind regards

    Zlatko

  • block of data based on a stored procedure with the input arguments

    Hello

    I am able to create a block of data based on the stored procedure.
    but I want that procedure to take both of the input arguments and I am facing issue while setting the value for this input arguments from another block element.
    Please someone help, how to set the value of the input of another block-element of control argument? (Note: data block is based on the stored procedure)

    Thanks in advance,
    Jean François Anandan

    I have an example that really works

    in the ownership of block

    arguments of data source query that you have two sections

    names one argument he write the name of the argument on the right, type the setting, fashion and value: block1.name and then pass the value to the procedure

  • How to view the run log in the stored procedure?

    Hello

    I'm working on a project of migrating from Sybase to Oracle (10g).

    On Sybase, when I run a stored procedure, it will connect to the console as:
    100 rows inserted
    200 rows affected
    ...

    One line per request in the stored procedure.


    Oracle, I only: 'Procedure completed successfully' (Yes, I'm french :-)


    Is there a way to get the logs for each request in my stored procedure?
    -An option?
    -One command after each request?


    Thanks in advance.

    user9321154 wrote:
    OK, it's great.

    Otherwise, there is not an option on Oracle to achieve this same result automatically.

    No, if you want to do this, you must do it yourself. PL/SQL is a real language, not a script like T - SQL language. Therefore, it is the procedure that one is successful or not, not every instruction.

    You should also be aware that if you use % ROWCOUNT SQL to get the number of rows processed and DBMS_OUTPUT. Put_line to show them on the screen, that the output will not appear before once you have completed the process, not as each DBMS_OUTPUT statement is processed.

    If you want to t shelves where in the procedure, you will need to insert the release of record in a table by using an autonomous transaction or something like UTL_FILE use to write the instructions in an o/s file.

    John

  • In a table - looping through the rows and the stored procedure call

    APEX version: 3.2.0.00.27

    Hello

    I searched the forum and tried a few things but could not make it work.

    I have a tabular presentation, developed with the help of the ATD (Cascading LOV - method of tabular presentation - AJAX - ATD )

    What I'm trying to do now:
    -After submit and validations, loop through all the lines and
    -call a stored procedure passing 3 parameters obtained from each of the lines on the form of tables. This procedure will be an update of a database table.

    On the forum, I found that I could do the loop "* FOR i IN 1..." APEX_APPLICATION.g_f03. "LOOP COUNT *" syntax.

    Only for testing purposes, I tried just to view information with the following (On Load - after a footer) process (example of Denes Kubicek == > http://deneskubicek.blogspot.com/2009/05/execute-javascript-throuhg-plsql.html):
    declare
      v_today  varchar2 (200);
    begin
    --  :P40_test := APEX_APPLICATION.g_f03(1);
    --  :P40_test2 := APEX_APPLICATION.g_f04.COUNT;
      :P40_test2 := 100;
    
      v_today := to_char (sysdate, 'dd.mm.yyyy');
    
    --FOR i IN 1.. APEX_APPLICATION.g_f03.COUNT LOOP 
    
      :P40_test := APEX_APPLICATION.g_f02(2);
    
      HTP.p ('<script type="text/javascript">');
      HTP.p (   'alert(''Today is '
              || v_today
    --          || APEX_APPLICATION.g_f04(APEX_APPLICATION.g_f03(i))
              || '.\n'
              || 'end!'');'
             );
      HTP.p ('</script>');
    
    --    :P40_test := APEX_APPLICATION.g_f02(APEX_APPLICATION.g_f02(i));
    
    --END LOOP;
    
    end;
    The foregoing would give me a ' * ORA-01403: no data found * ' message. I tried through various variants of APEX_APPLICATION.g_f0* #*, but still can't get anything to display correctly. In commenting on all the lines referring to APEX_APPLICATION.g_f0x above, the date would be are they displayed fine.

    I tried uncomment the FOR... LOOP and play with the code (defining the process runs "On submit - after calculations" and Validations), I got was a ' * ORA-06502: PL/SQL: digital error or value: character conversion number error * "message.

    Here is the script of the form in a table:
    select 
    "V"."MSLINK",                                       -- hidden (number)
    "V"."INSTALLATION_DATE",                        -- editable date picker
    "V"."MANUFACTURER_INDICATOR",              -- editable (cascading LOV -- text)
    "V"."MODEL_INDICATOR",                           -- editable (cascading LOV -- text)
    "V"."DIAMETER_INDICATOR",                      -- editable (LOV -- number)
    "V"."PURPOSE_INDICATOR",                        -- editable (LOV -- text)
    "V"."VALVE_NUMBER",                                -- shown but not editable -- number
    "V"."MODIFY_DATE",                                  -- shown but not editable
    "V"."MODIFY_USER",                                   -- shown but not editable
    "V"."VALVES_STYLE"."FEATURE"                  -- shown but not editable -- number
    from "#OWNER#"."VALVES" "V"
    Where
      "V"."PROJECT_ID" = :P1_PROJECT_NUMBER AND
      "V"."VALVES_DFLAG" = 0
    Regarding the parameters for the stored procedure, it would the MSLINK, VALVE_NUMBER and the VALVES_STYLE. FEATURE.

    Help, please!
    (Sorry for the long post).

    Thank you

    Tan

    Hi, Tan,

    I have not seen that type of object - I've only used custom types for purposes of test years ago and have never used their within Apex!

    One possibility is that the value of checksum being is based on all of the content of these fields, rather than only the part of the FEATURE. If there are other parts of the object, you could include those items as well.

    Otherwise, as you f01 KP for a record, you will need to retrieve the values of the FUNCTION in your PL/SQL code directly from the table (because the user cannot modify these fields, you can be sure that the values in the table will be still valid).

    Andy

  • Key of the stored procedure

    Hello

    I have a function in the db that returns a numeric value after passing an Id (digital). How do I create a join in physical layer as funtion will return a digital and given that it is a function, it can return only a single column.

    is it possible that I can keep the id (parameter) in the phycisal layer which I'm passing to the function, so that I can join neccasy in the physical layer with fact/Sun to the stored procedure.

    is the possible creation of mutiple stored procedure in physics if my function to only return a single column.

    Concerning
    Issue

    If I understand your question, you have a function that returns a numerical value based on an ID, we'll call it Customer ID as a sample. What you need to do is to create a view like this:

    CREATE THE VIEW IN CIRCULATION
    SELECT CUSTOMER_ID, get_outstanding (CUSTOMER_ID) FROM CLIENT

    You can then query this view like this:

    SELECT * EXCEPTIONAL WHERE CUSTOMER_ID = 999

    You could also use this point of view in your physical layer and attach it by customer ID. If you already have a table of facts, you could put a top view to add the extra column with your function. It of all good and should work fine with a warning. PL/SQL execution on SQL functions is not effective. Oracle has switch context between SQL and PL/SQL for each line and change in context is an expensive operation. In a proper system of DWH you préremplira your fact table with the results of get_outstanding for all customers so that there is no delay in the calculation it when OBIEE queries data.

  • Creating classic report to the stored procedure.

    How can we create a report based on a stored procedure out parameter.

    Can someone please help.

    Thank you

    Nani.

    Nani4850 wrote:

    Out parameter is a multi-level object type.

    I found a way to sort of basis a report on the parameter OUT procedure. The approach is:

    1. call the procedure in a process before PL/SQL areas, convert the object returned in an XML document and store in a collection XMLType column:

    declare
    
      k_rate_query varchar2(255) := 'RATE_QUERY';
    
      l_rate_type_code  number;
      l_rate_query      rate_rec;
      l_xml             xmltype;
    
      l_seq_id number;
    
    begin
    
      l_rate_type_code := to_number(:p1_rate_type_code);
      api_pkg.rate_query(l_rate_type_code, l_rate_query);
      l_xml := xmltype.createXML(l_rate_query);
    
      if not apex_collection.collection_exists(k_rate_query)
      then
        apex_collection.create_collection(k_rate_query);
      end if;
    
      select
          seq_id
      into
          l_seq_id
      from
          apex_collections
      where
          collection_name = k_rate_query
      and n001 = l_rate_type_code;
    
      apex_collection.update_member_attribute(k_rate_query, l_seq_id, 1, l_xml);
    
    exception
    
      when no_data_found
      then
        apex_collection.add_member(
            p_collection_name => k_rate_query
          , p_n001 => l_rate_type_code
          , p_xmltype001 => l_xml);
    
    end;
    

    2. use a SQL/XML query on the XML collection in the region report source:

    select
        rq.*
    from
        apex_collections ac
      , xmltable(
            '/RATE_REC/RATE_TBL/RATE_REC_TYPE'
            passing ac.xmltype001
            columns
                action_code         varchar2(20)  path 'ACTION_CODE'
              , rate_key            number        path 'RATE_KEY'
              , rate_type_code      varchar2(5)   path 'RATE_TYPE_CODE'
              , program_key         varchar2(12)  path 'PROGRAM_KEY'
              , rate                number(8,5)   path 'RATE'
              , effective_date      date          path 'EFFECTIVE_DATE'
              , current_yn          varchar2(1)   path 'CURRENT_YN'
              , non_current_dt      date          path 'NON_CURRENT_DT'
              , non_current_by_id   varchar2(4)   path 'NON_CURRENT_BY_ID'
              , non_current_reason  varchar2(400) path 'NON_CURRENT_REASON') rq
    where
        ac.collection_name = 'RATE_QUERY'
    and ac.n001 = to_number(:p1_rate_type_code)
    
  • Create a form based on a stored procedure error

    Hi all

    I am creating a form based on a stored procedure (CASH_MOVE). The stored procedure is inside a package (APEX_API).

    The package is not in the default schema of database application APEX (MO_APEX) analysis, but the workspace (USD) has access to this database scheme (MO_401)

    and the corresponding APEX analysis (MO_APEX/APEX_PUBLIC_USER) schema user has the EXECUTE privilege on the database to the other schema (APEX_API) package.

    So what happens during the wizard, at STEP 1, he sees the other schema, and I choose the package procedure.

    When I press next, it fails with the error 'user XXX has no privileges on the schema MO_401. ". "


    However, the user XXX is the developer of the APEX, which has no schema in the database. I tried also giving execute rights on APEX_PUBLIC_USER also without success.

    No idea why this happen?

    I use: Application Express 4.2.4.00.08

    Database version: 11.2.0.3.0

    TIA.

    Dionisis

    Ms. wrote:

    I am creating a form based on a stored procedure (CASH_MOVE). The stored procedure is inside a package (APEX_API).

    The package is not in the base schema of data analysis of the demand of the APEX (MO_APEX), but the workspace (MO_APEX) has access to this database scheme (MO_401)

    and the corresponding APEX analysis (MO_APEX/APEX_PUBLIC_USER) schema user has the EXECUTE privilege on the database to the other schema (APEX_API) package.

    So what happens during the wizard, at STEP 1, he sees the other schema, and I choose the package procedure.

    When I press next, it fails with the error 'user XXX has no privileges on the schema NNN. '.


    However, the user XXX is the developer of the APEX, which has no schema in the database. I tried also giving execute rights on APEX_PUBLIC_USER also without success.

    No idea why this happen?

    The developer APEX XXX there schema restrictions in the account privileges Schemes Accessible setting in Home > Administration > users > edit user?

  • Can not see all the stored procedures in the Entity Data Model Wizard

    I hope it is a simple oversight on my part I try to use the new beta version of odp.net with entity framework support. I can open the Entity Data Model Wizard, give him my information database, and I can choose various tables to use successfully. But in the list where I select the tables, views and stored procedures, the wizard does not see my stored procs or my point of view.

    Does anyone know why he would see the tables but not views or stored procedures? My procs can be found under "packages" If that makes a difference. I tried to create a fictional stored procedure at the level above the title of 'procedures', but it is unclear whether.

    Is it possible for me to debug this from here? The log files, I could watch that would help me?

    Thank you
    Jim

    I belive your Oracle database 10 g such as 9iR2 predates.
    ODP/EF Beta does not list the stored procedures or functions when connect you to a database Oracle 10 g before.

    Readme.txt:
    4. the procedures are not compatible with the DB 9.2.
    Thus, there is no stored procedure listed by the EDM Wizard for 9.2 DBs.

  • Creating views, dynamic SQL within stored procedure

    I'm having a problem with the creation of dynamic views of in a stored procedure. The following declare block works fine:

    DECLARE
    parameter i_nom_table varchar2 (200): = 'abc ';
    xyz cursor script, SELECT step
    STARTING from scripts
    WHERE table_name = i_nom_table parameter
    ORDER BY step CAD;
    l_sql scripts.script%TYPE;
    l_step scripts.step%TYPE;
    l_error VARCHAR2 (200);
    l_code VARCHAR2 (200);
    Start
    XYZ OPEN;
    LOOP
    XYZ-FETCH INTO l_step, l_sql;
    OUTPUT WHEN xyz % NOTFOUND;
    immediately run l_sql;
    insert into ingest_log values (null, sysdate, i_nom_table, l_step, l_sql, 'Success' parameter);
    END LOOP;
    CLOSE XYZ;
    insert into ingest_log values (null, sysdate, parameter i_nom_table, 0, "Accomplished all the steps.", "Success");
    EXCEPTION WHEN OTHERS THEN
    l_error: = substr (SQLERRM, 1, 200);
    l_code: = SQLCODE;
    insert into ingest_log values (null, sysdate, parameter i_nom_table, l_step, l_sql, l_code |) ' - ERROR - ' | l_error);
    END;

    However, if I create a procedure with this block and try to run it I get an insufficient privileges error. Do not know why. All tables, views, procedures are under the same user, and the user that I'm connected as the runtime of the declare block. The user has the following privileges:

    Connect, resource, xdbadmin, s/n

    Any reason you can think of for this? Script values are generally "CREATE OR REPLACE VIEW As.... » ;

    Permissions in Oracle to do indirectly through roles are not available when compiling packages, functions, and stored procedures. Direct subsidies are required during the creation of these objects in the database.

    http://articles.TechRepublic.com.com/5100-10878_11-6183799.html

  • How can I transfer content from an XML file in a MS SQL database of the stored procedure using LabWindows/CVI SQL Toolkit?

    Hello

    I have a problem to transfer content to an XML file in a MS SQL database through a stored procedure data/fixed. I am able to transfer the content of the file using method...

    HSTMT = DBPrepareSQL (hdbc, EXEC usp_InsertReport " ... ");

    resCode = DBExecutePreparedSQL (hstmt);

    resCode = DBClosePreparedSQL (hstmt);

    ... but in this case, I am not able to read the return value of the stored procedure.

    I tried to follow the example of the stored procedure in the help documentation (DBPrepareSQL), but I miss a xml data type?

    No idea how to solve my problem?

    Cake of KR

    DianaS salvation,

    Thanks for your comments. During this time I found another way which fullfill my needs:

    resCode = DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_TEXT);

    sprintf (sz_SqlStatement, "DECLARE @TESTID INT EXEC @TESTID = usp_InsertReport ' SELECT 'RetVal' %s = @TESTID", sz_Buffer ");
    HSTMT = DBActivateSQL (hdbc, sz_SqlStatement);

    While ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS)

    {

    / * Enter values in the record. */

    resCode = DBGetColInt (hstmt, 1, & s32_TestId);
    }

    resCode = DBDeactivateSQL (hstmt);

    sz_Buffer is the content of the XML file.

    Cake of KR

  • Call the stored procedure, and bind parameters by name

    Hello

    I use the Oracle ODBC 12 c driver to pass values from one Interface to our database Oracle 11.2. The Interface software collects data from modbus protocoll and calls a stored procedure. Right now my syntax to call the stored procedure looks like this:

    CALL procedure-name ('STRING', 'Timestamp as String', numValue1);

    It works very well. Now, I have to add a default setting to my procedure. To stay flexible to make other changes, I want to call the procedure and bind the parameters by name. Release 10.2.0.1.0 ISC ODBC Notes:

    Added support for the named parameter, binding the parameters by name. ODBC Oracle driver now allows the application to specify the parameters of a stored procedure by name, in the procedure call. Named parameters are to be used in calls to stored procedures and should not be used in other SQL statements.

    So, it shouldn't be a problem to use named notation, but how do I do this in ODBC? I tried like this, but oracle returns an ora-00936 error of missing expression:

    call procedure-name (paramName1 = > 'STRING',= paramName2 > 'Timestamp as String',paramName3 = > numValue1).


    Thank you for your help.

    Finally, I was able to find the error. The syntax of the statement was very good. The problem was caused by another declaration that I edited before and the error has not attracted Attention immediately.

    Thanks for reading and looking for an answer.

  • How can I force DAC to run always full load for one of the task that executes the stored procedure? And remaining tasks load incremental in the second and sub sequent executions.

    Hello

    How can I force DAC to run always full load for one of the task that executes the stored procedure? And remaining tasks load incremental in the second and sub sequent executions.

    Thank you

    Jay.

    Hi if your task is running an informatica mapping you can set your DAC task to run the full mapping for incremental and full loads, so tab task just point to the mapping.

    Hope that helps.

    Thank you

  • Execution of the stored procedure Oracle EF6 error.

    Hello

    Need help with the oracle error

    {"ORA-06550: line 1, column 8:"}

    PLS-00306: wrong number or types of arguments in the call to "sp_name".

    ORA-06550: line 1, column 8:

    {"PL/SQL: statement ignored '}

    This error occurs when the code runs the line in Vb.net application in Model Designer

    MyBase.ExecuteFunction ("sp_name" para1, para2, para3, dOBpara4, para5)

    I create the SSDL and CSDL, MSL files for oracle to MS SQL connection by the method mentioned in the link JasonShort - professional profile - CodeProject it worked perfectly fine without the stored procedures. I managed to insert, update, and delete records. Then, I created stored procedures for Insert, Update, Delete. It worked fine with MS SQL. I copied and updated oracle files respectively. I gives me the error mentioned above.

    I executed stored procedures in Oracle SQL Developer, and it works without error. But when it is executed via the model there is light of the error. Can anyone let me know the solution for this error. I'm using VS2010, EF6, Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    Thank you

    Prachin Soparkar

    Hello

    Sorry for the inconvenience. After I posted this question I took a break and saw that the error was nothing, but I had given FNAME as parameter name in MS SQL. In oracle when I created the sp I created the parameter with p_FNAME. Where the schema defined in the language SSDL and CSDL, MSL had to be changed to MS, but since I want to that it would be same in different databases, I choose to have changed it in oracle stored procedure. The error msg is confusing, it should be something not found parameter or incompatibility etc.

    Thank you

    Prachin Soparkar

  • Fall in the stored procedure option

    Hi Expert,

    I created the option in one of my stored procedure for testing purposes and now I am trying to drop the option and let the stored procedure, anyone know how I can do? Thank you!

    If what you want is to eliminate the Option that you have created in your Proc, you only need to:

    Expand the sign + to the left of you proc;

    Select the option that you want to remove;

    Press DELETE, or right-click and delete:

    I hope this can help you!

Maybe you are looking for