How to create one procedure which can drop and create materialized view

Hi,
I want to create one pl/sql procedure which can first drop materialized view CATEGORY_PK and after that create same materialized view CATEGORY_PK.
programme is as follows:
DROP MATERIALIZED VIEW CATEGORY_PK;
CREATE MATERIALIZED VIEW CATEGORY_PK REFRESH FORCE WITH PRIMARY KEY AS
SELECT cav1.ownerid AS categoryid, p.uuid AS productid ,p.domainID AS productdomainid,pav.stringvalue AS NAME
     ,pav2.stringvalue AS ID, pav3.stringvalue AS SHORT
FROM product p, product_av pav, catalogcategory_av cav1, catalogcategory_av cav2,product_av pav2,product_av pav3
WHERE
cav1.NAME = 'PRODUCT_BINDING_ATTRIBUTE' AND
cav2.NAME = 'PRODUCT_BINDING_VALUE' AND
cav1.ownerid = cav2.ownerid AND
p.uuid = pav.ownerid AND
          p.uuid = pav2.ownerid AND
          p.uuid = pav3.ownerid AND
pav.NAME = cav1.stringvalue AND
          pav2.NAME = cav1.stringvalue AND
          pav2.NAME = cav1.stringvalue AND
pav.stringvalue = cav2.stringvalue AND
          pav2.stringvalue = cav2.stringvalue AND
          pav3.stringvalue = cav2.stringvalue
UNION
SELECT catalogcategoryid AS categoryid, productid, repdomainid AS productdomainid,pav1.stringvalue AS NAME
     ,pav2.stringvalue AS ID, pav3.stringvalue AS SHORT
FROM productcategoryassignment ,product_av pav1,product_av pav2,product_av pav3
     WHERE pav1.ownerid=productid
     AND pav2.ownerid=productid
     AND pav3.ownerid=productid
     AND pav1.NAME='name'
     AND pav2.NAME='productID'
     AND pav3.NAME='shortDescription';

user498566 wrote:
I want to create one pl/sql procedure which can first drop materialized view CATEGORY_PK and after that create same materialized view CATEGORY_PK.That sounds like a waste of time and resources. What do you hope to achieve by this? A refresh? If so, a simple refresh of the old materialized view will do.
If you truly want to continue this road, you'll have to use the EXECUTE IMMEDIATE command to execute DDL commands from within PL/SQL.
Regards,
Rob.

Similar Messages

  • How to CREATE MATERIALIZED VIEW LOG (MV fast refresh) with some JOINS

    Hi @ all,
    i'm trying to create a MATERIALIZED VIEW LOG for a fast refresh of a MATERIALIZED VIEW.
    It works fine with a simple Request in the MATERIALIZED VIEW:
    CREATE MATERIALIZED VIEW MV_ZOTD43_P
    TABLESPACE GDII
    BUILD IMMEDIATE
    REFRESH FORCE AS
    SELECT * FROM ZOTD43_P;
    COMMIT;
    CREATE MATERIALIZED VIEW LOG ON ZOTD43_P
    TABLESPACE "GDII"
    WITH PRIMARY KEY, ROWID, SEQUENCE INCLUDING NEW VALUES;
    call DBMS_MVIEW.REFRESH('MV_ZOTD43_P', 'f');
    But when I use a complex SQL-Request with some JOINS (one of the Table with spatial Data) in the MATERIALIZED VIEW, I get an error:
    CREATE MATERIALIZED VIEW MV_TEST
    TABLESPACE GDII
    BUILD IMMEDIATE
    REFRESH FORCE AS
    SELECT lptd04_p.sst_nr AS sst_nr,
    lptd03_p.aaaa AS aaaa,
    lptd04_geom.geom as geom
    FROM lptd04_p lptd04_p
    JOIN lptd01_p lptd01_p ON lptd01_p.cre_nr = lptd04_p.sst_nr
    JOIN lptd04_geom ON lptd04_geom.sst_nr = lptd04_p.sst_nr
    JOIN lptd03_p lptd03_p ON lptd03_p.lief_nr = lptd04_p.lief_nr;
    COMMIT;
    CREATE MATERIALIZED VIEW LOG ON LPTD04_P
    TABLESPACE "GDII"
    WITH PRIMARY KEY, ROWID, SEQUENCE INCLUDING NEW VALUES;
    call DBMS_MVIEW.REFRESH('MV_TEST', 'f');
    Error report:
    SQL Error: ORA-12004: REFRESH FAST kann für Materialized View "GDI"."MV_GDI_SST_STAMM" nicht benutzt werden
    ORA-06512: in "SYS.DBMS_SNAPSHOT", Zeile 2255
    ORA-06512: in "SYS.DBMS_SNAPSHOT", Zeile 2461
    ORA-06512: in "SYS.DBMS_SNAPSHOT", Zeile 2430
    ORA-06512: in Zeile 1
    12004. 00000 - "REFRESH FAST cannot be used for materialized view \"%s\".\"%s\""
    *Cause:    The materialized view log does not exist or cannot be used. PCT
    refresh is also not enabled on the materialized view
    *Action:   Use just REFRESH, which will reinstantiate the entire table.
    If a materialized view log exists and the form of the materialized
    view allows the use of a materialized view log or PCT refresh is
    possible after a given set of changes, REFRESH FAST will
    be available starting the next time the materialized view is
    refreshed.
    Am I doing something wrong or is it not possible CREATE MATERIALIZED VIEW LOG when the MATERIALIZED VIEW got some JOINS?
    Regards,
    Greq

    Thanks for the link Alessandro ,
    the error seems something to do with the Column-Type SDO_GEOMETRY, so
    i create a new thread in the Spatial Discussion forum:
    FAST REFRESHing of Oracle Materialized Views containing SDO_GEOMETRY column
    Regards,
    Greq

  • How to create materialized view based on a view?

    Hi,
    I hope this is not very far fetched idea.
    I have a very complex view and I would like to replicate it 'in place' that is I would like to make a materialized view that is based on this view complex view. I would like to use this materialized view (i.e table) to query data instead of using the original view, since it takes Oracle some 10-15 seconds to execute my query on the original view and I am not allowed to create indexes on most of the tables that are included in the original view.
    Can this be done?
    Best regards,
    Tamas Szecsy

    The best way to do this is to create a materialzed view based on the underlying code of the original view. If you don't have this handy, issue the following in sqlplus:
    select text
    from user_views
    where view_name = 'NAME_OF_VIEW'
    You can then cut and paste the sql statement into your create materialized view statement.
    Please note, you will probable have to set the long parameter to a higher value to reveal the complete statement for example:
    SQL> set long 2048

  • How to create materialized view based on a synonym

    Hi all,
    I am trying to create simple materialized view based on a synonym and that synonym is pointing a view in other database (using dblink). I am getting table or view not found error . I am able to select synonym if i use select but not in materialized view. Please help me.
    Thanks,

    The best way to do this is to create a materialzed view based on the underlying code of the original view. If you don't have this handy, issue the following in sqlplus:
    select text
    from user_views
    where view_name = 'NAME_OF_VIEW'
    You can then cut and paste the sql statement into your create materialized view statement.
    Please note, you will probable have to set the long parameter to a higher value to reveal the complete statement for example:
    SQL> set long 2048

  • How to create materialized view log on remote database

    How do you create materialized view logs on a remote database.
    I tried
    create materialized view log on global_express_views.vccs438_project_work_request@h92edwp with sequence, rowid ( columns...)
    ERROR at line 1:
    ora-00949 illegal reference to remote database

    Hi,
    I am not getting the error exactly. But have some suggestion:
    If the schema owner does not own the master tables, then the schema owner must have the GLOBAL QUERY REWRITE privilege or the QUERY REWRITE object privilege on each table outside the schema.
    Hope, this may help you?
    Thanx.. Ratan

  • How to create materialized  view with parameter and index ?

    Hi all,
    i am using oracle 11g.
    i want to create  parameter materialized view  with two parameter (STORED_VALUE, LOV_NAME) with  an index .
    i have below view
    CREATE OR REPLACE FORCE VIEW SR_MY_TEST(DISPLAYED_VALUE, STORED_VALUE, LOV_NAME) AS
      SELECT  DISPLAYED_VALUE , LOVVALUE.STORED_VALUE , lovname.lov_name
               FROM (SELECT T.LOV_VALUE_ID,
          T.LOV_ID,
          T.ORG_ENTITY_ID,
          T.STORED_VALUE,
          T.DISPLAYED_VALUE,
          T.ENTERPRISE_ID
         FROM MS_QS_LIST_OF_VALUES_T T) lovvalue, ms_qs_lov_names lovname
              WHERE lovvalue.lov_id = lovname.lov_id
                AND lovvalue.org_entity_id = 1
                and LOVVALUE.ENTERPRISE_ID = 100000
                AND LOVNAME.ENTERPRISE_ID = 100000;
    i want to create index on   STORED_VALUE, LOV_NAME
    Thanks
    Damby

    No.AFAIK, there's nothing called as "parameterized MV".
    Materialized View store data like tables (and not like Views). So, does it make sense when you say - "table with parameters" ?
    Could you please explain your business requirement?
    What is the purpose behind those 2 parameters?

  • How to create a function/procedure which can take optional parameter?

    Hi,
    I want to create a function or a procedure which can take optional parameters. For example, I want to create fun1() or fun1(param1) like this. Only one function will act differently when different number of parameters are passed to it. Something like the substr() function in oracle. It can be called with 2 parameters, as well as three parameters.
    Thanks in advance,
    Kiran

    There are two ways of doing this. The regular way would be to add a DEFAULT clause to your function declaration:
      -- Function can be called with 1 or 2 parameters
      FUNCTION xxxx
        ( param_one  NUMBER
        , param_two  VARCHAR2  DEFAULT NULL )
      RETURN VARCHAR2;Or, if your functions are declared in a package you can do some over-loading:
      PACKAGE yyyy
      IS
        -- Function with 1 parameter
        FUNCTION xxxx
          ( param_one  NUMBER )
        RETURN VARCHAR2;
        -- Function with 2 parameters
        FUNCTION xxxx
          ( param_one  NUMBER
          , param_two  VARCHAR2 )
        RETURN VARCHAR2;
      END;If you are calling server-side functions from client-side tools (like OracleForms) you may need to use this second method.

  • Can you please help me in creating a stored procedure which can create a tablesapce in a specified location ?

    Hello ...
    Can you please help me in writing a procedure which can create tablespace. like i have a requirement that
    through sql query i need to get the location of where the data file of the newly created tablespace need to be stored.
    I need to store the location of the datafiles in a variable and i need to use that variable for specifying the location of the data file in newly created data file.
    please help me writing this procedure.....
    Regards vinay raj.
    Thanks in advance..

    select distinct substr(file_name,1,instr(file_name,'/',-1)) from dba_data_files;
    Run this in a few of your databases and see how often you ONLY get one row returned.
    Normally there is no "default" file system for data files (read about the DB_CREATE_FILE_DEST parameter and Oracle Managed Files for the exception to that).
    You could pick the same file system as an existing tablespace, but even then there is no guarantee that the file system has sufficient space for the new tablespace - you have to check that OUTSIDE the database.
    Given the query at the top it is pretty simple to create a SQL script that generates a SQL script.  This can be run in any database via sqlplus, and then the generated script can be edited as needed and run immediately, under human control, avoiding surprises.
    set echo off
    set feedback off
    set heading off
    set lines 100
    spool myts.sql
    select distinct 'create tablespace MYTS DATAFILE '''||substr(file_name,1,instr(file_name,'/',-1))||'myts01.dbf'' size 40M ONLINE;' stmt
    from dba_data_files;
    spool off
    For example, if you find there are multiple filesystems to choose from, run this then delete the filesystems you don't want from the generated script.  If you find there is only one file system but it is too full, work with your SA or storage to to add space or allocate a new file system, then modify the generated script accordingly.
    This example assumes a traditional file system, on a UNIX-style OS, not using Oracle-Managed files.  ASM or RAW will have a different format for the data file location, of course.

  • How to call a procedure which returns out parameter in form personalization

    Dear All,
    I have one procedure which is having 2 parameter in and one parameter out .
    The question is how to get the parameter out in from personalization in a local or global variable?
    Thanks

    Yes.
    You can use the "forms_ddl" builtin
    See the following examples. Make sure you include the single quotes as well as the = sign in the begining.
    See http://phenix.blog.163.com/blog/static/8397219320096213953151/
    http://oracle.anilpassi.com/forms-personalizations.html
    Sandeep Gandhi

  • How to build a wsdl which can cater dynamically to number of attachments

    We have a WebService client that calls a Webservice on the Server.
    When the client calls the webservice , it passes the SOAP message(Header,Body & MIME attachments)and these attachments vary in number based on different business requirements.
    We know how to build WSDL for server with static number of attachments,but no clue on how to build a wsdl which can cater dynamically to number of attachments comming from client request.
    - thanks in advance

    Hello,
    We may have multiple approaches here depending of :
    - which version of the product you are using
    - what are your clients in term of stack, and API they are willing to use
    - which encoding did you use for your WS (swa, swaRef or dime)
    So for my answer I am documenting how to do it on OracleAS 10gR3 (10.1.3), using swaRef approach.
    The easiest way is to exchange array of binary data and describle that in the WSDL, so in my case the WSDL element that is used will look like that:
    <element name="filesResponseElement">
    <complexType>
    <sequence>
    <element name="result" type="ns1:swaRef" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
    </complexType>
    </element>
    This will generate from the Java code an array of AttachmentPart[].
    Regards
    Tugdual Grall

  • How to create table view with reference table

    Hi experts,
    How to create table view with reference table in SE11, plz gve me stp by stp procedure.
    pints grnded for hlp.

    Hi
    Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
    enter the description
    On the left hand side choose the table name.
    Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
    Save and then activate.
    Hope this helps.
    Regards,
    Harish

  • How to create a view with Oracle apps Org initialization ?

    Hi,
    How to create a view which needs Oracle apps org initialization to provide the correct data .
    The purpose of the view is to be accessed in Primavera DB via a DB link for reporting purpose.
    So how should the org be initialized so that the view returns the correct data when accessed from the remote data base using the DB link?
    EX: step1 run fnd_client_info.set_org_context for the org
    step2 query the veiw returns correct data in Oracle.
    How can this be achieved if the view needs to be accessed via DB link?
    sample view sql :
    select po_header_id
    from po_distributions_all pod
    where (apps.po_intg_document_funds_grp.get_active_encumbrance_func
    ('PO',
    pod.po_distribution_id
    ) <> 0
    Thanks in advance!
    Darshini

    Hi,
    This is not possible in Oracle. What u can do is create the view without the where clasue and supply the where clause at runtime.
    Hope this helps...
    Regards,
    Ganesh R

  • How to create a view dynamicly in plsql?

    I need to write a pl/sql package to create a view dynamic
    ,but i can't use 'create or replace view xxxx as select *
    from db where ...',I know the dbms_sql package can parse the
    'select' sentence,but i don't know how to create a view,only can
    drop a view,who can help me?
    thanks!
    null

    Try 'EXECUTE IMMEDIATE 'CREATE AS SELECT....' in your PL/SQL
    xhpxorcl (guest) wrote:
    : I need to write a pl/sql package to create a view dynamic
    : ,but i can't use 'create or replace view xxxx as select *
    : from db where ...',I know the dbms_sql package can parse the
    : 'select' sentence,but i don't know how to create a view,only
    can
    : drop a view,who can help me?
    : thanks!
    null

  • How to Create material master workflow

    Hi All,
    Can anybody tell me how to create material master workflow?
    i need to customize the workitem  for creating data in different views in MM01 transaction with restriction to particular user.
    Regards,
    Priti

    Hi,
    This link is to  display a material.My requirement is to create a workflow which will allow a responsible person to enter data for specific department data e.g Purchase,Accounting etc.Initially anyone can create data using basic data1 and basic data2 views.After this my workflow will be triggered and it will go to next person who is responsible to enter Purchase data and then Accounting data.
    Plz help me to create different views with respect to person.
    Thanks in advance.

  • How to create XMLTYPE View from the XMLType table

    Hi:
    I have a large XML file and inserted to the XMLTYPE table
    For the XQUERY purpose I would like to create XMLView of the table.
    The examples I got from Oracle to create XML view are for small files.
    Can some one help me how to create XMLType VIEW for large XML Files ( 20,000 lines )?
    Ali_2

    Have a look at the examples given on XMLType Views (based on relational tables) or standard views (based on XMLType storage) in the FAQ url located on the main page of this forum site regarding XMLDB.

Maybe you are looking for

  • How to read a mixed text and binary random-access file?

    I have a PDF file which I want to decode. The format is a mixture of binary data and text. What I need is to position the file to a particular position, and then to read from that point as a stream either a set of binary bytes or straight ASCII text.

  • How do I connect email address if server can't be accessed?

    eprint cannot access email address

  • Error in Pacman

    Hello, I recently intalled Arch Linux and as you can see i was trying to install the ethernet drivers to get all working to install the Eee PC kernel via pacman, but when i try to install the kernel i got some problems: # pacman -Sy kernel-eee :: Syn

  • Bt Infinity Hub replacment and reseting hub questi...

    Hi all I was wanting to ask a couple of questions about the hub Q1 I have read many times on here that when people have speed problems to reset the home hub to sort it out. The question is why ? I would of thought reseting the openreach modem would s

  • Graphics Card for Motion 4, RAM and processor upgrade

    I am using a dual quad-core Mac Pro with 8GB DDR2 667MHz RAM for FCP and Motion. I have a NVIDIA Quadro FX card which does not work with Motion. Any suggestions on the card? I am looking into ATI 4870. Also, would like to put in some more RAM..any su