How no to select lines with NULL values
Hi,
I am not a newbie newbie in SQL but I do not understand why I cannot retrieve the lines where there are null values.
The table observatoire.fiche has 2 columns with default values set to NULL : total_heures, and total_heures_exceptionnelles. These are numeric types columns.
I want not to select lines where :
total_heures equal NULL AND total_heures_exceptionnelles = NULLI have tried this but I do get an "Invalid relational operator" error message.
select a.nom || ' ' || a.prenom d, a.agent_id r
from OBSERVATOIRE.AGENT a, observatoire.fiche b
where a.agent_id = b.agent_id
and b.total_heures NOT NULL AND total_heures_exceptionnelles NOT NULL
group by a.nom, a.prenom, a.agent_id
order by a.nomCould you help me ?
Thank you for your kind answers.
Satyaki_De wrote:
I think this is not the good way to do it. Did you check my solution? It should work the same output as your solution.Really ?
test@ORA10G>
test@ORA10G> -- (1)
test@ORA10G> with t as (
2 select 1 as x, 10 as total_heures, null as total_heures_exceptionnelles from dual union all
3 select 1, null, 20 from dual union all
4 select 1, null, null from dual union all
5 select 1, 30, 40 from dual)
6 --
7 select x, total_heures, total_heures_exceptionnelles
8 from t
9 where x = 1
10 AND NOT ( total_heures IS NULL
11 AND
12 total_heures_exceptionnelles IS NULL
13 );
X TOTAL_HEURES TOTAL_HEURES_EXCEPTIONNELLES
1 10
1 20
1 30 40
test@ORA10G>
test@ORA10G> -- (2)
test@ORA10G> with t as (
2 select 1 as x, 10 as total_heures, null as total_heures_exceptionnelles from dual union all
3 select 1, null, 20 from dual union all
4 select 1, null, null from dual union all
5 select 1, 30, 40 from dual)
6 --
7 select x, total_heures, total_heures_exceptionnelles
8 from t
9 where x = 1
10 AND total_heures IS NOT NULL
11 AND total_heures_exceptionnelles IS NOT NULL;
X TOTAL_HEURES TOTAL_HEURES_EXCEPTIONNELLES
1 30 40
test@ORA10G>
test@ORA10G>isotope
Similar Messages
-
How to select columns with null values
HI
In my table ‘A’ I have 10 columns and 30,000 records. I need all those columns whose value is null for all the records.
For example in the below table column 'suffix' is null for all the records. So I want column suffix to be selected.
Name Suffix Street
James 1100 Washington street
Richard 273 GEORGIA ST
Arnold 3018 OAKHILL AVE
MICHAEL 834 E 161ST ST
Joseph 410 PINE AVE
Thanks in advanceTrue...
But, i think here null needs to handle otherwise it will again throw some error like this ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.20
satyaki>
satyaki>
satyaki>
satyaki>SELECT owner, table_name, column_name
2 FROM all_tab_cols
3 WHERE data_type NOT IN ('BLOB', 'LONG', 'CLOB')
4 AND dbms_xmlgen.getxmltype('select count('
5 || CASE
6 WHEN data_type NOT IN
7 ('BLOB', 'LONG', 'CLOB')
8 THEN
9 column_name
10 ELSE
11 '1'
12 END
13 || ') c from '
14 || owner
15 || '.'
16 || table_name).EXTRACT (
17 '//text()'
18 ).getnumberval () = 0
19 AND table_name IN
20 (SELECT table_name
21 FROM all_tab_privs
22 WHERE privilege = 'SELECT' AND USER IN (grantor, grantee));
ERROR:
ORA-19202: Error occurred in XML processing
ORA-24347: Warning of a NULL column in an aggregate function
ORA-06512: at "SYS.DBMS_XMLGEN", line 288
ORA-06512: at line 1
no rows selected
Elapsed: 00:00:04.03
satyaki>Or,
satyaki>
satyaki>
satyaki>SELECT table_name, column_name
2 FROM user_tab_cols
3 WHERE data_type NOT IN ('BLOB', 'LONG', 'CLOB')
4 AND dbms_xmlgen.getxmltype('select count('
5 || CASE
6 WHEN data_type NOT IN ('BLOB', 'LONG', 'CLOB') THEN
7 column_name
8 ELSE
9 '1'
10 END
11 || ') c from '||table_name).EXTRACT('//text()').getnumberval() = 0;
AND dbms_xmlgen.getxmltype('select count('
ERROR at line 4:
ORA-19202: Error occurred in XML processing
ORA-24347: Warning of a NULL column in an aggregate function
ORA-06512: at "SYS.DBMS_XMLGEN", line 288
ORA-06512: at line 1
Elapsed: 00:00:02.66
satyaki>
satyaki>Do you have any idea to resolve this issue in this context?
Regards.
Satyaki De. -
Selecting rows with null values in an sql 3 table
Hi everyone I use oracle database 11g and have the following SQL statement:
SELECT Oprema.Opr_Id, Oprema.Datum_Nabavke, Oprema.Datum_Zaduzenja, Oprema.Dobavljac, Oprema.Jedinica_Mjere,
coalesce ((Oprema.Zaduzio), 0), Oprema.Vrijednost, Oprema.Kolicina_Nabavna, Oprema.Kolicina_Otpisana, Oprema.Kolicina_Trenutna, Oprema.Status, Oprema.Konto,
Oprema.KontoIsp, Oprema.Broj_Naloga, Oprema.Sifra_Objekta, Dobavljaci.Naziv AS DobNaz, coalesce(to_char(Uposlenici.Prezime), 'hm'), Objekti.Objekat_ID
FROM OPREMA Oprema, UPOSLENICI Uposlenici, DOBAVLJACI Dobavljaci, OBJEKTI Objekti
WHERE Oprema.Dobavljac=Dobavljaci.Dob_Id AND Oprema.Zaduzio=Uposlenici.UposlenikId AND Oprema.Sifra_Objekta=Objekti.Objekat_IDWhat I need is to show all the rows in the database. The problem is that some of the foreign keys Zaduzio and Objekti are NULL. This means the databse won't show those and only shows me rows where both have values. In all of these rows except for 3 only one of the two foreign keys has a value.
So what I need is an sql that would show me all 3. As you can see I tried with Coallesce but it didn't work, still only 3 rows show.
I also tried with UNION
SELECT Oprema.Opr_Id, Oprema.Datum_Nabavke, Oprema.Datum_Zaduzenja, Oprema.Dobavljac, Oprema.Jedinica_Mjere,
Oprema.Zaduzio, Oprema.Vrijednost, Oprema.Kolicina_Nabavna, Oprema.Kolicina_Otpisana, Oprema.Kolicina_Trenutna, Oprema.Status, Oprema.Konto,
Oprema.KontoIsp, Oprema.Broj_Naloga, Oprema.Sifra_Objekta, Dobavljaci.Naziv AS DobNaz, Uposlenici.Prezime, Objekti.Objekat_ID
FROM OPREMA Oprema, UPOSLENICI Uposlenici, DOBAVLJACI Dobavljaci, OBJEKTI Objekti
WHERE Oprema.Dobavljac=Dobavljaci.Dob_Id AND Oprema.Zaduzio=Uposlenici.UposlenikId AND Oprema.Sifra_Objekta=Objekti.Objekat_IDBut then the rows that have both Zaduzio and Objekti values are multiplied and selected twice.
So any ideas on how to do this?Hi,
If those foreign keys are NULL, then an inner join won't produce any results. Maybe you need to make it an outer-join, like this:
SELECT Oprema.Opr_Id
, Oprema.Datum_Nabavke
, Oprema.Datum_Zaduzenja
, Oprema.Dobavljac
, Oprema.Jedinica_Mjere
, COALESCE ( Oprema.Zaduzio
, 0
) AS zaduzio_or_0
, Oprema.Vrijednost
, Oprema.Kolicina_Nabavna
, Oprema.Kolicina_Otpisana
, Oprema.Kolicina_Trenutna
, Oprema.Status
, Oprema.Konto,
Oprema.KontoIsp
, Oprema.Broj_Naloga
, Oprema.Sifra_Objekta
, Dobavljaci.Naziv AS DobNaz
, COALESCE ( TO_CHAR (Uposlenici.Prezime)
, 'hm'
) AS prezime_or_hm
, Objekti.Objekat_ID
FROM OPREMA
JOIN DOBAVLJACI ON Oprema.Dobavljac = Dobavljaci.Dob_Id
LEFT OUTER JOIN UPOSLENICI ON Oprema.Zaduzio = Uposlenici.UposlenikId
LEFT OUTER JOIN OBJEKTI ON Oprema.Sifra_Objekta = Objekti.Objekat_ID
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Simplify the problem. For example, if you really need to display 18 columns, but 15 of them have nothing to do with the problem, then post a question that just includes e or 4 of those columns.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
How to create a dimension object in SAP BW Unv with Null value
Hello,
for query syncronisation task, I need a dimension object in my BW universe with NULL value. Does someone know, how to do it or if its possible?
Regards,
ThiloHi Thilo,
so the only common item is Material then - correct ?
Query 1 Query 2
Formulation (grouping of materials) (No counterpart)
Material Material
dummy key figure (why?) Company Code
10 Keyfigure
Is this something you regular have to do ? what about a MultiProvider ?
did you try "merged dimensions" in the Web Intelligence Report ?
Ingo -
To overcome column with null value-urgent
hai all,
when i query i get column with null value.
how to solve it?
thank in advance.
rcs
SQL> DESC SCOTT.CB1;
Name Null? Type
ID NUMBER
SUPCODE NUMBER
SUPLNAME VARCHAR2(100)
NAME VARCHAR2(100)
ITEMCODE VARCHAR2(10)
RECDOC NUMBER
RECDATE VARCHAR2(10)
TOTVALUE NUMBER
QTY NUMBER
CB_IPNO NUMBER
CB_VNNO NUMBER
CB_VDT VARCHAR2(10)
CB_AMT NUMBER
RECDOC_GR VARCHAR2(30)
RECDATE_GR DATE
SUPCODE_GR VARCHAR2(10)
TABLE LOOK LIKE THIS (NOT ALL DATA IN SAME ROW, BECUSE I INSERTED LAST 3 COLUMN VALUES):
ID SUPCODE SUPLNAME NAME ITEMCODE RECDOC RECDATE TOTVALUE QTY CB_IPNO CB_VNNO CB_VDT CB_AMT RECDOC_GR RECDATE_GR SUPCODE_GR
2015 AAAA 04117 9083 10545.6 78
2016 BBBB 04609 9087 25200 3600
2017 GGGG 04609 9088 28175 4025
2018 36591371.64 2565017.27
00001/07-08 02/04/2007 14020362
00002/07-08 02/04/2007 14020362
00003/07-08 02/04/2007 14010254
00004/07-08 02/04/2007 14010254
00005/07-08 02/04/2007 14021458
SQL> SELECT DISTINCT ID, SUPCODE_GR, NAME, ITEMCODE, RECDOC, RECDATE_GR, TOTVALUE, QTY FROM SCOTT.CB
1;
ID SUPCODE_GR
NAME
ITEMCODE RECDOC RECDATE_G TOTVALUE QTY
1
PRO.AT.ALU.POWDER UNCOATED
04609 15 51975 7425
2
PEN, GEL PEN
07969 17 154 11
ID SUPCODE_GR
I NEED RESULT AS FOLLOWS (ALL RESPECTIVE DDATA IN ONE LINE NOW NOT LIKE THAT):
ID SUPCODE SUPLNAME NAME ITEMCODE RECDOC RECDATE TOTVALUE QTY CB_IPNO CB_VNNO CB_VDT CB_AMT RECDOC_GR RECDATE_GR SUPCODE_GR
2015 AAAA 04117 9083 10545.6 78 00001/07-08 02/04/2007 14020362
============Even accounting for the formatting, I'm not sure I even understand the question. It could be any number of different problems or non-problems.
-
JDBC MS Access--- cannot extract entry with null value with data type Meta
I'm trying to extract a data entry with null value by using JDBC. The database is MS Access.
The question is how to extract null entry with data type memo? The following code works when the label has data type Text, but it throws sqlException when the data type is memo.
Any advice will be appreciated! thanks!
Following are the table description and JDBC code:
test table has the following attributes:
Field name Data Type
name Text
label Memo
table contents:
name label
me null
you gates
Code:
String query = "SELECT name, label FROM test where name like 'me' ";
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
String name = rs.getString("name");
rs.getString("val");
String label = rs.getString("label");
System.out.println("\t"+name+"\t"+label);
catch (SQLException ex)
System.out.println(ex.getSQLState());
System.out.println(ex.getErrorCode());
System.out.println("in sqlexception");
output:
C:\Temp\SEFormExtractor>java DBTest
yet SELECT name, label FROM test
null
0
in sqlexceptionThe question is how to extract null entry with data type memo?Okay, what you need to do is this:
if (rs.getString("val") == null)
// do something
}This way, when it's a null value, you can check it first, and then handle it how you want, rather than getting an exception. -
how to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method. thanks
INSERT targetdb.dbo.tbl (col1, col2, col3, ...)
SELECT col1, col2, col3, ...
FROM sourcedb.dbo.tbl
Or what is your question really about? Since you talke about foreign keys etc, I suspect that you want to transfer the entire table definition, but you cannot do that with an INSERT statement.
Erland Sommarskog, SQL Server MVP, [email protected] -
Need help with NULL values in Crosstables
Hello everybody,
I need some help with NULL values and crosstables. My issue is the following:
I have a query (BW - MDX-Query) that gives me turnover measures for each month. In Crystal Reports I choose crosstable to display this whereby I put all month in columns and all turnover-measures in rows. Each month that has a value (measures are not empty) is chown in the crosstables rows. So far so good. The problem occures when there are month that actually have no values (measures are empty). In that case these months are not chown in columns. But I need CR to display these columns and show the value 0. How can I do that?Hi Frank,
Cross tab shows the data based on your column and these column fields are grouped and based on the group it will show your summaries.
If there is no data for any of your group it will not display that group. In this case you will have to create a standard report which should look like cross tab and to get zero values you need to write formulas .
Example if you want to display Moth wise sales :
if Month() = 01 Then
sum() else 0
Now this formula will check if your month is Jan, then it will sum up the values else it will display zero value.
This is possible only through standard report not with Cross Tab.
Thanks,
Sastry -
Sql query slowness due to rank and columns with null values:
Sql query slowness due to rank and columns with null values:
I have the following table in database with around 10 millions records:
Declaration:
create table PropertyOwners (
[Key] int not null primary key,
PropertyKey int not null,
BoughtDate DateTime,
OwnerKey int null,
GroupKey int null
go
[Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
With the following index:
CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]
[PropertyKey] ASC,
[BoughtDate] DESC,
[OwnerKey] DESC,
[GroupKey] DESC
go
Description of the case:
For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
declare @ownerKey int = 40000
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from (
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
) as result
where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
May be the slowness is due to as OwnerKey/GroupKey in the table can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
view.
Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
go
declare @ownerKey int = 1
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from #result as result
where result.[Rank]=1
and result.[OwnerKey]=@ownerKey
go
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Range interval partitioning with null value
Hello,
I have question, how can I create table with partition and after that I will insert null value in the partition key like this kind of
range interval partitioning with null value.
I have Oracle 11g.
Thanks
Mohammeduser13777053 wrote:
Thank you, but my question is about range interval not for range?http://docs.oracle.com/cd/E11882_01/server.112/e25523/partition.htm#VLDBG00220
A MAXVALUE literal can be defined for the highest partition. MAXVALUE represents a virtual infinite value that sorts higher than any other possible value for the partitioning key, *including the NULL value.*
So since you're trying to partition by interval (which doesn't support a MAXVALUE clause) you're out of luck.
There's probably fancy hacks and what not you could try to implement, but i'm not about to recommend any of those here :)
Cheers, -
How to dynamic select based on runtime value ?
how to dynamic select based on runtime value ?
I want to write a select function, which do selecting based on parameters. eg,
CREATE OR REPLACE FUNCTION myfunction
(tableName VARCHAR2, pkName VARCHAR2, pkValue VARCHAR2, requestString VARCHAR2)
RETURN VARCHAR2 AS
BEGIN
select requestString from tableName where pkName=pkValue;
RETURN NULL;
END;
myfunction('users', 'user_id', '100', 'user_name'); it will select 'user_name' from table 'users' where 'user_id' = '100'.
This way could save lots of coding. but it can't pass compiler. how to work out ?
Thanks.While this may save code, if used frequently it will be ineffecient as all [explicative deleted]. The danger is that it would be used even for repeatable statements.
This mode of operation ensures that every statement [calling the funciton] needs to be reparsed, which is extremely expensive in Oracle (in CPU cycles, recursive SQL and shared pool memory).
Such reparsing is rarely a good thing for the environment ... it could easily lead to buying more CPU (bigger box) and therefore adding more Oracle license ... which could quickly exceed the typical developer's salary.
However - if you really, really want to do this, look up 'execute immendiate' in the PL/SQL manuals. -
Pro*C & SQLDA with NULL value for predicate column
Hi: I am using a C program to update a table via a dynamic sql (method 4) and SQLDA. In the update statement predicate, I have place holders (as in TBLCOL=:C000). One of the columns in the predicate contains null values, so I set L[n] = 0, V[n] = pData (which pData[0] = '\0'), *(I[n]) = -1, and T[n] = 5 (for text). I cannot find the row that I know is there.
I cannot change my statement to contain TBLCOL IS NULL, since I don't know ahead of time if I'm looking for rows with null values for this column. The Pro*C manual says that by setting the appropriate *(I[n]) = -1, it indicates to Oracle to simulate the "IS NULL" clause, and update the appropriate rows. In my case, I receive 1403 as SQLCODE when I use TBLCOL=:C000 vs TBLCOL IS NULL. What am I doing wrong? Thank you for your help.You should include these columns as well;
ChangeType (see mxi_changetype)
ValOwner (repository)
UserID ("jobid=<>", usermskey, GUI (mmc), DG (dyngrp), reconcile)
IdAudit (This is the event task (add and del member for assignments)
ParentAuditId (AuditID of parent which last updated the attribute, not consistent)
ChangedBy (Holds the MSKEY of the user which last changed the attribute)
ExpiryTime
to make sure you get a fuller picture of the audit record.
Your selection does not cover all events and descriptions
br,
Chris -
How to create a matrix with constant values and multiply it with the output of adc
How to create a matrix with constant values and multiply it with the output of adc
nitinkajay wrote:
How to create a matrix with constant values and multiply it with the output of adc
Place array constant on diagram, drag a double to it, r-click "add dimension". There, a constant 2D double array, a matrix.
/Y
LabVIEW 8.2 - 2014
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
G# - Free award winning reference based OOP for LV -
JDBC Receiver Adapter with Null Value
HI,
I have configured ID for JDBC Receiver. In my communication channel, I already check Integration of Empty String Values = Null Value. However, when I check the result from audit log, it still shows that SAP XI sends the null value to database. In my understanding, it should not send the field which has null value (It shouldn't be included in sql statement).
I check this with other scenario. With the same check at Integration of Empty String Values = Null Value, it doesn't send null value to database. It happens only with my first scenario.
Have anyone ever been through this before? Any suggestion please?
Thanks,
PavinHi,
1. The occurrence is 0...1
2. This is the first result with null value (Please see field Error)
UPDATE EXPCRM_T_CustomerProfile SET RequestID=455, RecordNo=1, SAPCustomerCode=0001000344, Error=NULL, Status=2, UpdateDateTime=12/03/2008 13:45:03 WHERE (RequestID=455 AND RecordNo=1)
Then, I change the option from Null Value to Empty string. This is the result.
UPDATE EXPCRM_T_CustomerProfile SET RequestID=455, RecordNo=1, SAPCustomerCode=0001000344, Error=', Status=2, UpdateDateTime=12/03/2008 13:46:12 WHERE (RequestID=455 AND RecordNo=1)
Field Error Change from NULL to '
The expected result from me is that field Error should not exist at all. Please help.
Thanks,
Pavin -
bc4juix:StyledText doesn't work with null values?
Hi , anyone knows why the <bc4juix:StyledText> tag doesn't work with null values?
For example when datasource does not give back data...
Thanks
GuillermoWhich version of Jdev are you using? What are the results you are getting?
Maybe you are looking for
-
Archiving problem for Windows OS...
Hi all, I was trying to archive the messages. I followed the below document settings and created the archiving not able to archive the messages. https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/402fae48-0601-0010-3088-85c46a236f50
-
Microsoft Word 2012 scam app on store
I just noticed a "Microsoft Word 2012" app on the app store while browsing AppShopper. I checked it on the store and it is obviously a scam. How did this app even make it to the store? I don't see how an app advertised as "All features of the MAC ver
-
ORACLE Client Installation(ODBC Driver) 8.1.6
I've been having some difficulty installing Oracle 8.1.6 client on Windows NT4 SP5 machines. The installations would go successful all the way 100% then exits!!! All the appropriate files are copied to their directories and I am able to launch Net8As
-
Issue When Creating a Database View
Hi I am trying two join two tables using a database view through SE11 and this tables are related to SAP HR. As per the requirement we need to create a table join using SQVI in which we are facing a issue where the transaction is freez
-
I have a book I have written in Pages. It has lots of photos. When I make a pdf, it's about 380 Megs and is larger still in the pages format--nearly 500 megs. The publishing company online has a maximum size limit of 400 megs for the pdf file. The bo