Is not null and null join
Hi, I am trying to correctly display a list of tasks for a project, but without a join with the project number (which I was aware of) and the employee table, I get over 500 results.The task can be created without a responsible employee of her as well, so that the page does not require the field to fill.
Here's the SQL, someone at - it ideas?
select
pd.pk_proj_detail_id "Task Number",
pd.task_title "Task Title",
pd.DETAIL_STATUS "Task Status",
pm.name "Associated Project",
pps.last_name||', '||pps.first_name||', '||pps.middle_initial||'.' "Assigned Employee",
pd.TRACKIT_NUMBER "TrackIt! Number",
pd.CREATEBY_DATE "Date Entered",
pd.DATE_BEGIN "Date Began",
pd.ESTIMATED_DATE "Estimated Completion Date",
pd.DATE_END "Date Completed"
from
PROTRAC_DETAIL pd,
protrac_master pm,
cobr.vw_pps_payroll pps,
resources r
where
pd.fk_proj_master_id = pm.PK_PROJ_MASTER_ID
and r.fk_master_id = pm.PK_PROJ_MASTER_ID
and (r.emp_id = pps.emple_no
or r.emp_id is null)
Hello
Replace:
res.last_name||', '||res.first_name||', '||res.middle_initial||'.' "Assigned Employee",
with
res.last_name
|| CASE
WHEN res.first_name IS NOT NULL
THEN ', ' || res.first_name
END
|| CASE
WHEN res.middle_initial IS NOT NULL
THEN ', ' || res.middle_initial || '.'
END AS "Assigned Employee",
Here's why:
If all res columns have a NULL value (which can happen because of the outer join), then
res.last_name||', '||res.first_name||', '||res.middle_initial||'.' "Assigned Employee",
is equivalent to
NULL ||', '|| NULL ||', '|| NULL ||'.' "Assigned Employee",
The punctuation is there to separate the three columns.
If a column if the NULL value, you don't need to separate, so you need to make some sort of if-else operation to test if the punctuation is needed and show only if it is necessary.
CASE expressions above will also give you a nicer output if some columns are set to NULL, but others are not.
(For example, if the middle_initials are rarely saved.)
Tags: Database
Similar Questions
-
Hello guys,.
with the example I want to insert the new translation into a table of conversion below, but
the NOT IN clause does not work. I also tried an ANTI-JOINTURE after reading some
why NOT IN may not work but the ANTI-JOINTURE did not work either.
The result of the query above is 0 rows inserted. There are about 1000 lines that already exist and I want to avoid
insertion of those, once again. Note that the text is not even the ID or the SOURCE.
INSERT INTO T_Translations
(
SELECT ID, SOURCE, TEXT, OF
(
SELECT distinct ID, SOURCE, DOMAIN,
TransText AS TEXT
DE)
-Deutsche text aus TKZ_1
SELECT TransText OF
-... - Source table 1
UNION ALL
-... - Source table 2
UNION ALL
-... - Source table 3
UNION ALL
-... - Source table 4
) WHERE TransText IS NOT NULL
)
WHEN NOT IN TEXT (SELECT TEXT FROM T_Translations)
);
Any suggestions?
Thank you very much.It might be a problem with the alias.
The TEXT column can come from many different parts of your query. I changed it a bit and removed unnecessary inline views.
INSERT INTO T_Translations i SELECT distinct v.ID, v.SOURCE, v.DOMAIN, v.TransText FROM ( --Deutsche Texte aus TKZ_1 SELECT TransText FROM --...--Source Table 1 UNION ALL --...--Source Table 2 UNION ALL --...--Source Table 3 UNION ALL --...--Source Table 4 ) v WHERE v.TransText IS NOT NULL AND not exists (SELECT null FROM T_Translations t2 where v.TransText = t2.TEXT ) ;
-
What is the difference between primary key and unique indexes with forced not null?
Primary key is = unique index + not null?
The short answer is Yes.
However, even if the primary key, applying both uniquness and not null, there is a notion of "special".
You can only have one primary key in tables, but you can have multiple unique indexes and constraints not null.
See: https://asktom.oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8743855576462
-
Purpose of "null is not null" and "null is null" statements
Hi all
Please can someone explain the purpose of these statements and what it means.
1 null is not null
2 null is null
(a) NULL should be treated in a special way in the comparisons - see values NULL SQL - IS NULL and IS NOT NULL or SQL ISNULL(), NVL(), IFNULL() and COALESCE() functions
(b) If you really clauses Null is not null or Null is null (meaning: the first is not a variable) it could replace "always wrong" and "always true"; Maybe in some test queries
-
Can check and not Null added to the names Administration constraints?
I don't know if this is the right place to make a request for improvement, but it would be possible to add "and not Null Check constraints" in Tools-> object names Administration?
It would be extremely useful for those who use them and also apply naming rules.
Thank youI logged an ER
Philippe
-
Two tables provided, how you retrieve the values in two columns using values in a column (the pass get values. If col. A is not null values and get the pass. B if col. A is null)?
Guessing
Select nvl (x.col_a, y.col_b) the_column
from table_1 x,.
table_2 y
where x.pk = y.pk
Concerning
Etbin
-
Hide and show region - open if Item not Null
Hello
I use APEX 4.0 and can not find a way to get the skin and see the region develop if a Page element has a value (is not Null) in the region, without clicking the sign more. I would like it done automatically based on an item that has a value or not. null or not null. I know how to have always hide it and see the region see the/develop once the shape is present. But if the item is null the region hosts not on the loading of the page, but when an element has the value when the page opens, I want the area to be open / extend without having to click the sign more. I searched the forum and found a large number of threads to have just the Hide and Show open area / develop once the form on the page is open, but not what I need now. Thanks for reading this thread and look forward to a support for this issue.Hi Charles,
I created a dynamic action on page 7, it works as expected.
This code will only work with your current theme, because the rocker is made according to the css class of the > icon (as you can see in the live action)
Thank you
-
Hi all
Is it possible to use the Index BITMAP for a NOT NULL condition?
>
CREATE a BITMAP of INDEX x_ix FOR tab (x);
SELECT *.
TAB
WHERE x IS NOT NULL
>
Thank you!user3646231 wrote:
You say that :) to hopeHere it is:
Your test is a good effort - but it needs a little more.
Your question is "is it possible...". «, not "If Oracle always...» »
Your demonstration showed an example where the choice of plan Oracle has surprised you (and me). Now, you need run the query with index indicator (because if the indexed access path is legal, must be taken an indexed correctly suggested path).
I just ran a similar test (1 line of 100,000), with the following results:
SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------ SQL_ID 52q6gxkscvg9v, child number 0 ------------------------------------- select /*+ index(t1(n1)) */ * from t1 where n1 is not null Plan hash value: 2828957992 ---------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | ---------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 1859 | | 1 | TABLE ACCESS BY INDEX ROWID | T1 | 1 | 118 | 1859 | | 2 | BITMAP CONVERSION TO ROWIDS| | | | | |* 3 | BITMAP INDEX FULL SCAN | T1_N1 | | | | ---------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter("N1" IS NOT NULL)
You will notice that the cost of the query is unreasonable - and without the suspicion my test showed Oracle taking the full analysis at a much lower cost.
If your test has actually demonstrated a bug in the costing, explaining why Oracle does not automatically take a path that seems reasonable.The above output comes from 11.2.0.3, but I had the same thing with 11.1.0.7
Concerning
Jonathan Lewis
http://jonathanlewis.WordPress.com
Author: core Oracle -
The doc is correct on the constraint not null and scan limited index full?
Gave birth to the large [url http://forums.oracle.com/forums/thread.jspa?messageID=9313643] another thread:
Jonathan Lewis wrote:
Just below where Hemant pointed to in the other thread, http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/indexiot.htm#sthref314
>
I wasn't expecting to see because the doc said about scan limited index full "...". and at least one column in the index key has the NOT NULL constraint,"which would be foolish to say if the rowid was what filled that. There are currently only 2 factory codes and code 1 company (not nulls - Oracle does know that?), so I was kind of expected Oracle to reorder the predicates with an index skip scan. Take a fresh look on the doc, I wonder if I should not specify the company code in the query and maybe spend employee and job_number in the index. I hope it's obvious that this index has been added for other queries. This request could be taken out a change in the requirements of anyway, but I don't know when.
If you wear it as a separate thread, I'll take a look.
Can you give a reference to the manual - the comment you quoted may not be correct.
(Somehow I have the feeling that we had this conversation before, perhaps in a forum that no longer exists. "(Or was it all just a dream)."
Edit: Also seen in
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28274/optimops.htm#i52044
http://download.Oracle.com/docs/CD/B14117_01/server.101/b10752/optimops.htm#51111
http://download.Oracle.com/docs/CD/F49540_01/doc/server.815/a67781/c20b_ops.htm#11004
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14211/optimops.htm#i52044
and everything on the net.
Edited by: jgarry 26 January 2011 17:41
2nd edition: link fix that edit may 1 have ransacked.
Edited by: jgarry January 27, 2011 10:40Joel,
I just had this 'already seen' (new) sense to speak of it.
Mentioning the reference 11.1 gave you:
+ "Index full scans are an alternative to a full table scan when the index contains all the columns needed for the query, and at least in the index key column has the constraint NOT NULL. A full scan can access the data of the index itself, without access to the table ' + '.
This so obviously must be bad that I couldn't decide if I was proven wrong or was amazed to find that I couldn't he show the falsity. (Just because something is obvious, it does not mean it is true – Terry Pratchett.)
However, here is the obvious counter-example - that I came across 8.1.7.4 because it's the oldest version of Oracle that I have now:
create table t1 as select rownum id1, rownum id2, rownum id3, lpad(rownum,10,'0') small_vc, rpad('x',100) padding from all_objects where rownum <= 10000 ; create index t1_i1 on t1(id1, id2, id3); begin dbms_stats.gather_table_stats( ownname => user, tabname =>'T1', cascade => true ); end; / set autotrace traceonly explain select /*+ index_ffs(t1) */ id1, id3 from t1 where id2 = 99 ;
No 'NOT NULL columns". But any line I will have a (non-null) value for id2, then it should be in the index - then Oracle should be able to do a full scan and get the right answer. Here is the map (I have no need of Council - but your configuration may be different):
Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4 Card=1 Bytes=12) 1 0 INDEX (FAST FULL SCAN) OF 'T1_I1' (NON-UNIQUE) (Cost=4 Card=1 Bytes=12)
If you change the predicate to: "id2 is zero", then the only legal path is an analysis.
Concerning
Jonathan Lewis
http://jonathanlewis.WordPress.com
http://www.jlcomp.demon.co.UK+ "I believe in the evidence. I believe in observation, measurement and reasoning, confirmed by independent observers. I'll believe anything, no matter how wild and ridiculous, if there is evidence for it. The wildest and most ridiculous something is, however, the firmer and more solid, the evidence should be. » +
Isaac Asimov -
Primary key and unique key not Null
Hello gurus,
Asked in an interview about the difference between primary and unique keys.
I talked Unique keys can accept null values, but they are unique through should have the table. So, the next question asked me was "a Unique key NOT NULL can be treated as the primary key?
Tricky question! :)
I said yes! that it meets the requirement to be a primary key for this particular table, but since this isn't really a primary key, that it can't be covered in the foreign keys.
The interviewer wanted just a Yes or no.
Can someone please put some of this?
Thanks in advance!Two things.
1. unique can also be referenced as a foreign key. If your statement "but because this isn't really a primary key may not be seized key foreign." is not true.
2. primary key and Unique key are different (for example you can have more than one UK in a table but PK's alone) and to know the difference, read some RDBMS concepts.I'm curious to know what is the outcome of your interview? ;)
-
Hide/show text when field null and not null
I discovered how only display a field in a query using Dreamweaver 8, PHP, and MySQL when the value of the field is zero in showing this:
http://www.Adobe.com/cfusion/webforums/Forum/MessageView.cfm?forumid=12 & catid = 189 & ThreadID = 1005921 & arctab = & highlight_key = y & keyword1 = see the % 20region
However, how can I put text next to the field data when there are data in the field? Therefore, 1) hide textes_ data when the value in the record field is zero and 2) show text data and when the fields of records is not null.
I tried to put the text with the echo, but then the text is displayed without the data from the field when the field is null.
The code I have so far is:
<? PHP if (! is_null ($row_rsProperties ['US_List_Price'])) {echo $row_rsProperties ['US_List_Price'] ;}? >
rsProperties is the recordset and US_List_Price is the field
Thank you!
dulcey1 wrote:
> I tried to format the text with the echo, but then the text is displayed
> without data field when the field is null.
>
> The code I have so far is:
>
> $row_rsProperties ["US_List_Price"] ;} ?>The is_null() function checks a NULL value. I suspect that your
the fields are empty instead of NULL. Change the code to do this:
"Text". $row_rsProperties ['US_List_Price'] ;} ?>--
Adobe Community Expert David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
How to combine two conditions: there is and point not null?
Hello!
I have a flash chart area I would like to show only if two conditions are true.
The first condition is the following:
There are (at least a line returns the SQL query):
And the second condition would be:select 1 from observatoire.fiche aa, observatoire.activite_faite bb where aa.fiche_id = bb.fiche_id and bb.fiche_id = aa.fiche_id AND bb.activites_id = TO_NUMBER(:P23_ACTIVITES_ID) AND TRUNC(aa.date_activite, 'YYYY') = TRUNC(TO_DATE(:P23_ANNEE, 'YYYY'), 'YYYY')
Point not null:
How to combine these two conditions in one display condition?P23_ACTIVITES_ID
Thank you.
ChristianHello
The problem is that you do-
TO_NUMBER(:P23_ACTIVITES_ID)
When you leave the value of Null return like this, you will see "null %" generally used in session state (i.e., it is not actually null). Of course 'null %' cannot be converted to a number, from which the error you see.
A simple solution would be to make your value null return value-1 or another value that is guaranteed not to be a piece of identification (and alternative is to convert the real null null % thanks to a process of App/Page etc (if you search this forum you will find a few examples on how to do this).) Another alternative is to use a DECODING to detect the '% null' etc.
Hope this helps,
John.
--------------------------------------------
Blog: http://jes.blogs.shellprompt.net
Work: http://www.apex-evangelists.com
Author of Pro Application Express: http://tinyurl.com/3gu7cd
AWARDS: Don't forget to mark correct or useful posts on the forum, not only for my answers, but for everyone! -
filter (NULL IS NOT NULL) plan to explain?
Hi all
Can someone please explain what this explain plan statement means? I see a (NULL IS NOT NULL) filter as first statement - could not understand why it came so Googling.
My query is used:
My Plan to explain:EXPLAIN PLAN FOR MERGE INTO summary_bysrccd USING (SELECT LAST_DAY(TRUNC(to_timestamp(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS SUMMARY_DATE, os.acctnum, ol.sourcecode AS sourcecode, ol.sourcename AS sourcename, count(1) cnt_articleview FROM article_views os , master_sourcecode ol where os.sourcecode = ol.sourcecode AND os.acctnum IS NOT NULL AND ol.sourcecode IS NOT NULL AND os.requestdatetime IS NOT NULL AND UPPER(os.success_ind) = 'S' AND ( ('INCR' = 'FULL' AND (get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('23-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('27-AUG-2011 23:59:59','DD-MON-YYYY HH24:MI:SS') AND os.entry_CreatedDate BETWEEN TO_DATE('22-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('28-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') )) OR ('INCR' = 'FULL' AND os.entry_createddate BETWEEN TO_DATE('23-AUG-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('27-AUG-2011 23:59:59','DD-MON-YYYY HH24:MI:SS') ) ) group by LAST_DAY(TRUNC(to_timestamp(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,ol.sourcecode,ol.sourcename) mrg_query ON (ods_av_summary_bysrccd.acctnum = mrg_query.acctnum AND ods_av_summary_bysrccd.summary_date=mrg_query.summary_date AND ods_av_summary_bysrccd.sourcecode=mrg_query.sourcecode) WHEN NOT MATCHED THEN INSERT (SUMMARY_date,ACCTNUM,SOURCECODE,SOURCENAME,CNT_ARTICLEVIEW,ENTRY_LASTUPDATEDDATE) VALUES(mrg_query.summary_date,mrg_query.acctnum,mrg_query.sourcecode,mrg_query.sourcename, mrg_query.cnt_articleview,sysdate) WHEN MATCHED THEN UPDATE SET ods_av_summary_bysrccd.cnt_articleview= CASE WHEN NVL('INCR','INCR') = 'FULL' THEN mrg_query.cnt_articleview ELSE ods_av_summary_bysrccd.cnt_articleview+mrg_query.cnt_articleview END, ods_av_summary_bysrccd.entry_lastupdateddate=sysdate;
SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 268591246 ----------------------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop | ----------------------------------------------------------------------------------------------------------------------------------------------- | 0 | MERGE STATEMENT | | 1 | 456 | | 3 (0)| 00:00:01 | | | | 1 | MERGE | ODS_AV_SUMMARY_BYSRCCD | | | | | | | | | 2 | VIEW | | | | | | | | | | 3 | NESTED LOOPS OUTER | | 1 | 417 | | 3 (0)| 00:00:01 | | | | 4 | VIEW | | 1 | 360 | | 5 (100)| 00:00:01 | | | | 5 | SORT GROUP BY | | 1 | 73 | 595M| | | | | PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |* 6 | FILTER | | | | | | | | | |* 7 | HASH JOIN | | 6975K| 485M| 3944K| 17594 (1)| 00:03:32 | | | | 8 | TABLE ACCESS FULL | ODS_MASTER_SOURCECODE | 84021 | 2953K| | 273 (1)| 00:00:04 | | | |* 9 | TABLE ACCESS BY GLOBAL INDEX ROWID| ODS_ARTICLE_VIEWS | 7007K| 247M| | 826 (0)| 00:00:10 | 33 | 33 | |* 10 | INDEX FULL SCAN | IDX_AV_ACCTNUM | 25M| | | 26 (0)| 00:00:01 | | | | 11 | TABLE ACCESS BY GLOBAL INDEX ROWID | ODS_AV_SUMMARY_BYSRCCD | 1 | 57 | | 3 (0)| 00:00:01 | ROWID | ROWID | |* 12 | INDEX UNIQUE SCAN | ODS_AV_SUMMARY_BYSRCCD_PK | 1 | | | 2 (0)| 00:00:01 | | | ----------------------------------------------------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 6 - filter(NULL IS NOT NULL) 7 - access("OS"."SOURCECODE"="OL"."SOURCECODE") 9 - filter("OS"."REQUESTDATETIME" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-08-23 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-08-27 23:59:59', 'syyyy-mm-dd hh24:mi:ss') AND UPPER("OS"."SUCCESS_IND")='S') 10 - filter("OS"."ACCTNUM" IS NOT NULL) 12 - access("ODS_AV_SUMMARY_BYSRCCD"."SUMMARY_DATE"(+)=INTERNAL_FUNCTION("MRG_QUERY"."SUMMARY_DATE") AND "ODS_AV_SUMMARY_BYSRCCD"."ACCTNUM"(+)="MRG_QUERY"."ACCTNUM" AND "ODS_AV_SUMMARY_BYSRCCD"."SOURCECODE"(+)="MRG_QUERY"."SOURCECODE") Note ----- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - dynamic sampling used for this statement
This filter appears usually when the CBO has found a conflict between your predicates WHERE clause and declarative constraints on the tables involved.
For example, suppose that the EMP table had this constraint:
CHECK(empno > 0)
And you were to interrogate the EMP with this query:
select * from emp where empno < 0
You will find that the NULL value is NOT NULL filter in the execution plan.
-
In our 10g to 11g migration, we have identified a strange problem:
With this DDL:
This work of SELECTION very well and always return data T3 because one of the T2 value is recovereddrop table T1 cascade constraints; drop table T2 cascade constraints; drop table T3 cascade constraints; drop table T4 cascade constraints; -------------------------------------------------------- -- DDL for Table T1 -------------------------------------------------------- CREATE TABLE "T1" ( "T1_PK" NUMBER(4,0), "T1_DATA" VARCHAR2(20 BYTE) ); -------------------------------------------------------- -- DDL for Table T2 -------------------------------------------------------- CREATE TABLE "T2" ( "T2_PK" NUMBER(4,0), "T2_T1_FK" NUMBER(4,0), "T2_DATA" VARCHAR2(20 BYTE) ); -------------------------------------------------------- -- DDL for Table T3 -------------------------------------------------------- CREATE TABLE "T3" ( "T3_PK" NUMBER(4,0), "T3_T2_FK" NUMBER(4,0), "T3_DATA" VARCHAR2(20 BYTE) ); -------------------------------------------------------- -- DDL for Table T4 -------------------------------------------------------- CREATE TABLE "T4" ( "T4_PK" NUMBER(4,0), "T4_T2_FK" NUMBER(4,0), "T4_DISC" CHAR(1 BYTE) ); REM INSERTING into T1 Insert into T1 (T1_PK,T1_DATA) values (1,'T1_1'); Insert into T1 (T1_PK,T1_DATA) values (2,'T1_2'); REM INSERTING into PERS_ADM.T2 Insert into T2 (T2_PK,T2_T1_FK,T2_DATA) values (1,1,'T2_1'); Insert into T2 (T2_PK,T2_T1_FK,T2_DATA) values (2,2,'T2_2'); Insert into T2 (T2_PK,T2_T1_FK,T2_DATA) values (3,1,'T2_3'); REM INSERTING into PERS_ADM.T3 Insert into T3 (T3_PK,T3_T2_FK,T3_DATA) values (1,1,'T3_1'); Insert into T3 (T3_PK,T3_T2_FK,T3_DATA) values (2,2,'T3_2'); Insert into T3 (T3_PK,T3_T2_FK,T3_DATA) values (3,1,'T3_3'); REM INSERTING into PERS_ADM.T4 Insert into T4 (T4_PK,T4_T2_FK,T4_DISC) values (1,1,'1'); Insert into T4 (T4_PK,T4_T2_FK,T4_DISC) values (2,2,'1'); Insert into T4 (T4_PK,T4_T2_FK,T4_DISC) values (3,1,'0');
but when we activate restriction non-zero in the PK fields:select * from T1 left join (select T2.* from T2 inner join T4 on T4.T4_T2_FK = T2.T2_PK and T4.T4_DISC = 0) T2A on T2A.T2_T1_FK = T1.T1_PK left join (select T2.* from T2 inner join T4 on T4.T4_T2_FK = T2.T2_PK and T4.T4_DISC = 1) T2B on T2B.T2_T1_FK = T1.T1_PK left join T3 on T3.T3_T2_FK = nvl(T2A.T2_PK, T2B.T2_PK)
the nvl function is not used!-------------------------------------------------------- -- Constraints for Table T1 -------------------------------------------------------- ALTER TABLE "T1" MODIFY ("T1_PK" NOT NULL ENABLE); -------------------------------------------------------- -- Constraints for Table T2 -------------------------------------------------------- ALTER TABLE "T2" MODIFY ("T2_PK" NOT NULL ENABLE); -------------------------------------------------------- -- Constraints for Table T3 -------------------------------------------------------- ALTER TABLE "T3" MODIFY ("T3_PK" NOT NULL ENABLE); -------------------------------------------------------- -- Constraints for Table T4 -------------------------------------------------------- ALTER TABLE "T4" MODIFY ("T4_PK" NOT NULL ENABLE);
It seems that Oracle was so adept at realizing that a field not null can never be null, decide not to apply the nvl function
Any idea?Can you just clarify what the problem?
I see no difference in 11.2.0.2 - plan looks the same, data looks the same. Am I missing something?SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production PL/SQL Release 11.2.0.2.0 - Production CORE 11.2.0.2.0 Production TNS for Linux: Version 11.2.0.2.0 - Production NLSRTL Version 11.2.0.2.0 - Production SQL> set autotrace on SQL> select * 2 from T1 3 left join (select T2.* from T2 inner join T4 on T4.T4_T2_FK = T2.T2_PK and T4.T4_DISC = 0) T2A on T2A.T2_T1_FK = T1.T1_PK 4 left join (select T2.* from T2 inner join T4 on T4.T4_T2_FK = T2.T2_PK and T4.T4_DISC = 1) T2B on T2B.T2_T1_FK = T1.T1_PK 5 left join T3 on T3.T3_T2_FK = nvl(T2A.T2_PK, T2B.T2_PK); T1_PK T1_DATA T2_PK T2_T1_FK T2_DATA T2_PK T2_T1_FK T2_DATA T3_PK T3_T2_FK T3 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - 1 T1_1 1 1 T2_1 1 1 T2_1 1 1 T3_1 2 T1_2 2 2 T2_2 2 2 T3_2 1 T1_1 1 1 T2_1 1 1 T2_1 3 1 T3_3 Execution Plan ---------------------------------------------------------- Plan hash value: 3187431534 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3 | 417 | 27 (12)| 00:00:01 | |* 1 | HASH JOIN OUTER | | 3 | 417 | 27 (12)| 00:00:01 | | 2 | VIEW | | 2 | 202 | 22 (10)| 00:00:01 | |* 3 | HASH JOIN OUTER | | 2 | 202 | 22 (10)| 00:00:01 | |* 4 | HASH JOIN OUTER | | 2 | 126 | 13 (8)| 00:00:01 | | 5 | TABLE ACCESS FULL | T1 | 2 | 50 | 4 (0)| 00:00:01 | | 6 | VIEW | | 1 | 38 | 9 (12)| 00:00:01 | |* 7 | HASH JOIN | | 1 | 54 | 9 (12)| 00:00:01 | |* 8 | TABLE ACCESS FULL| T4 | 1 | 16 | 4 (0)| 00:00:01 | | 9 | TABLE ACCESS FULL| T2 | 3 | 114 | 4 (0)| 00:00:01 | | 10 | VIEW | | 2 | 76 | 9 (12)| 00:00:01 | |* 11 | HASH JOIN | | 2 | 108 | 9 (12)| 00:00:01 | |* 12 | TABLE ACCESS FULL | T4 | 2 | 32 | 4 (0)| 00:00:01 | | 13 | TABLE ACCESS FULL | T2 | 3 | 114 | 4 (0)| 00:00:01 | | 14 | TABLE ACCESS FULL | T3 | 3 | 114 | 4 (0)| 00:00:01 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("T3"."T3_T2_FK"(+)=NVL("T2A"."T2_PK","T2B"."T2_PK")) 3 - access("T2B"."T2_T1_FK"(+)="T1"."T1_PK") 4 - access("T2A"."T2_T1_FK"(+)="T1"."T1_PK") 7 - access("T4"."T4_T2_FK"="T2"."T2_PK") 8 - filter(TO_NUMBER("T4"."T4_DISC")=0) 11 - access("T4"."T4_T2_FK"="T2"."T2_PK") 12 - filter(TO_NUMBER("T4"."T4_DISC")=1) Note ----- - dynamic sampling used for this statement (level=4) Statistics ---------------------------------------------------------- 36 recursive calls 0 db block gets 111 consistent gets 0 physical reads 0 redo size 1000 bytes sent via SQL*Net to client 334 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 3 rows processed SQL> ALTER TABLE "T1" MODIFY ("T1_PK" NOT NULL ENABLE); Table altered. SQL> ALTER TABLE "T2" MODIFY ("T2_PK" NOT NULL ENABLE); Table altered. SQL> ALTER TABLE "T3" MODIFY ("T3_PK" NOT NULL ENABLE); Table altered. SQL> ALTER TABLE "T4" MODIFY ("T4_PK" NOT NULL ENABLE); Table altered. SQL> select * 2 from T1 3 left join (select T2.* from T2 inner join T4 on T4.T4_T2_FK = T2.T2_PK and T4.T4_DISC = 0) T2A on T2A.T2_T1_FK = T1.T1_PK 4 left join (select T2.* from T2 inner join T4 on T4.T4_T2_FK = T2.T2_PK and T4.T4_DISC = 1) T2B on T2B.T2_T1_FK = T1.T1_PK 5 left join T3 on T3.T3_T2_FK = nvl(T2A.T2_PK, T2B.T2_PK); T1_PK T1_DATA T2_PK T2_T1_FK T2_DATA T2_PK T2_T1_FK T2_DATA T3_PK T3_T2_FK T3 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- - 1 T1_1 1 1 T2_1 1 1 T2_1 1 1 T3_1 2 T1_2 2 2 T2_2 2 2 T3_2 1 T1_1 1 1 T2_1 1 1 T2_1 3 1 T3_3 Execution Plan ---------------------------------------------------------- Plan hash value: 3187431534 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3 | 417 | 27 (12)| 00:00:01 | |* 1 | HASH JOIN OUTER | | 3 | 417 | 27 (12)| 00:00:01 | | 2 | VIEW | | 2 | 202 | 22 (10)| 00:00:01 | |* 3 | HASH JOIN OUTER | | 2 | 202 | 22 (10)| 00:00:01 | |* 4 | HASH JOIN OUTER | | 2 | 126 | 13 (8)| 00:00:01 | | 5 | TABLE ACCESS FULL | T1 | 2 | 50 | 4 (0)| 00:00:01 | | 6 | VIEW | | 1 | 38 | 9 (12)| 00:00:01 | |* 7 | HASH JOIN | | 1 | 54 | 9 (12)| 00:00:01 | |* 8 | TABLE ACCESS FULL| T4 | 1 | 16 | 4 (0)| 00:00:01 | | 9 | TABLE ACCESS FULL| T2 | 3 | 114 | 4 (0)| 00:00:01 | | 10 | VIEW | | 2 | 76 | 9 (12)| 00:00:01 | |* 11 | HASH JOIN | | 2 | 108 | 9 (12)| 00:00:01 | |* 12 | TABLE ACCESS FULL | T4 | 2 | 32 | 4 (0)| 00:00:01 | | 13 | TABLE ACCESS FULL | T2 | 3 | 114 | 4 (0)| 00:00:01 | | 14 | TABLE ACCESS FULL | T3 | 3 | 114 | 4 (0)| 00:00:01 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - access("T3"."T3_T2_FK"(+)=NVL("T2A"."T2_PK","T2B"."T2_PK")) 3 - access("T2B"."T2_T1_FK"(+)="T1"."T1_PK") 4 - access("T2A"."T2_T1_FK"(+)="T1"."T1_PK") 7 - access("T4"."T4_T2_FK"="T2"."T2_PK") 8 - filter(TO_NUMBER("T4"."T4_DISC")=0) 11 - access("T4"."T4_T2_FK"="T2"."T2_PK") 12 - filter(TO_NUMBER("T4"."T4_DISC")=1) Note ----- - dynamic sampling used for this statement (level=4) Statistics ---------------------------------------------------------- 98 recursive calls 0 db block gets 186 consistent gets 0 physical reads 0 redo size 1000 bytes sent via SQL*Net to client 334 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 20 sorts (memory) 0 sorts (disk) 3 rows processed SQL>
-
Distinguish NOT NULL constraints Check constraints
Join user_constraints to user_cons_columns for constraint_type = 'C' indicates the Check constraints, and NOT NULL constraints, but also (because those are implemented as Check constraints).
My question is how to filter constraints NOT NULL to let only the 'normal Check constraints '?
I tried WHERE SUBSTR(search_condition,-12,12) & LT; & GT; 'IS NOT NULL '.
but as search_condition is of type LONG, I can't use substring.
Has anyone already found it? Thank you!!ByronBarton wrote:
Has anyone already found it?
Well, there is no easy way. Simple, if you always create named* validation constraints. If so, online NOT NULL constraint will get name generated and forced check no:
SQL> create table test_tbl( 2 c1 number not null, 3 c2 number, 4 constraint test_tbl_chk1 5 check( 6 c2 is not null 7 ) 8 ) 9 / Table created. SQL> select constraint_name, 2 generated 3 from user_constraints 4 where table_name = 'TEST_TBL' 5 / CONSTRAINT_NAME GENERATED ------------------------------ -------------- SYS_C008666 GENERATED NAME TEST_TBL_CHK1 USER NAME SQL>
However, if the check constraint is not named we:
SQL> create table test_tbl( 2 c1 number not null, 3 c2 number, 4 check( 5 c2 is not null 6 ) 7 ) 8 / Table created. SQL> select constraint_name, 2 generated 3 from user_constraints 4 where table_name = 'TEST_TBL' 5 / CONSTRAINT_NAME GENERATED ------------------------------ -------------- SYS_C008668 GENERATED NAME SYS_C008669 GENERATED NAME SQL>
Then, the only way I know is:
SQL> column owner format a10 SQL> column table_name format a10 SQL> column column_name format a10 SQL> select u.name owner, 2 t.name table_name, 3 a.name column_name, 4 c.name constraint_name, 5 decode(k.type#,7,'NOT NULL',1,'CHECK CONSTRAINT','UNKNOWN') type 6 from sys.USER$ u, 7 sys.CON$ c, 8 sys.CDEF$ k, 9 sys.OBJ$ t, 10 sys.COL$ a, 11 sys.CCOL$ r 12 where u.name = user 13 and c.owner# = u.user# 14 and k.con# = c.con# 15 and t.obj# = k.obj# 16 and t.name = 'TEST_TBL' 17 and a.obj# = t.obj# 18 and r.col# = a.col# 19 and r.con# = k.con# 20 and r.obj# = k.obj# 21 / OWNER TABLE_NAME COLUMN_NAM CONSTRAINT_NAME TYPE ---------- ---------- ---------- ------------------------------ ---------------- SCOTT TEST_TBL C1 SYS_C008668 NOT NULL SCOTT TEST_TBL C2 SYS_C008669 CHECK CONSTRAINT SQL>
SY.
Maybe you are looking for
-
Lack of purchased content.
Hi people I bought albums in itunes, but they are now gone from my library? I don't have an iphone and im using an Android mobile phone and phone to view itunes. I wanted to transfer music from my itunes library (because I paid for them) my Samsung p
-
Increase the memory in I MBR 13 '' end 2013
My MacbookPro has a SSD 251 GB which is almost full, I have now 13 GB left. It will be fully this year if I continue to upload the Photos. My Photos are I-phone and camera and are stored in I-Cloud and 2 devices What choices do I have? More SSD? Move
-
OR PCI-6542: Creation of dynamic waveforms using the HSDIO library
Hello! I have problems to understand how to create waveforms using the HSDIO library to run on a card PCI-6542. I need to create a program that activates a channel for 12.5 microseconds, waiting for a while (i.e. 100 samples) and activates another ch
-
HP Officejet Pro 8500 has... Think new HP ink tank is empty.
Printer stopped working and asked a new magenta ink tank. I put a new reservoir of HP, but it keeps asking for a new. I'm sure that wasn't too empty... Please advise...
-
I have diferent problems with my pc not the message which sort an Every wants entered in internet explore or Skype and the I change the photo of my desk or uninstalling the programs this famous message is "THE CPP is not available please I want help