A query to extract only the non-null columns.
Hello
I have a table with:
COLA, COLB TEACHERS COLD COLE
AA BB < null > < null > JJ
< Null > < null > CC < null > EE
I need a query that retrieves only 1 rows like this:
COLA, COLB TEACHERS COLD COLE
AA BB CC DD EE
My version of the database is 11.2
Thnak you
odd design but in this case, you could go with MAX (or MIN)
HTH
Tags: Database
Similar Questions
-
with regard to the non-null columns
Hi all
I use 10g db.
I have a query as below
for the date of the range I have 5 files among them 4 records has value for the SH_NUMBER column and a block is null.SELECT SH_CODE,SH_NAME,SH_NUMBER FROM SHIPPING_DETAILS WHERE SH_COMP = :GLOBAL.COMPANY AND TRUNC(SH_DATE) BETWEEN '01-JAN-2009' AND '02-JAN-2009' AND SH_NUMBER = NVL(l_num,SH_NUMBER)
but I don't get any record for which SH_NUMBER is set to null.
why there is not this number?
How this code above will be the judge?AND SH_NUMBER = NVL(l_num,SH_NUMBER)
Please suggest me.
Thank you...Try this:
AND NVL(SH_NUMBER, -999) = NVL(l_num, NVL(SH_NUMBER, -999))
or:
AND (l_num IS NULL OR (l_num IS NOT NULL AND SH_NUMBER = l_num))
-
Do we not have an oracle function to select the non-null columns at the beginning
Hello
I have 8 columns. Some of them may be null.
I want to display all 8 columns in my result. Columns not null will be first and no one at the end.
Here is an example of data:
Employee table:
The expected result is:Employee_id Emp_fname emp_lname emp_mname dept salary emp_height emp_weight 1 aaa ddd d1 100 6 180 2 bbb ccc 120 169 3 dfe d2 5.9 223
Thank you.result1 result2 result3 result4 result5 result6 result7 result8 1 aaa ddd d1 100 6 180 2 bbb ccc 120 169 3 dfe d2 5.9 223
Published by: BluShadow on July 12, 2012 16:12
addition of {noformat}{noformat} tags for readability. Please read {message:id=9360002} and do this yourself in future.
945559 wrote:
I'm using Oracle Database 11 g Release 11.2.0.3.0.Here is my sample data.
CREATE TABLE saleshist (product VARCHAR2 (30), q1 NUMBER NUMBER of q2, q3 NUMBER, NUMBER of T4);
INSERT INTO saleshist VALUES ('EE Oracle', 100, 123, null, 128);
INSERT INTO saleshist VALUES (null, 'Partitioning', 100, 130, 128);desired output:
col1, col2, col3 col4
'Oracle EE', 100, 123, 128, null
"Partitioning", 100,130,128, nullIt seems that you have 4 column headers, but 5 columns.
Assuming that the character ' ~' never occurs in one of the columns:
WITH got_list AS ( SELECT '~' || product || '~' || TO_CHAR (q1) || '~' || TO_CHAR (q2) || '~' || TO_CHAR (q3) || '~' || TO_CHAR (q4) AS list FROM saleshist ) SELECT REGEXP_SUBSTR (list, '[^~]+', 1, 1) AS col1 , REGEXP_SUBSTR (list, '[^~]+', 1, 2) AS col2 , REGEXP_SUBSTR (list, '[^~]+', 1, 3) AS col3 , REGEXP_SUBSTR (list, '[^~]+', 1, 4) AS col4 , REGEXP_SUBSTR (list, '[^~]+', 1, 5) AS col5 FROM got_list ;
Output:
COL1 COL2 COL3 COL4 COL5 --------------- ---------- ---------- ---------- ---------- Oracle EE 100 123 128 Partitioning 100 130 128
If you need a multiple character string, such as '? ~', to delimit the columns, then the same basic approach works, but the regular expression is messier.
Product is just another column in this solution. Can be NULL, and it doesn't have to be unique.
-
How to write a hierarchical query so that only the child nodes are displayed?
Hi all
I have a hierarchical query that I use in an area of tree demand APEX and there are nodes that have no children and I am trying to find a way to not display these nodes. Essentially if the user does not have to develop a lot of knots to know that nothing exists at the most detailed level.
The data are based on the Oracle Fusion FND tables but for example purposes here is enough data to illustrate my question:
create table APPL_TAXONOMY_HIERARCHY (SOURCE_MODULE_ID varchar2(30), TARGET_MODULE_ID varchar2(30)); create table APPL_TAXONOMY_TL (module_id varchar2(30), description varchar2(100), user_module_name varchar2(30), language varchar2(5)); create table APPL_TAXONOMY (MODULE_ID varchar2(30), MODULE_NAME varchar2(30), MODULE_TYPE varchar2(10), MODULE_KEY varchar2(30)); create table TABLES (table_name varchar2(30), module_key varchar2(30));
insert into APPL_TAXONOMY_TL values ('1', null, 'Oracle Fusion', 'US' ); insert into APPL_TAXONOMY_TL values ('2', null, 'Financials', 'US' ); insert into APPL_TAXONOMY_TL values ('3', null, 'Human Resources', 'US' ); insert into APPL_TAXONOMY_TL values ('20', null, 'Accounts Payable', 'US' ); insert into APPL_TAXONOMY_TL values ('10', null, 'General Ledger', 'US' ); insert into APPL_TAXONOMY_HIERARCHY values ('1', 'DDDDDDDD'); insert into APPL_TAXONOMY_HIERARCHY values ('2', '1'); insert into APPL_TAXONOMY_HIERARCHY values ('3', '1'); insert into APPL_TAXONOMY_HIERARCHY values ('4', '1'); insert into APPL_TAXONOMY_HIERARCHY values ('10', '2'); insert into APPL_TAXONOMY_HIERARCHY values ('20', '2'); insert into APPL_TAXONOMY values ('1', 'Fusion', 'PROD', 'Fusion'); insert into APPL_TAXONOMY values ('2', 'Financials', 'FAMILY', 'FIN'); insert into APPL_TAXONOMY values ('10', 'GL', 'APP', 'GL'); insert into APPL_TAXONOMY values ('3', 'Human Resources', 'FAMILY', 'HR'); insert into APPL_TAXONOMY values ('20', 'AP', 'APP', 'AP'); insert into tables values ('GL_JE_SOURCES_TL','GL'); insert into tables values ('GL_JE_CATEGORIES','GL');
My hierarchical query is as follows:
with MODULES as ( SELECT h.source_module_id, b.user_module_name, h.target_module_id FROM APPL_TAXONOMY_HIERARCHY H, APPL_TAXONOMY_TL B, APPL_TAXONOMY VL where H.source_module_id = b.module_id and b.module_id = vl.module_id and vl.module_type not in ('PAGE', 'LBA') UNION ALL select distinct table_name, table_name, regexp_substr(table_name,'[^_]+',1,1) from TABLES --needed as a link between TABLES and APPL_TAXONOMY union all select module_key as source_module_id, module_name as user_module_name, module_id as target_module_id from appl_taxonomy VL where VL.module_type = 'APP') SELECT case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status, LEVEL, user_module_name as title, null as icon, ltrim(user_module_name, ' ') as value, null as tooltip, null as link FROM MODULES START WITH source_module_id = '1' CONNECT BY PRIOR source_module_id = target_module_id ORDER SIBLINGS BY user_module_name;
In Oracle APEX, this gives a tree with the appropriate data, you can see here:
https://Apex.Oracle.com/pls/Apex/f?p=32581:29 (username: guest, pw: app_1000);
The SQL of the query results are:
STATUS TITLE LEVEL VALUE ---------- ---------- ------------------------------ ------------------------------
1 1 oracle Fusion Oracle Fusion -1 2 financial tables Financials -1 3 accounts payable Accounts payable 0 4 AP AP -1 General Accounting 3 General Accounting -1 4 GL GL 0 5 GL_JE_CATEGORIES GL_JE_CATEGORIES 0 5 GL_JE_SOURCES_TL GL_JE_SOURCES_TL 0 2 human resources Human resources The lowest level is the name of the table to level 5. HR is not any level under level 2, in the same way, "AP" (level 4) has nothing below, i.e. no level 5 and that's why I don't want to show these nodes. Is this possible with the above query?
Thanks in advance for your suggestions!
John
Hello
The following query will include only the nodes of level = 5 and their ancestors (or descendants):
WITH modules LIKE
(
SELECT h.source_module_id
b.user_module_name AS the title
h.target_module_id
To appl_taxonomy_hierarchy:
appl_taxonomy_tl b
appl_taxonomy vl
WHERE h.source_module_id = b.module_id
AND b.module_id = vl.module_id
AND vl.module_type NOT IN ('PAGE', "LBA")
UNION ALL
SELECT DISTINCT
table-name
table_name
, REGEXP_SUBSTR (table_name, ' [^ _] +')
From the tables - required as a link between the TABLES and APPL_TAXONOMY
UNION ALL
SELECT module_key AS source_module_id
AS user_module_name module_name
module_id AS target_module_id
Of appl_taxonomy vl
WHERE vl.module_type = 'APP '.
)
connect_by_results AS
(
SELECT THE CHECK BOX
WHEN CONNECT_BY_ISLEAF = 1 THEN 0
WHEN LEVEL = 1 THEN 1
OF ANOTHER-1
The END as status
LEVEL AS lvl
title
-, NULL AS icon
, LTRIM (title, "") AS the value
-, NULL as ToolTip
-, Link AS NULL
source_module_id
SYS_CONNECT_BY_PATH (source_module_id - or something unique
, ' ~' - or anything else that may occur in the unique key
) || ' ~' AS the path
ROWNUM AS sort_key
Modules
START WITH source_module_id = '1'
CONNECT BY PRIOR Source_module_id = target_module_id
Brothers and SŒURS of ORDER BY title
)
SELECT the status, lvl, title, value
-, icon, tooltip, link
OF connect_by_results m
WHEN THERE IS)
SELECT 1
OF connect_by_results
WHERE the lvl = 5
AND the path AS ' % ~' | m.source_module_id
|| '~%'
)
ORDER BY sort_key
;
You may notice that subqueries modules and the connect_by_results are essentially what you've posted originally. What was the main request is now called connect_by_results, and it has a couple of additional columns that are necessary in the new main request or the EXISTS subquery.
However, I am suspicious of the 'magic number' 5. Could you have a situation where the sheets you are interested in can be a different levels (for example, some level = 5 and then some, into another branch of the tree, at the LEVEL = 6, or 7 or 4)? If so, post an example. You have need of a Query of Yo-Yo, where you do a bottom-up CONNECT BY query to get the universe of interest, and then make a descendant CONNECT BY query on this set of results.
-
Need help to write a MySQL query that returns only the peer matching records
Because I don't know how to explain it easily, I use the table below as an example.
I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.
Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.
How can I create a query that will do it?
ID | col1 | col2
--------------------
1. ABC | DEF
2. DEF | ABC
3. ABC | IGS
4. DEF | IGS
5. IGS | DEF
* Please let me know if you have no idea of what I'm trying to explain.I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.
SELECT a.col1,
a.col2
FROM table_name AS a
LEFT OUTER
Table_name JOIN b
ON b.col1 = a.col2
AND a.col1 = b.col2
WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '. -
validation working is not to count the non-null fields
I have six fields on the screen, I want to check that at least 3 of them are filled (3)...
I created a validation as follows to count the non-null fields... but it's not working...
Please help solve this problem or recommend a better way to do this...
declare
number of question_count;
Start
question_count: = 0;
If: p1_t_question_1 is null then
null;
on the other
question_count: =: question_count + 1;
end if;
If: p1_t_question_2 is null then
null;
on the other
question_count: =: question_count + 1;
end if;
If: p1_t_question_3 is null then
null;
on the other
question_count: =: question_count + 1;
end if;
If: p1_t_question_4 is null then
null;
on the other
question_count: =: question_count + 1;
end if;
If: p1_t_question_6 is null then
null;
on the other
question_count: =: question_count + 1;
end if;
If: p1_t_question_6 is null then
null;
on the other
question_count: =: question_count + 1;
end if;
If: question_count > 2 then return false;
otherwise returns true;
end if;
end;I'll take a look a bit.
In the meantime, check if the code asIf the trim (both '%' from: p1_question_with_nul') = 'null '.
help
Ok. Take a look now. I used the function TRIM as shown above and also changed the comparison for questions 3 text based on ' if: p1_question_with_text is null'
Seems to work now
CITY
Published by: city has 23 October 2009 05:26
-
How to set a non-Null column in CF9 ORM?
How to set a non-Null column in CF9 ORM? Thank you.
Just to recycle my answer to your other question:
You should find what you need in the docs here: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSB7BEC0B4-8096-498d-8F9B- 77C88878AC6C.html
Scroll up to where it describes the properties of the DOF.
--
Adam
-
Refine a query to display only the entries for the current week
Hello.
Anyone know how to change a query to display only those records that have dates of the current week? Records have a start date and an end date, so the query should recognize that the entry may be valid for more than one week?
Kind regards
swelchHi Steve,.
I just created a dataset that contained the periods before, during and after the current week - on the assumption that if any day of a range (start/end) falls within the current week so it is included.
In my example this is 'today', June 25, 2011, and a week is defined as Sun - Sat. So my week of 'course' is u 19 June 2011 / I June 25, 2011.
A line any with a start date before or during my 'current' week and an end date that is after or during my "current" week, i.e. no matter what date in its range included in the 'in progress' week will appear.
See you soon,.
Rob -
the non-null values insert select
Please could you help me on this:
INSERT INTO new_table (ID, hobby, country, internal_id, cat)
SELECT ID, hobby, country internal_id,
Max (CASE cat WHEN = 'ben' THEN 1
WHAT cat = 'ale' THEN 2
WHAT cat = 'inf' THEN 3
WHAT cat = "cad" THEN 4
WHAT cat = 'juv' THEN 5
WHAT cat = 'sen' THEN 6
WHAT cat = 'teacher' THEN 7
END)
Ancienne_table GROUP BY ID, hobby, country, internal_id;
the lines on ancienne_table have duplicates regs as follows:
ID Country Hobby Internal_ID CAT 1 Oman Rugby Union 63180 Juv 1 Oman Rugby Union 63180 Teacher 1 Oman Rugby Union 63180 Juv the request requires the output as follows:
ID Country Hobby Internal_ID CAT 1 Oman Rugby Union 63180 7 because cat = 'juv' (5) is less cat =' teacher (7).
all columns are not null and the primary key of the new_table is ID + hobby
The script displays the following output:
01400 00000 - 'impossible to insert NULL into (%s)' because does not recognize the function max.
Thanks in advance.
Kind regards.
Actually there are values not in the range of cat. There is an error in the old data table.
I proceeded to remove the lines out of reach in the cat because column that are not relevant in this case.
The parameters I use Oracle are:
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production."
AMT for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
Thank you very much. You are so helpful.
Kind regards.
-
Query that count only the column null lines
create table test
(a varchar2 (10))
b varchar2 (10),
c varchar2 (10),
d varchar2 (10),
e varchar2 (10));
SQL > DESC TEST
Name Null? Type
------------------------------- -------- ----
A VARCHAR2 (10)
B VARCHAR2 (10)
C VARCHAR2 (10)
D VARCHAR2 (10)
E VARCHAR2 (10)
SQL > SELECT * FROM TEST;
A B C D E
---------- ---------- ---------- ---------- ----------
A1 - A3 A4-
B1 - B3, B4-
C1 - C3 C4-
D1 - D4 D5
-E2 - E4 E5
I want an application that only count the rows of the column as null
A B C D E
--- ---- ----- ------ -------
1 4 2 0 3
Published by: Nilesh hole, Pune, India, on August 28, 2009 12:30select SUM(case when a is null then 1 else 0 end) ,SUM(case when b is null then 1 else 0 end) ,SUM(case when c is null then 1 else 0 end) ,SUM(case when d is null then 1 else 0 end) ,SUM(case when e is null then 1 else 0 end) from TEST /
Published by: Toon Koppelaars August 28, 2009 09:07
-
Extract only the digit that starts the chain of txt
Hello LabVIEW community. IM starting programming in LabVIEW and I stuck with one problem.
IM creating weather station that send a txt file measurments.
I just want open created by terminal .txt or .log file, draw different graphs of txt.
journal and vi as an attachment file.
Can I change the display size in the logfile (change separator), but always it will be mixed in a single file.
Anyone know how to extract file only for example. all dimensions of moisture?
I created vi that open and draw but still a problem of mesurment choose who I want.
Sorry for my bad English
If you want to use read the spreadsheet file, you write the data to a format that it can understand. This usually means a tab-delimited text files.
I recommend that you show us your code, locate the file where you write. We can make life a lot easier on you by fixing that.
In general what you want here is a line with headers (to indicate what are the names of channel), then data. Each column of data belongs to a specific channel. Each column is separated by a tab CHARACTER. A new line in the file for each new data point for all channels. If your newspaper should really resemble the home.
So now, just remove the header information, and then string array spreadsheet to activate all the data in a 2D double table. You can use then just Board Index to get the channel data that you care.
-
Where can I get directions to EXTRACT only the audio of a DVD with Windows Media Player v11
Have investigated this question on the NET and seen various solutions (freeware), but I have just started using WMP to migrate my CD music in MP3 format.
I have some great DVD rip also I want. Any direction is appreciated!
Hi PEL7176,
Windows media player only supports the extraction of CD and DVD not.
You may need to use a third-party software to perform this procedure.
NOTE: Microsoft cannot guarantee that problems resulting from the use of third-party software can be resolved. Software using third party is at your own risk.
With regard to:
Samhrutha G S - Microsoft technical support.
Visit our Microsoft answers feedback Forum and let us know what you think.
-
Need to get the latest news for a group-max (value) of the non-null values
Hello
Here is my table and data
SQL > desc method
NUMBER OF SEQ_ID
EMP_ID NUMBER
ISSUE GUID
FIRST NAME VARCHAR2 (30)
LAST_NAME VARCHAR2 (30)
E-MAIL VARCHAR2 (45)
PHONENO VARCHAR2 (30)
SQL > Select * method;
SEQ_ID EMP_ID GUID FIRST_NAME LAST_NAME EMAIL PHONENO
------ - ----- ---- --------- --------------------------------------------------- ----------------------------------------- ------------------------------
1 100 20 RAJA HHH 686678
2 100 20 [email protected]
3 100 20 RAJA 134555
4 100 20 HAPPY [email protected]
5 200 20 RAM
6 200 20 JJJ 2345667
7 200 20 RM GGG [email protected] 1234557
8 200 20 [email protected] RRR
8 selected lines
I want the latest news on the employee, the group id comibnation for the rest of the columns.
So I want to get the following result.
100 20 RAVI HHH [email protected] 134555
200 20 RRR GGG [email protected] 1234557
If you note here for the family name, we take the previous value non-zero value Eg HHH column and is the same for all columns.
It's the value of line max (seqid) for empid, combination of guid and if the column values are null, we must get the previous maximum value non-zero.
The seqid is also there that the sequence.
Please help me to get the result set.
Thanks in advance.
mjhraja.SQL> select emp_id, guid, max(first_name) first_name, max(last_name) last_name 2 , max(email) email, max(phoneno) phoneno 3 from ( 4 select emp_id, guid 5 , first_value (first_name ignore nulls) 6 over (partition by emp_id, guid order by seq_id desc) first_name 7 , first_value (last_name ignore nulls) 8 over (partition by emp_id, guid order by seq_id desc) last_name 9 , first_value (email ignore nulls) 10 over (partition by emp_id, guid order by seq_id desc) email 11 , first_value (phoneno ignore nulls) 12 over (partition by emp_id, guid order by seq_id desc) phoneno 13 from emp_info 14 ) 15 group by emp_id, guid 16 / EMP_ID GUID FIRST_NAME LAST_NAME EMAIL PHONENO ---------- ---- ---------- ---------- -------------------- ---------- 100 20 RAVI HHH [email protected] 134555 200 20 RRR GGG [email protected] 1234557 SQL>
-
Substring to extract only the charahters in the same position
You are looking for a function to regex replace characters in odd position for null value.
example:
Input string = "1213441516871819"
string output = "23456789 '.
Oracle 11.2 version
Thank you
He needs a little more to deal with odd length strings...
SELECT REGEXP_REPLACE (' 123 ', '.) (.) |.', '\1')
DOUBLE;
Basically, that is to say "get two characters and give me the second or if you fit to 2 characters, then replace just one character and replace it with nothing.
-
Hello
RDBMS: Oracle 10.2 standard edition
Is there any setting exists in expdp to export data from only selected tables?Yes,
username/password expdp tables = table1, table2,... happy = data_only...
Dean
Maybe you are looking for
-
The piece on my iPhone that I plug the charger in is missing
The body of my iPhone that I plug my charger in is absent. Can it be replaced without replacing the entire phone?
-
How can I turn off "find my phone" when my screen is locked?
The touch screen on my phone stopped working today. When I went to Best Buy, they said that I need to backup my phone in ITunes, before they can send for a new(refurb.) phone. I also disable "find my phone". The problem is... I can't do anything
-
HP 2000: Remove password Admin / turn on password at startup
Hello I work at a pawn shop, and we have a problem, we have never met before. This portable, which is allowed and is now on sale in the shop, now ask an administrator password or power on password. He didn't get it when it was brought, nor when he
-
from the start, password cannot sign in when the satellite wireless is enabled
laptop works strangely lately, but I've not had problems with not being is not able to connect to the computer when the wireless is turned on and having to switch off to sign into the system.
-
Hello I need help with this. We have a dial out peer and it is mapped on the incoming side and calls do not come out to the carrier. Instead the tower to the PBX. PBX: 10.21.10.12 Carrier: 1.1.1.1 LAN cube: 10.21.10.250 The call: 13053284888 Called