SQL for views with constraints
We use a product that requires us to have pk's on all of our views. So when I generate the SQL using DBMS_METADATA or using SQL Developer we have to keep the original scripts so that we can manually insert the constraint definition into the generated script.
I noted that while browsing the SQL tab for each view I can see the constraint in the view definition. So where is this tab generating it's SQL from? It's not in the text of the view, and dbms_metadata does not seem to do it.
It would be useful for me to be able to generate them with the constraint in the text already as this process that we do now is cumbersome.
Can anyone tell me where/how I can do that?
Cheers,
Henri
OK, here is little test:
alter view emp_sal
add constraint emp_sal_uk unique (ename) DISABLE NOVALIDATE ;
After that command the view definition is
CREATE OR REPLACE FORCE VIEW "SCOTT"."EMP_SAL" ("EMPNO", "ENAME", "SAL",
UNIQUE ("EMPNO") RELY DISABLE,
CONSTRAINT "ID_PK" PRIMARY KEY ("EMPNO") RELY DISABLE,
CONSTRAINT "EMP_SAL_UK" UNIQUE ("ENAME") DISABLE) AS
SELECT empno, ename, sal FROM emp;
so that the constraint becomes effectively inline. It is displayed with
select dbms_metadata.GET_DDL('VIEW', 'EMP_SAL') from dual;
Similar Messages
-
Aperture shared over a network for viewing with Front Row?
Aperture shared over a network for viewing with Front Row? I can view iPhoto from my laptop or desk top but I cannot find a way to share Aperture over the network.
If tested to work with other MacOs versions, this should be a main FAQ listed on Apple's Support website for Aperture and/Mac OSX.
-
Optimizing SQL for views on views
i'm trying to optimize the performance of a view, which joins 2
other views:
select *
from v1, v2
where v2.xxx = v1.xxx
when i select data from the view, i set a where clause that
results in only one matching row in the view v1 that can be
accessed by rowid (unique index). There is also a (none-unique)
index on the column xxx of that v2 view which should by used by
the optimizer (rule-based, 7.3.4.3.0).
But it isn't. Instead the database performs a full table scan of
the driving table of the v2 view, finds some rows and merges the
data with those from the v1 view. But as the v2 view is very
large it takes very long....
When i type
select * from v2 where xxx='abc'
the query executes qickly because the index on xxx is used.
What can prevent the optimizer from using the index on xxx in my
view?
I even tried to force use of the index by the INDEX hint but it
didn't work.
any help appreciated
thanks
nullThanks kgronau,
My Oracle gateway for SQL server is in a Linux box and obviously the SQL server in a windows box.
In that case how I would execute dg4msql_cvw.sql which is under $ORACLE_HOME/dg4msql/admin path of Linux server?
Regards
Satish -
SQL for View Definition using outer join
Hello everyone,
I am creating a view using the statement below
SELECT *
FROM table_a A
,table_b B
,table_c C
WHERE A.sg_code = B.sg_code and
B.st_code = 'E' and
A.sg_code = C.sg_code(+) and
C.st_code = 'T'
The structure of the view is as follows
View
sg_code| Name | start_date | end_date |
1 | Test |13-03-2008 | NULL |
Table_a
sg_code,Name
Table_b
sg_code,st_code,actual_date
the view can have a null for the column 'end_date'
This means there will not be a record inserted in the Table_b for end_date=null, there will only be a record for actual_date=start_date
In this scenario when I query the view I am not seeing the newly created record just because there is a condition "C.st_code = 'T'" with the outer join on the sg_code.
When I look into the individual tables I see the records.
Table A
Pg_code,Name
1 Test
Table B
Id pg_code As_of_date
1 1 13-03-2008
How should I modify my view definition so that I can query the view even if there is a null for 'end_date'
Thanks
fmthe last line should be:
C.st_code(+) = 'T'
by failing to include the (+) on that line, you made it NOT an outer join. an outer joined table must be outer joined on every where criteria, including to constants. -
How do I Reveal/Hide Hidden Layers for viewing with Acrobat Reader (iPad)?
Hi,
I've created a document in Quark Xpress with multiple layers which I then exported to a PDF. Using Acrobat Pro I created hotspots which revealed/hid these layers on rollover. It works perfectly on the desktop version of Acrobat Reader but not on Acrobat Reader for iPad (where the hidden layers are automatically switched on and touching the hotspots does not hide them). Does anybody know a good work around to this?There are many features which are possible in the desktop version of Adobe Reader which won't work in Reader for tablets. I think this is one of them. Probably no workaround possible until the feature is updated.
-
ORA-00933 - Error in PL/SQL for Form with report.
Hello,
I am getting this error :
failed to parse SQL query:
ORA-00933: SQL command not properly ended
and my PL/SQL function body returning SQL is as follows:
Declare
q varchar2(32767);
w varchar2(4000);
v_total varchar2(10);
Begin
v_total:='TOTAL' ;
q:=' SELECT ASR_DB_CLIENT.CLIENT_NAME, ';
q:=q||' ASR_DB_OIS.ACCT_NAME, ';
q:=q||' ASR_DB_OIS.ACCT_NBR, ';
q:=q||' ASR_DB_OIS.INCEPT_DT, ';
q:=q||' asr_db_prod.MKT_CODE, ';
q:=q||' asr_db_prod.asst_clss, ';
q:=q||' ASR_DB_OIS.PROD_CODE, ';
q:=q||' ASR_DB_OIS.GROUP_CODE, ';
q:=q||' ASR_DB_PLAN.TAX_STAT, ';
q:=q||' asr_db_clnt_type.clnt_type_name, ';
q:=q||' asr_db_plan_type.plan_type_name, ';
q:=q||' ASR_DB_OIS.ACCT_type, ';
q:=q||' ASR_DB_PLAN.CNTRY_CODE, ';
q:=q||' ASR_DB_OIS.DISCRET_FLAG, ';
q:=q||' ASR_DB_OIS.ASST_BAL ';
q:=q||' FROM ASR_DB_OIS, ASR_DB_PLAN, ASR_DB_CLIENT, ASR_DB_PROD, ';
q:=q||' asr_db_plan_type, ';
q:=q||' asr_db_Clnt_type ';
q:=q||' WHERE';
q:=q||' ASR_DB_OIS.PLAN_ID = ASR_DB_PLAN.PLAN_ID and ';
q:=q||' ASR_DB_OIS.as_of_dt = ASR_DB_PLAN.as_of_dt and ';
q:=q||' ASR_DB_PLAN.CLIENT_ID = ASR_DB_CLIENT.CLIENT_ID and ';
q:=q||' ASR_DB_OIS.as_of_dt = ASR_DB_CLIENT.as_of_dt and ';
q:=q||' asr_db_ois.prod_code = asr_db_prod.prod_code and ';
q:=q||' ASR_DB_PLAN.plan_type_code = ASR_DB_PLAN_type.plan_type_code and ';
q:=q||' ASR_DB_Client.clnt_type_code = ASR_DB_clnt_type.clnt_type_code and ';
q:=q||' ASR_DB_OIS.AS_OF_DT = :p99_asofdate ';
IF :P2_ROLLUPSLEEVE = 'RU'
THEN
q :=q||' and ASR_DB_OIS.PARENT_OIS_ID is null ';
Else
q :=q||' and ASR_DB_OIS.ACCT_TYPE like "%"'||v_total||'"%" ';
q :=q||' and ASR_DB_OIS.PARENT_OIS_ID is not null ';
END IF;
return q;
end;
Why this is failing ?
Is "%"'||v_total||'"%" '; incorrect ?
P2_ROLLUPSLEEVE is a radio button.
Please advise....
Thanks,
HMAnd
Also, I get the following error when I try few other things like
q :=q||' and ASR_DB_OIS.ACCT_TYPE = '||v_total||' ';
or
q :=q||' and ASR_DB_OIS.ACCT_TYPE = "||v_total||" ';
failed to parse SQL query:
ORA-00904: "TOTAL": invalid identifier
And
ORA-06550: line 43, column 41: PLS-00103: Encountered the symbol "TOTAL" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between || member SUBMULTISET_ The symbol "* was inserted before "TOTAL" to continue.
When I try
q :=q||' and ASR_DB_OIS.ACCT_TYPE = "'TOTAL'" ';
Any helpful tips will be much appreciated.
Thanks,
HM -
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,
KarthikHi, 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. -
Need help in creating a view with Encryption for hiding the code used by the multiple users
Hi,
Can anyone help me out in creating view with encryption data to hide the stored procedure logic with other users.
I have create a stored procedure with encryted view but while running this manually temporary views are getting created, therefore the problem is if there are 500 entries then 500 temp views will get created.
Any solution to aviod creating temporary views, please refer my code below
USE [etl_validation]
GO
/****** Object: StoredProcedure [dbo].[Pr_DBAccess_mod] Script Date: 05/23/2014 12:53:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Pr_DBAccess_mod](@ETL_CONFIG_ID INT)
AS
BEGIN
DECLARE @openquery NVARCHAR(MAX),
@DATABASENAME NVARCHAR(100),
@HIERNAME NVARCHAR(100),
@TABLENAME NVARCHAR(100),
@SERVERTYPE NVARCHAR(100),
@SERVERNAME NVARCHAR(100),
@USERNAME NVARCHAR(100),
@PASSWORD NVARCHAR(100),
@ETL_CONFIG_IDN NVARCHAR(100);
SET @ETL_CONFIG_IDN=CAST(@ETL_CONFIG_ID AS NVARCHAR);
SET @TABLENAME='Department';
SET @SERVERTYPE='SQL';
SET @SERVERNAME ='192.168.31.176';
SET @DATABASENAME='AdventureWorks2008R2';
SET @HIERNAME = 'HumanResources';
IF @SERVERTYPE='SQL'
BEGIN
/*SET @openquery= 'SELECT * INTO ##TestTable
FROM OPENROWSET(''SQLNCLI'',''server=192.168.31.176;Trusted_Connection=yes;'','''+@query+''')'
SET @openquery= 'CREATE VIEW '+@TABLENAME+@ETL_CONFIG_IDN+
' WITH ENCRYPTION AS SELECT * FROM OPENROWSET(''SQLNCLI'',''SERVER='+@SERVERNAME+';TRUSTED_CONNECTION=YES;'',''SELECT * FROM '+@DATABASENAME+'.'+@HIERNAME+'.'+@TABLENAME+''')'
SELECT @openquery
END
EXECUTE sp_executesql @openquery
ENDHi aa_rif,
According to your description and code message, you execute the sp_executesql statement in your stored procedure, it indeed create many views with a tablename and ETL_CONFIG_ID named. If you need not to use these temporary views, you can delete them when
it contains the tablename in one view name.
In addition, if you want to create view with encryption in SQL Server, you can use directly the ENCRYPTION option to encrypt the T-SQL of a view in create view commands, for more information, see:
http://learnsqlserver.in/4/Create-View-With-Encryption.aspx. if not, you can descript more detail about requriements, so that more forum members can involve into the thread and help you
out.
Regards,
Sofiya Li
Sofiya Li
TechNet Community Support -
Are Cube organized materialized view with Year to Date calculated measure eligible for Query Rewrite
Hi,
Will appreciate if someone can help me with a question regarding Cube organized MV (OLAP).
Does cube organized materialized view with calculated measures based on time series Year to date, inception to date eg.
SUM(FCT_POSITION.BASE_REALIZED_PNL) OVER (HIERARCHY DIM_CALENDAR.CALENDAR BETWEEN UNBOUNDED PRECEDING AND CURRENT MEMBER WITHIN ANCESTOR AT DIMENSION LEVEL DIM_CALENDAR."YEAR")
are eligible for query rewrites or these are considered advanced for query rewrite purposes.
I was hoping to find an example with YTD window function on physical fact dim tables with optimizer rewriting it to Cube Org. MV but not much success.
Thanks in advanceI dont think this is possible.
(My own reasoning)
Part of the reason query rewrite works for base measures only (not calc measures in olap like ytd would be) is due to the fact that the data is staged in olap but its lineage is understandable via the olap cube mappings. That dependency/source identification is lost when we build calculated measures in olap and i think its almost impossible for optimizer to understand the finer points relating to an olap calculation defined via olap calculation (olap dml or olap expression) and also match it with the equivalent calculation using relational sql expression. The difficulty may be because both the olap ytd as well as relational ytd defined via sum() over (partition by ... order by ...) have many non-standard variations of the same calculation/definition. E.g: You can choose to use or choose not to use the option relating to IGNORE NULLs within the sql analytic function. OLAP defn may use NASKIP or NASKIP2.
I tried to search for query rewrite solutions for Inventory stock based calculations (aggregation along time=last value along time) and see if olap cube with cube aggregation option set to "Last non-na hierarchical value" works as an alternative to relational calculation. My experience has been that its not possible. You can do it relationally or you can do it via olap but your application needs to be aware of each and make the appropriate backend sql/call. In such cases, you cannot make olap (aw/cubes/dimensions) appear magically behind the scenes to fulfill the query execution while appearing to work relationally.
HTH
Shankar -
SQL Developer - Data Modeler - Trigger for FK arc constraints
In the preferences there is an option "Data Modeler > DDL > Create Triggers for FK arc constraints". I think Oracle recomments to use constraints instead of triggers where it is possible. Can anyone from the Development team tell me why here is just the option to create triggers and not also the option to create table level constraints for FK arc constraints? If it is possible I'd like to have this option. My suggetion is to use the following check constraint construction for creation: nvl2(FK_IDx,1,0)+nvl2(FK_IDy,1,0)+...+nvl2(FK_IDz,1,0)=1 or with not only single FK columns: nvl2(FK_IDx1,1,0)+nvl2(FK_IDx2,1,0)+nvl2(FK_IDy,2,0)+...+nvl2(FK_IDz,2,0)=2. Please tell me if that would be possible (and maybe available in next Version) or why it is better to user triggers instead.
Thanks
/cThe Data Modeler forum is at:
SQL Developer Data Modeler -
Loading millions of rows using SQL*loader to a table with constraints
I have a table with constraints and I need to load millions of rows in it using SQL*Loader.
What is the best way to do this, means what SQL*Loader options to use, for getting the best loading performance and how to deal with constraints?
Regards- check if your table has check constraints (like column not null)
if you trust the data in the file you have to load you can disable this constrainst and after the loader enable this constrainst.
- Check if you can modify the table and place it in nologging mode (generate less redo but ONLY is SOME Conditions)
Hope it helps
Rui Madaleno -
Updatable View issues: cannot select FOR UPDATE from view with DI
Hi All,
I have a simple view XY and an instead of trigger on that to insert data into one table which is used in the my view. When I do insert statement on view XY it is working fine from sql but when i used same thing with page process of " Process Row of XY Automatic Row Processing (DML) " i am getting following error. I am using APEX 3.0 . Please help me.
ORA-20001: Error in DML: p_rowid=xxxx, p_alt_rowid=abc, p_rowid2=, p_alt_rowid2=. ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
ThanksJames,
are you already on 3.0.1.00.07 or 3.0.1.00.08? Have a look at the release notes, it says something about a bug fix for some occurrences of ORA-02014.
Also have a look at the new substitution value/item FSP_DML_LOCK_ROW which turns locking off if you set it to FALSE. See http://www.oracle.com/technology/products/database/application_express/html/3.0.1_readme.html#CHDIDIAF and also http://download-west.oracle.com/docs/cd/B32472_01/doc/appdev.300/b32471/advnc.htm#BCGFDAIJ
Patrick
My APEX Blog: http://inside-apex.blogspot.com
The ApexLib Framework: http://apexlib.sourceforge.net
The APEX Builder Plugin: http://apexplugin.sourceforge.net/ New! -
how do i access the data stored on my time capsule? for example, if i try to view a photo, i get the option to "view with iphoto" but when i click on "view with iphoto" nothing happens. i'm having similar trouble openning up movies, music, etc. it appears as though the files exist / saved on the time capsule (because i can see how much storage they consume), but i can't open them. thanks!
Unfortunately, Apple removed the feature to "browse backups" in Time Machine backups of iPhoto a few years ago.
You have to restore the entire iPhoto library to a separate location to be able to "see" it, and then choose the specific images that you want use.
For complete details, see #15 in Pondini's excellent support document Time Machine -- FAQ. Check the information in the pink box there.
Frequently Asked Questions -
How to build sql query for view object at run time
Hi,
I have a LOV on my form that is created from a view object.
View object is read-only and is created from a SQL query.
SQL query consists of few input parameters and table joins.
My scenario is such that if input parameters are passed, i have to join extra tables, otherwise, only one table can fetch the results I need.
Can anyone please suggest, how I can solve this? I want to build the query for view object at run time based on the values passed to input parameters.
Thanks
Srikanth AddankiAs I understand you want to change the query at run time.
If this is what you want, you can use setQuery Method then use executeQuery.
http://download.oracle.com/docs/cd/B14099_19/web.1012/b14022/oracle/jbo/server/ViewObjectImpl.html#setQuery_java_lang_String_ -
As a new user of Apple TV, I need some assistance.When I rent a movie on iTunes and download for viewing later, say a day or two later, It seems to load itself all over again with a msg saying ready to view in 25 mins ! So having waited the 25 mins movie starts and runs for maybe 1 hour and the pauses for maybe 5 mins while it seems to load again . any help appreciated
Welcome to the Apple Community.
If you use the Apple TV for something else or turn it off it will erase whatever is on it's drive. If you are going to download content for later viewing you might consider doing it on the computer, downloads don't disappear until they expire and you can watch them as many times as you want.
Maybe you are looking for
-
I've changed my "My Music" folder and now I cant get iTunes to run!
Ok, Maybe some has a fix for this - I am running Vista and I have moved my "My Music" folder from its original location to its own dedicated hard drive (F:). Now when I install and try to run any iTunes version I get the error "The folder iTunes cann
-
Purchase Organation Disappearing after cancelliation of Assignments
HI, step1: i was created purchase requisation Of Type K - Cost center using me51n Transaction. step2: after that using ME54n Tcode i was release that purchase Requisation and saved. step 3: after releasing go to T code ME57 and execute Me57 Tcode fo
-
Does anyone know where the iWeb data files are located or what they are called? I can't find them. I looked in Finder for files named the same as my website, but found nothing. Any help would be appreciated.
-
Hi, We are implementing SRM 4.0, extended classic scenario We have added some custom fields at the header level in the structure INCL_EEW_PD_HEADER_CSF_PO and INCL_EEW_PD_HEADER_CSF as per sap note 672960. We have implemented the badi BBP_ECS_PO_OUT_
-
Installation Error for NW2004s Java SP9 Trial
Hello, I tried to install trial version on XP professional as well as Windows 2003 server (separate computers). Every time I get error exactly at the same place. I go through first 3 / 4 screens, when I specify correct JCE zip file. It fails with fol