Creating view with union, what to do if a table is missing?

Dear All,
I have three schema in one DB, 11gR1 is the database and Linux is OS.
Schema1
Schema2
Schema3
Each schema contains almost the same structure, but different data.
There are few tables that exists in one schema and may not exist in the other one.
In another schema, i am creating consolidated views using union command.
select * from schema1.table1
union
select * from schema2.table1
union
select * from schema2.table1
If table1 do not exists in schema2, the view gives error.
Is there any possibility that query somehow check if the table exists then select records otherwise skip? It has to be one query.
I hope i am able to deliver through words what I mean.
Your kind help is required on this.
Regards, Imran

So basically
you want to have one view for all the tables with same name in different schemas
and you don't want to check the existence of tables before creating the view.
In that case you can create a script to generate the views by selecting from dba_tables like below
select 'create or replace view v_'||table_name||' as select * from '||owner||'.'||table_name||' union bla bla bla' from dba_tables where table_name='table'
you will probably end up doing this with a cursor and you need to be carefull about union clauses in case there is no bla bla part
Coskan Gundogar
Blog: http://coskan.wordpress.com
Twitter: http://www.twitter.com/coskan
Linkedin: http://uk.linkedin.com/in/coskan
---------

Similar Messages

  • Create view with union

    Hi all,
    I have tried to create a view with next code:
    CREATE VIEW vista_urbanizacion AS SELECT
    RUPI_URBANIZACIONES.NOMBRE_URBANIZACION,
    RUPI_URBANIZACIONES.NRO_PREDIOS,
    RUPI_URBANIZACIONES.NRO_URBANIZACION,
    RUPI_URBANIZACIONES.ESTADO,
    RUPI_URBANIZACIONES.FECHA_INGRESO,
    RUPI_URBANIZACIONES.AREA_TERRENO,
    RUPI_URBANIZACIONES.TIPO,
    RUPI_URBANIZACIONES.UBICACION_ARCHIVO,
    RUPI_URBANIZACIONES.NRO_SUPERURBANIZACION,
    RUPI_URBANIZACIONES.ID_URBANIZADOR,
    RUPI_URBANIZACIONES.AREA_TOTAL_CESION,
    RUPI_ESCRITURAS.MATRICULA_INMOBILIARIA,
    RUPI_ESCRITURAS.NOTARIA,
    RUPI_ESCRITURAS.CIUDAD,
    RUPI_ESCRITURAS.ACTO_JURIDICO,
    RUPI_ESCRITURAS.FECHA_ESCRITURA,
    RUPI_ESCRITURAS.NRO_ESCRITURA,
    RUPI_ESCRITURAS.CONSECUTIVO,
    RUPI_ESCRITURAS.URBANIZACI_NRO_URBANIZACION,
    RUPI_ACTAS.TIPO_ACTA,
    RUPI_ACTAS.NRO_ACTA,
    RUPI_ACTAS.FECHA_ACTA
    FROM
    RUPI_URBANIZACIONES,
    RUPI_ESCRITURAS,
    RUPI_ACTAS
    WHERE
    RUPI_URBANIZACIONES.NRO_URBANIZACION =
    RUPI_ESCRITURAS.URBANIZACI_NRO_URBANIZACION
    AND
    FECHA_ESCRITURA IN (SELECT MIN(FECHA_ESCRITURA) FROM RUPI_ESCRITURAS
    WHERE
    RUPI_URBANIZACIONES.NRO_URBANIZACION = RUPI_ESCRITURAS.URBANIZACI_NRO_URBANIZACION)
    AND
    RUPI_URBANIZACIONES.NRO_URBANIZACION =
    RUPI_ACTAS.URBANIZACI_NRO_URBANIZACION
    AND
    FECHA_ACTA IN (SELECT MAX(FECHA_ACTA) FROM RUPI_ACTAS
    WHERE
    RUPI_URBANIZACIONES.NRO_URBANIZACION =
    RUPI_ACTAS.URBANIZACI_NRO_URBANIZACION)
    The problem is the condition "and" from the rupi_escrituras and rupi_actas tables that only will select elements of rupi_urbanizaciones included both in rupi_escrituras and rupi_actas.
    I need to use something like "union" in order to include all the distinct elements of both tables rupi_escrituras and rupi_actas.
    Could anyone help?
    Thanks in advance
    Romulo

    Yep,
    In this query you don't do any join between the tables. So let's get back to the basic.
    Take you first query
    SELECT CBR_ID,PLT_ID,SUM(COUNT_POL)
    FROM
    SELECT  pcd_irs_id CBR_ID, pcd_plt_id PLT_ID , sum(pcd_amount_lc) SUM_PREM,0 COUNT_POL
    FROM seema
    where trunc(pcd_registry_date)=TRUNC(pcd_registry_date)
    and pcd_plt_id in('U01','U02')
    and pcd_irs_id in (55,56)
    AND PCD_IRS_TYPE!=4
    GROUP BY PCD_irs_ID,PCD_PLT_ID
    UNION
    SELECT PLM_CBR_ID CBR_ID,PLM_PLT_ID PLT_ID,0 SUM_PREM, COUNT(PLM_POLICY_NO) COUNT_POL
    FROM sarah
    WHERE  trunc(PLM_registry_date)=TRUNC(PLM_registry_date)
    AND PLM_PLT_ID IN('U01','U02)
    GROUP BY PLM_CBR_ID,PLM_PLT_ID)
    GROUP BY CBR_ID,PLT_ID
    ORDER BY CBR_ID,PLT_IDThis query is quite near to the result that you need. You are very near to the result just add the filter that you need in the second query:
    SELECT CBR_ID,PLT_ID,SUM(COUNT_POL)
    FROM
    SELECT  pcd_irs_id CBR_ID, pcd_plt_id PLT_ID , sum(pcd_amount_lc) SUM_PREM,0 COUNT_POL
    FROM seema
    where trunc(pcd_registry_date)=TRUNC(pcd_registry_date)
    and pcd_plt_id in('U01','U02')
    and pcd_irs_id in (55,56)
    AND PCD_IRS_TYPE!=4
    GROUP BY PCD_irs_ID,PCD_PLT_ID
    UNION
    SELECT PLM_CBR_ID CBR_ID,PLM_PLT_ID PLT_ID,0 SUM_PREM, COUNT(PLM_POLICY_NO) COUNT_POL
    FROM sarah
    WHERE  trunc(PLM_registry_date)=TRUNC(PLM_registry_date)
    AND PLM_PLT_ID IN('U01','U02)
    and PLM_CBR_ID in (55,56)          --<<<<<<<<< ADDED FILTER
    GROUP BY PLM_CBR_ID,PLM_PLT_ID)
    GROUP BY CBR_ID,PLT_ID
    ORDER BY CBR_ID,PLT_IDand you are done.
    Bye
    Antonio

  • How I can create view with parameters?

    I have very big query (2000 rows) and 2 parameters.
    How I can create view with parameters?

    If I use this small part of my query than I have error :
    java.lang.NullPointerException
         at oracle.javatools.db.ora.OracleSQLQueryBuilder.buildQuery(OracleSQLQueryBuilder.java:199)
         at oracle.javatools.db.ora.OracleSQLQueryBuilder.buildQuery(OracleSQLQueryBuilder.java:147)
    What does it means?
    select
    ' Payroll ' as Revenue
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and ( nvl(a.scode, 0) between 60000 and 6009000 )
    union all ---------------------------------------------------------------------------------------------------------------------------------
    select
    ' Payroll Taxes '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    (nvl(a.scode, 0) between 60100 and 60690 )
    union all -------------------------------------------------------------------------------------------------------------------------------
    select
    ' Workers Comp/Disability '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    ( nvl(a.scode, 0) between 61200 and 61260)
    union all -------------------------------------------------------------------------------------------------------------------------------
    select
    ' Pension and Hospitalization '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    ( nvl(a.scode, 0) between 61000 and 61550 )
    union all -------------------------------------------------------------------------------------------------------------------------------
    select
    ' Other Labor Costs '
    , t.umonth, nvl(p.hmy, 0), nvl(t.sMTD, 0), nvl(a.inormalbalance, 0), nvl(T.sbudget, 0), nvl(a.scode, 0)
    from
    acct a, total t, property p, param par
    where
    nvl(t.hacct, 0) = nvl(a.hmy, 0)
    and nvl(par.hretain, 0) <> nvl(a.hmy, 0)
    and nvl(t.iBook, 0) = 0
    and nvl(a.iacctType, 0) = 0 /*Regular accts*/
    and nvl(t.hppty, 0) = nvl(p.hmy, 0)
    and
    ( nvl(a.scode, 0) between 616000 and 616400 )

  • Materalized view with union all and fast referesh

    I have a one view which is very slow. in this view we are joining many tables and many union all queries.
    now I am planing to make materalized view
    Tell me how i will created view with fast refresh with union all query.
    Pls help its urgent..
    Thanks
    Reena

    Refer to the Replication Manual for the create syntax and exceptions.

  • Create View  with Force and No Force

    Can Anyone Tell me how to create view with force and no force i have very little idea about this

    This is the syntax.
    CREATE [OR REPLACE] FORCE VIEW view
    [(alias[, alias]...)]
    AS subquery
    [WITH CHECK OPTION [CONSTRAINT constraint]]
    [WITH READ ONLY [CONSTRAINT constraint]];You can see interesting threads about this topic here.
    Re: Creating view forcibly
    Creating View forcefully
    Cheers
    Sarma.

  • Is it possible to create views with parameters ?

    Hi,
    As MS-Access, is it possible to create views with parameters ?
    Ms-Access syntax : parameters [a] text; select * from table where code = [a]
    If yes, can you give samples ?
    Regards
    Pascal

    I suggest you you write a stored procedure that returns a recordset in oracle. Then execute the stored procedure and loop through the record set.
    Look in in MS Knowledgebase searching on ADO Stored Proceedures for the VB/C++/VBS .. code.
    Look in in Oracle PL/SQL guide for the Stored Proceedure code.

  • Makes it possible to create view with parameters

    makes it possibel to create view with paramater, example
    create or replace view v_test(segment varchar2)
        select * from ref_user where segment = segmentThanks

    thanks..
    select count(distinct substr(a.svm_id,1,10)) jumlah " +
       " from daily_distribution_pop a, ref_toko b " +
       " where " +
       " substr(a.svm_id,1,10)=b.id and b.segment_type = 'A' and enable_flag='Y' " +
       " and a.tgl_visit between to_date('" + fromStartDate + "', 'dd/MM/yyyy') and to_date('" + fromEndDate + "', 'dd/MM/yyyy')
         and " + whereA + "= '" + whereB + "' " +
       " and substr(a.pom_id,1,2) = 'DP' and (a.qty_instore <> 0 or a.qty_delivered <> 0) ";
    {code}
    where fromStartDate,  fromEndDate, whereA, whereB  is variable parameter from asp.net.
    how to i can implement with view                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • What is the use for CREATING VIEW WITH CHECK OPTION?

    Dear Legends,
    I have a doubt
    What is the use for creating view?
    A: First Data Integrity, Selecting Particular Columns..
    What is the use for creating a view with check option?
    A: As per oracle manual I read that its a referential integrity check through views.
    A: Enforcing constraints at DB level.
    A: using CHECK OPTION we can do INSERTS UPDATES for a view for those columns who have no constraints... is it right??
    A: If we do a INSERT OR UPDATE for columns who have constraints it will show error... is it right???
    Please clear my doubt's Legends
    Lots of Thanks....
    Regards,
    Karthik

    Hi, Karthick,
    karthiksingh_dba wrote:
    ... What is the use for creating view?
    A: First Data Integrity, Selecting Particular Columns..Most views are created and used for convenience. A view is a saved query. If the same operations are often done, then it can be very convenient to code those operations once, in a view, and refer to the view rather than explicitly doing those operations.
    Sometimes, views are created and used for security reasons. For example, you many want to allow some users to see only certain rows or certain columns of a table.
    Views are necessary for INSTEAD OF triggers.
    What is the use for creating a view with check option?
    A: As per oracle manual I read that its a referential integrity check through views.The reason is integrity, not necessarily referential integrity. The CHECK option applies only when DML is done through the view. It prohibits certain changes. For example, if a user can't see certain rows through a view, the CHECK option keeps the user from creating such rows.
    A: Enforcing constraints at DB level.I'm not sure what you mean. Please give an example.
    A: using CHECK OPTION we can do INSERTS UPDATES for a view for those columns who have no constraints... is it right??No. Using CHECK OPTION, you can do some inserts and updates, but not others. The columns involved may or may not have constraints in either case.
    A: If we do a INSERT OR UPDATE for columns who have constraints it will show error... is it right???If you try to violate a constraint, you'll get an error. That happens in views with or without the CHECK OPTION, and also in tables.

  • Updatable Materialized View with Union ALL

    (please don't ask about db structure)
    DB: 11gR2
    create table table_1  (
        id number primary key,
        val varchar2(100)
    create table table_2  (
        id number primary key,
        val varchar2(100)
    insert into table_1(id) values (0);
    insert into table_1(id) values (2);
    insert into table_1(id) values (3);
    insert into table_1(id) values (4);
    insert into table_1(id) values (5);
    insert into table_2(id) values (10);
    insert into table_2(id) values (12);
    insert into table_2(id) values (13);
    insert into table_2(id) values (14);
    insert into table_2(id) values (15);
    update table_1 set val='Table1 val:'||id;
    update table_2 set val='Table2 val:'||id;
    create view v_table_all as
    select * from table_1
    view V_TABLE_ALL created.
    select * from v_table_all;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             YES       YES        YES      
    VAL                            YES       YES        YES      
    update v_table_all set val='XXX changed' where id = 3;
    1 row updated.
    select * from table_1;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      XXX changed                                                                                         
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    rollback;
    select * from table_1;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    create or replace view v_table_all as
    select * from table_1
    union select * from table_2;
    view V_TABLE_ALL created.
    select * from v_table_all;
    ID                     VAL                                                                                                 
    0                      Table1 val:0                                                                                        
    2                      Table1 val:2                                                                                        
    3                      Table1 val:3                                                                                        
    4                      Table1 val:4                                                                                        
    5                      Table1 val:5                                                                                        
    10                     Table2 val:10                                                                                       
    12                     Table2 val:12                                                                                       
    13                     Table2 val:13                                                                                       
    14                     Table2 val:14                                                                                       
    15                     Table2 val:15  
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             NO        NO         NO       
    VAL                            NO        NO         NO       
    trying update:
    update v_table_all set val='XXX changed' where id = 3;
    SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
    01732. 00000 -  "data manipulation operation not legal on this view"
    *Cause:   
    *Action:
    drop view v_table_all;
    view V_TABLE_ALL dropped.all is ok before this point.
    now we want create a new materialized view with some query
    create  materialized view v_table_all
    as
    select * from table_1
    union all select * from table_2 ;
    materialized view V_TABLE_ALL created.
    select column_name, updatable, insertable, deletable
    from user_updatable_columns
    where table_name = 'V_TABLE_ALL'
    COLUMN_NAME                    UPDATABLE INSERTABLE DELETABLE
    ID                             YES       YES        YES      
    VAL                            YES       YES        YES       it seems to be ok with update.
    but...
    update v_table_all set val='XXX changed' where id = 3;
    SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
    01732. 00000 -  "data manipulation operation not legal on this view"
    *Cause:   
    *Action:How can solve this issue??
    Any suggestion

    Looks like user_updatable_columns sort of thinks the MV is just a table - I don't know about that...
    An MV on a single table can be updated - I tried that and it works:
    create materialized view mv_table_1 for update
    as
    select * from table_1;I noticed [url http://download.oracle.com/docs/cd/E11882_01/server.112/e16579/advmv.htm#sthref294]examples stating the UNION ALL needs a "marker" so Oracle can know from the data which source table a row in the MV originates from - like this:
    create materialized view v_table_all for update
    as
    select 'T1' tab_id, table_1.* from table_1
    union all
    select 'T2' tab_id, table_2.* from table_2 ;But that also fails (the "marker" requirement was specifically for FAST REFRESH, so it was just a long shot ;-) )
    What are you planning to do?
    <li>Create the MV.
    <li>Update records in the MV - which then is no longer consistent with the source data.
    <li>Schedule a complete refresh once in a while - thereby overwriting/losing the updates in the MV.
    If that is the case, I suggest using a true table rather than an MV.
    <li>Create table t_table_all as select ... .
    <li>Update records in the table - which then is no longer consistent with the source data.
    <li>Schedule a job to delete table and insert into table select ... once in a while - thereby overwriting/losing the updates in the table.
    In other words a kind of "do it yourself MV".
    I cannot see another way at the moment? But perhaps try in the data warehousing forum - the people there may have greater experience with MV's ;-)

  • Oracle doc inconsistent on materialize view with union all and self joins

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

  • Different results using View with union all in 11R1 compared to 10R2

    Hello,
    I have the following situation:
    In Oracle 10R2 I defined a view which looks like this
    create view test_view
    as
    select 'field1;field2;field3' field from dual
    union all
    select field
    from (
    select tfield1||';'||tfield2||';'||tfield3 field
    from table1
    order by tfield1,tfield2,tfield3
    The idea is, my first line contains a header information an then the data in the required sorting order.
    So, in 10R2, when I export the view with select field from test_view, I get the result as expected, which means, the header from the part with the dual was in the first line and after that, the data in the required sort order.
    Now, in 11.1.0.7, it is completely different, because the row of the dual is somewhere in my result set. But if I send the sql instead of the view, I get the expected result as in 10R2.
    I have no idea why this is the case now, because in 10R2 this was working permanently as expected. When I look at the execution plan, I see, that he starts parallelisation, which is ok, but the difference is, that in this parallelisation the select from dual is included and in 10R2 he first make the line from the dual and then the parallelisation with the data. It's not clear to me, that if I send the sql to the database I see the required result, but if i define the view as mentioned, and start a select field from view, I get now get the different sorting, because of the parallelisation, where the optimizer he changes his behavior comparing the both database versions. So my question ist, how can I change this behavior to get the same behavior as in release 10R2.
    Best regards
    Rainer

    Hello,
    thank you for your sample, I see your idea for my sorting purpose.
    I want to look at the following point:
    I create the table, as you described. The table has the degree and instances 1. Now I deefine the following view:
    create view view_test
    as
    select 'field1;field2;field3' field
    from dual
    union all
    select tfield1 || ';' || tfield2 || ';' || tfield3 field
    from (select * from table1 order by tfield1,tfield2).
    This is the way I used it in 10 R2.
    Now, the SQL select field from view_test delivers the expected result:
    field1;field2;field3
    a;b;c
    d;e;f
    So far so good. But now, I changed the degree of the table1 (alter table table1 parallel (degree 4 instances 1);).
    The result looks like that:
    a;b;c
    field1;field2;field3
    d;e;f
    So, the parallelisation of my object seems to be the reason for the, in my eyes, "wrong" sort order. In 10R2 I used this degree and instance values for my table and defined a view and it was working fine. Now, after our migration, I had this "trouble". For me it seems, that the optimizer made some changes, or mabe this is a bug, who knows ?
    I also tried, to change the nls_comp, and set the undocumented parameters as described in the Metalink note 7497640.8, but with no effect of my result set.
    Best regards
    Rainer

  • How to create view with schemabinding on cross datbases(partitioned views)

    Hello Everyone,
    Please help me to sort this issue. I know it is not possible bind the scheman in below example. But is there any solution to solve this issue.
    I've tables like below
    create database D1--First database
    create table dbo.t1(
    id int
    create database D2--Second database
    create table dbo.t2(
    id int
    i want to create a view with the schema binding option on this
    create database D3
    use d3
    create view vw_v1
    with schemabinding
    as
    select id from d1.dbo.t1
    union all
    select id from d2.dbo.t2
    I'm getting this below error
    Msg 4512, Level 16, State 3, Procedure vw_v1, Line 7
    Cannot schema bind view 'vw_v1' because name 'd1.dbo.t12' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.
    Many thanks
    A-ZSQL

    CREATE VIEW
    SCHEMABINDING
    Binds the view to the schema of the underlying table or tables. When SCHEMABINDING is specified, the base table or tables cannot be modified in a way that would affect the view definition. The view definition itself must first be modified or dropped to remove
    dependencies on the table that is to be modified.
    > When you use SCHEMABINDING,
    the select_statement must include the two-part names (schema.object)
    of tables, views, or user-defined functions that are referenced.
    >
    All referenced objects must be in the same database.
    José Diz     Belo Horizonte, MG - Brasil

  • Cannot create view with parameter bindings

    Hi, I'm trying to create this view in SQLPlus:
    SELECT order_no, SUM(cut_qty),
    SUM(received_qty)
    FROM (
    SELECT order_no, cut.dated, DECODE(cut.bimetallic, 'F', cut.quantity, cut.quantity/2) cut_qty,0 AS received_qty
    FROM cut_shop_orders_dated cut
    WHERE cut.dated BETWEEN TO_DATE('&date1','DD/MM/YYYY') AND TO_DATE('&date2','DD/MM/YYYY')
    UNION
    (SELECT order_no, rec.dated, 0, rec.quantity
    FROM received_shop_orders_dated rec
    WHERE rec.dated BETWEEN TO_DATE('&date3','DD/MM/YYYY') AND TO_DATE('&date4','DD/MM/YYYY')))
    GROUP BY order_no
    The problem is that sqlplus asks me for the parameter values and then creates it with these values as literal dates in the to_date function, those not asking for parameter values in runtime.
    How can I create it using parameters with no values at design time?
    Thanks.
    Leandro.

    if you want something like :
    select * from emp $where_clause;
    you can write a procedure with parameter and run it as dynamic sql for example
    create or replace procedure pr1 ( p_where   varchar2) is
    begin
      execute immediate 'create or replace view view_name as select * from emp '|| p_where;
    end pr1;
    /then run it on sql*plus
    SQL> exec pr1('where deptno = 10');
    make sure you give yourself "create any view" rights explicitly.
    HTH
    Ghulam

  • Create view With Ref cursor data

    Hi friends,
    I want to create view as follows.
    Example:
    Create or replace v_name
    select job,sal, <funcation>
    from emp;
    Note:- Function not having out parameter.
    Function returning ref cursor values datatype.
    Requirement:-
    I want to create view even function returing ref cursor datatype.
    Please advise how to create view.
    Regards,
    Kishore

    user7284612 wrote:
    Hi friends,
    I want to create view as follows.
    Example:
    Create or replace v_name
    select job,sal, <funcation>
    from emp;
    Note:- Function not having out parameter.
    Function returning ref cursor values datatype.
    Requirement:-
    I want to create view even function returing ref cursor datatype.
    Please advise how to create view.You perhaps are misunderstanding what a ref cursor is. It does not contain data like a table, so cannot be treated as one.
    Take a read of this:
    PL/SQL 101 : Understanding Ref Cursors

  • Error creating view with tables of other user

    I am creating of view containing two tables of another user. I
    am a dba-user.
    The statement looks like this:
    CREATE VIEW TEST
    (SELECT ...
    FROM DWH.TABLE_A A, DWH.TABLE_B B
    WHERE A.ID = B.ID)
    I get an error-message (ORA-00942: Table or view not found).
    When I create the view as user DWH, everything went OK. I don't
    think it has something to do with privileges since I am the dba-
    user.
    How can I create a view using other users tables?

    Hi
    To create view on table of another user you need to have select
    privilege grant directly to you - not to role granted to you. In
    your case you can select tables because you have granted dba
    role and it has select any table prvivilege, but you havent
    directly granted this rights without role.
    Regards

Maybe you are looking for