SELECT where the column is NULL or a number
HelloI am trying to use a query that the WHERE clause contains a column that can be NULL or a number. If it contains a number, I want to select the rows that contain the numerical value for this column; Otherwise, the rows that contain NULL for this column, as shown here:
SELECT col_1,
col_2,
etc...
OF CN_BGT_ENTRIES
WHERE grnt_id = p_grnt_id
AND subbgt_nbr = (SELECT MAX (subbgt_nbr) FROM CN_BGT_ENTRIES WHERE grnt_id = p_grnt_id);
in the opposite case
AND subbgt_nbr is null;
My strategy has been to create a cursor, EXTRACT the max value in l_subbgt_max and then use a BOX of the form:
SELECT col_1,
col_2,
etc...
OF CN_BGT_ENTRIES
WHERE grnt_id = p_grnt_id
AND (CASE
WHEN l_subbgt_max IS NULL THEN ' subbgt_nbr IS NULL; "
ELSE ' subbgt_nbr = l_subbgt_max; »
(END);
I tried every syntax since I can think of (for example, CASE NVL(l_subbgt_max,0) = 0) but continues to receive:
PL/SQL: ORA-00920: invalid relational operator
ORA-06550: line 13, column 3:
PL/SQL: SQL statement ignored
I know that I can DECLARE 2 sliders and then use a conditional to run one or the other, but in the interest of the growth and written some thing a little more sophisticated, I was hoping that someone with more experience SQL could tell me how [s] he would do this.
Thanks in advance for your time.
I guess that l_subbgt_nbr is a variable?
In any case, something like this:
SELECT col_1,
col_2,
etc ...
FROM CN_BGT_ENTRIES
WHERE grnt_id = p_grnt_id
AND ( ( l_subbgt_nbr is null and subbgt_nbr is null )
OR ( l_subbgt_nbr is not null and subbgt_nbr = (SELECT MAX(subbgt_nbr)
FROM CN_BGT_ENTRIES
WHERE grnt_id = p_grnt_id)
)
);
Cheers, APC
Published by: APC on July 23, 2012 15:46
Tags: Database
Similar Questions
-
Error when selecting all the columns in the table
Hi all
When I write a query by selecting all the columns of the table fromo using * function as well as another new column, I get the error,
Select *, to_char (hiredate, 'fmday') day
WCP
where to_char (hiredate, 'fmday') ('Monday');
ERROR on line 1:
ORA-00923: THE KEYWORD not found where expected
I need all the columns in the table with the column user-defined 'day '. Is there a way I can get the result like this?
Hello
padders wrote:
Alias table to use...
Or the name of the table, for example
Select emp.*, to_char (hiredate, "fmday") as day
WCP
where to_char (hiredate, 'fmday') ('Monday');
The bottom line is that * must be qualified (with a table name or alias) when the SELECT clause includes anything else besides *.
-
Returns all duplicate rows, where the columns correspond
Dear members,
I have a table that contains duplicates, and the query should return only the rows where the columns correspond...
create master table (varchar2 (10) firstname, lastname varchar2 (10), code VARCHAR2 (3), place varchar2 (10));
insert into Master values ('bob', 'John', '1', 'atlanta');
insert into Master values ('bob', 'John', '1', 'atlanta');
insert into Master values ('bob', 'John', '1', 'atlanta');
insert into Master values ('test', 'John', '1', 'atlanta');
Insert into master values('bob','john','1','bank');
The application should we 3 rows.
Bob-john-1-atlanta
Bob-john-1-atlanta
Bob-john-1-atlanta
I tried a few changes to query such as select * from master M, mater n where m.firstname = n.firstname and...
Is there another way to do this...
Thanks in advance...select firstname, lastname, code, place from ( select m.*, count(*) over(partition by firstname,lastname,code,place) cnt from master m ) where cnt > 1 order by firstname, lastname, code, place / FIRSTNAME LASTNAME COD PLACE ---------- ---------- --- ---------- bob john 1 atlanta bob john 1 atlanta bob john 1 atlanta SQL>
SY.
-
dynamically display title based on the value selected in the column picker
Hi all
Would it be possible to display the title of the dynamic report based on the value selected in the column picker. Suppose I have two State of the column and region. When I choose the status in the column picker the title of the report will show 'Summary of the situation' when I'll choose the region then the title will change to "summary of the region. Please help me...Hello
Check your mail before I send the entire process with screenshots.
Concerning
NGO
-
Select only records where the column values are not all equal to zero
Hi everyone, it seems so easy, but it has left me speechless on the research in a way that is clean, easy to achieve. I know when someone replies, I'm going to kick me. So, let's assume this is what I have:
I need an external application around it or something which will select only 'Type 1'... that is, if all months are each equal to zero, do not include the record in the result set.with mytable as ( select 'Type 1' as itemtype, 'JAN' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'FEB' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'MAR' as monthname, 5 as theval from dual union all select 'Type 1' as itemtype, 'APR' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'MAY' as monthname, 4 as theval from dual union all select 'Type 1' as itemtype, 'JUL' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'AUG' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'SEP' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'OCT' as monthname, 7 as theval from dual union all select 'Type 1' as itemtype, 'NOV' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'DEC' as monthname, 2 as theval from dual union all select 'Type 2' as itemtype, 'JAN' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'FEB' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'MAR' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'APR' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'MAY' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'OCT' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'NOV' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'DEC' as monthname, 0 as theval from dual ) select itemtype, sum (case monthname when 'JAN' then theval else 0 end) as JAN, sum (case monthname when 'FEB' then theval else 0 end) as FEB, sum (case monthname when 'MAR' then theval else 0 end) as MAR, sum (case monthname when 'APR' then theval else 0 end) as APR, sum (case monthname when 'MAY' then theval else 0 end) as MAY, sum (case monthname when 'JUN' then theval else 0 end) as JUN, sum (case monthname when 'JUL' then theval else 0 end) as JUL, sum (case monthname when 'AUG' then theval else 0 end) as AUG, sum (case monthname when 'SEP' then theval else 0 end) as SEP, sum (case monthname when 'OCT' then theval else 0 end) as OCT, sum (case monthname when 'NOV' then theval else 0 end) as NOV, sum (case monthname when 'DEC' then theval else 0 end) as DEC from mytable group by itemtype order by itemtype
In summary to get a total of zero is not an option, because I could have-15 and + 15 in different columns, in which case, the recording should be displayed.
Something as simple as... 'not the case (oct = 0 and 0 nov and dec = 0...) at the end is all it seems to me necessary. I thought to add a case for each column clause, but that seems not very effective. Ideas?
Thanks in advance!
Mark
Edit... I know not what follows will work using the MINUS operator, but my actual query is really huge, and I don't want to have to write it twice...
{code}
Select
ItemType,
sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
sum (case monthname when "APR" then Val else 0 end) as APR.
sum (case when monthname 'MAY', then Val else 0 end) either.
sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
sum (case monthname when "JUL" then Val else 0 end) as JUL,.
sum (case monthname when "AUG" then Val else 0 end) as AUG.
sum (case monthname when "MS" then Val else 0 end) as MS.
sum (case monthname when "OCTS" then Val else 0 end) OCT.
sum (case monthname when "NOV" then Val else 0 end) as NOV.
sum (case monthname when 'DEC' then Val else 0 end) as DEC
FROM MyTable
Group of itemtype
less
Select
ItemType,
Jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
de)
Select
ItemType,
sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
sum (case monthname when "APR" then Val else 0 end) as APR.
sum (case when monthname 'MAY', then Val else 0 end) either.
sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
sum (case monthname when "JUL" then Val else 0 end) as JUL,.
sum (case monthname when "AUG" then Val else 0 end) as AUG.
sum (case monthname when "MS" then Val else 0 end) as MS.
sum (case monthname when "OCTS" then Val else 0 end) OCT.
sum (case monthname when "NOV" then Val else 0 end) as NOV.
sum (case monthname when 'DEC' then Val else 0 end) as DEC
FROM MyTable
Group of itemtype
)
where (oct = 0 & nov = 0 and dec = 0 and jan = 0 and 0 = Feb and mar = 0
apr = 0 and may = 0 and = 0 jun and Jul = 0 and aug = 0 and Ms = 0
)
order of itemtype
{code}
Change again... OK, I guess that I am answering my own question here, but I think that by using a WITH to write the main request once clause and then selecting * twice using the MINUS operator between where the second query is where (oct = 0, etc.) is what I need. If anyone has better suggestions, please let me know! Here's the logic of nickname for what I come up with to date...
{code}
WITH mainquery as (select all)
Select * from mainquery
less
Select * from mainquery where (oct = 0, nov = 0, etc...)
{code}
Thanks again!
Mark
Published by: user455268 on March 1, 2012 19:13
Published by: user455268 on March 1, 2012 19:16Hello
You can do it with a HAVING clause:
select itemtype, sum (case monthname when 'JAN' then theval else 0 end) as JAN, sum (case monthname when 'FEB' then theval else 0 end) as FEB, sum (case monthname when 'MAR' then theval else 0 end) as MAR, sum (case monthname when 'APR' then theval else 0 end) as APR, sum (case monthname when 'MAY' then theval else 0 end) as MAY, sum (case monthname when 'JUN' then theval else 0 end) as JUN, sum (case monthname when 'JUL' then theval else 0 end) as JUL, sum (case monthname when 'AUG' then theval else 0 end) as AUG, sum (case monthname when 'SEP' then theval else 0 end) as SEP, sum (case monthname when 'OCT' then theval else 0 end) as OCT, sum (case monthname when 'NOV' then theval else 0 end) as NOV, sum (case monthname when 'DEC' then theval else 0 end) as DEC from mytable group by itemtype HAVING MIN (theval) != 0 OR MAX (theval) != 0 order by itemtype ;
If the values are all 0, then the MIN and MAX will be 0.
If the MIN or MAX is not 0, the values are all 0.This assumes that the combination (itemtype, monthname) is unique, because it is in your sample data.
If this is not the case, start with a subquery that GROUPs BY itemtype, monthname, so that when you get to the main request, this combination will be unique. -
SET COLSEP does not insert character if the column is null or empty - please help
Hello experts,
This is probably a question of beginner and I can't seem to find the answer. I train at the output of the coil of a simple SQL query to a file .txt or .csv using colsep as the column separator that prints fine except when there is a column value empty. Here is my SQL:
recsep off Set
set linesize 240
NewPage 0 value
set pagesize 9999
the value of colsep «;»
BREAK ON JUMP MESSAGE_SET_NBR 1 ON LAST_UPDATE_DTTM
Select D.MESSAGE_SET_NBR, S.DESCR, D.MESSAGE_NBR, D.LAST_UPDATE_DTTM, D.MESSAGE_TEXT
PSMSGCATDEFN D, PSMSGSETDEFN S
WHERE
D.MESSAGE_SET_NBR = S.MESSAGE_SET_NBR AND D.MESSAGE_SET_NBR BETWEEN 999 AND 19999
ORDER by D.MESSAGE_SET_NBR, D.MESSAGE_NBR ASC, S.DESCR
Here is an example of the data that are generated. The missing splitter really screw up my spacing outfile. Please note the last line that is missing from the colsep the missing date.
18177; Applicant tracking messages. 2582; APRIL 13 07; Some applicants, %1, do not have an email address in the order
; Applicant tracking messages. 2613; 7 FEBRUARY 07; Rejected candidates
; Applicant tracking messages. 2614; 4 APRIL 07. Select the employee to whom the plaintiff is routed
; Applicant tracking messages. 2615; 7 MARCH 07; The name of this source is in use.
; Applicant tracking messages. 2616; JULY 2 09; Subsource name is in use.
; Applicant tracking messages. 2617; 12 OCTOBER 10; Jurisdiction is not specified for one or more skills.
; Applicant tracking messages. 2618; Please enter a value in the field before continuing.
Thanks in advance for your help!... Jason
Published by: user957626 on June 16, 2011 14:40Hi Jason,
Welcome to the forum!
Usually, when you go to waiting a .csv file, you want to concatenate the columns together as
select empno || ';' || ename || ';' ||job from emp;
Downside is that you need to SET 0 PAGES and then produce your own header.
Something likePROMPT Empno;Ename;Job
Alternatively, if you want to pursuit the COLSEP approach, you can play with
SET NULL text
Concerning
Peter -
Where the column to enable or disable tracks (12.3.2.35)?
After the update of 12.3.2.35 I miss the column where I can click in order to activate or disable the track in the Playlist Layout "Title".
In previous versions, I used an AppleScript for marking and copying selected titles and now?
Thanks for help
JG
Boxes not appearing is not in iTunes 11 - https://discussions.apple.com/message/21933606#21933606 - to ensure that the preferences are set to display check boxes.
-
Mark from a table where the column value is a colon-delimited list
Version: Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
Hello
This is a new query of a query Frank helped me with:
Demand is all users to restrict the report based on a multiple selection on the front-end server (application APEX) filter.
The filter returns that a colon-delimited list and the data in the table can be saved in a delimited by a colon list too. There may be 1 to n values (up to 4000 characters).
I need a WHERE clause that will allow a match, if it exists, between the data in the column of the Table and the Mult-selection list filter.
The abbreviated for this post query would be something like:
SELECT slt_id, slt_item, slt_owner
OF slt_dashboard
WHERE slt_owner IN (colon delimited page list);
The Create Table and Insert statements:
CREATE TABLE slt_dashboard ( dashboard_id NUMBER, slt_id VARCHAR2(10), slt_item VARCHAR2(2500), slt_owner VARCHAR2(4000), slt_type VARCHAR2(25), slt_year NUMBER, parent_id NUMBER ); --Insert slt_dashboard INSERT INTO slt_dashboard(dashboard_id,slt_id,slt_item,slt_owner,slt_type,slt_year,parent_id) VALUES (12,'1.1','Implement revenue enhancement initiatives','E15889:JPARISI:BDUR63','Business Commitment',2014,6); INSERT INTO slt_dashboard(dashboard_id,slt_id,slt_item,slt_owner,slt_type,slt_year,parent_id) VALUES (13,'1.2','Strengthen our Energy position','KVROMAN','Business Commitment',2014,6);
I have a function to separate the list delimited by two points in a table for the IN clause, but because these values can be saved in a delimited list of Colon in the column of the Table, I have a problem, being able to analyze the data in the column, AND the filter data.
The function is:
CREATE OR REPLACE FUNCTION get_list( p_string IN VARCHAR2 ,p_delimiter IN VARCHAR2 DEFAULT ':' ) RETURN vc_array_1 PIPELINED IS l_string VARCHAR2( 32000 ); l_array wwv_flow_global.vc_arr2; BEGIN l_array := APEX_UTIL.string_to_table( p_string ,p_delimiter ); FOR i IN l_array.FIRST .. l_array.LAST LOOP PIPE ROW ( TRIM( l_array( i ) ) ); END LOOP; RETURN; END;
The function called in the query in the form (it's just for reference in case someone wanted to know):
SELECT ... FROM ... WHERE slt_owner IN (SELECT * FROM TABLE( get_list( :P115_SLT_OWNER ) ));
But I can't use this approach because the data in the Table can be saved in a delimited list of Colon too.
Desired output:
If the Mult-Select list filter contains: E15889:JPARISI then
1.1 implementation of the E15889 revenue improvement initiatives; JPARISI (it's a semicolon between the names)
If the multiple-selection list filter contains: KVROMAN then
1.2 strengthen our position of energy KVROMAN
If the multiple-selection list filter contains: BDUR63:KVROMAN then
1.1 implementation of the BDUR63 revenue improvement initiatives
1.2 strengthen our position of energy KVROMAN
Please let me know if something is not clear.
Thank you
Joe
I went to approach the Table and the Page works perfectly.
Thank you to everyone!
Thank you
Joe
-
Multi select in the column picker
Experts,
I have a requirement... When I need to select several columns in the column Chooser... I can't go to the view due to its limitations selector...
the columns that are displayed in the drop-down menu to the bottom of the column selector cannot be tab criteria... so... I can not go to show the selector... I want that the selector column... but with that... usage may need to select 1,2 or even more...
is it possible... Help, please
Thank you
KiranHi, kiran. Glad to see that it works. To assign points, you must go to the line items and top right indicate the 'proper' and 'useful '; otherwise, no points are awarded. Thank you.
-
How to assign the text value when the data in the column is null or empty
Hello guys
I have a small question
I have a column A that half of its value is empty, now the condition is that whenever the column is empty, assign "N/a" in the column... So I wrote a code which is:
<? If: not (column A)? > column a = 'n/a' <? end if? >
However, when I preview the RTF model, the data in the column still has not changed at all, many lines are still empty and did not show 'n/a '... The column is of type text
Please advice
Thank youN/A
-
disabled the columns writing null in DB
Hi all
I have an im app building and there is a tabular form with a few pairs of columns, one column is a code and the other is a description.
I have LOV popups that populate the description based on the chosen code.
What is now everything works really well.
Then I disabled all the fields of description in tabular form (for 25 displayed lines), the surface looks like a lot.
the user selects the code from the context menu and the changes of the description. and the description cannot be changed.
but when the user clicks on the button submit, these fields of 25 description is written with the NULL value to the database.
is this normal?
I just need to activate the fields again before submitting? or is there a better way to do it?
Thanks in advance
RyanHello
One way is to change your button to submit measures for "defined by the dynamic Action.
Then create a dynamic action that fires on your submit button click event.
In dynamic action, first enable you items and then submit.Kind regards
Jari
-----
My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
Twitter: http://www.twitter.com/jariolai -
SQL join on the two tables where the column as another column
Hi all
tried to get the results of a join between two tables where only one column is like another.
Table1 (nameA) examples: black2, green1
Table2 (Name) example: black2.location.uk.com, green1.location.uk.com
so, for example, I want to match all those in table1 with black2 column in table2 that begins with black2 and so of suite, if you see what im trying to get to!
My sql up to now:
but it errors:select * from schema.table1 a join schema.table2 b on a.nameA like concat('%', b.nameB, '%');
ORA-00909: invalid number of arguments
00909 00000 - "invalid number of arguments.
Any help or advice would be greatly appreciated, thank you!Or any of them should do...
select * from schema.table1 a join schema.table2 b on a.nameA like '%'||b.nameB||'%';
or
select * from schema.table1 a join schema.table2 b on instr(b.nameB,a.nameA) > 0
-
Update updated the columns with null are excluded from the DB adapter
Hi all
My fusion system interacts with DB2 using the DB adapter.
I have a script that I need to update a flag in the table after completing my bpel workflow. But by updating the value of indicator to "Processsed", there are other columns with a NULL value.
How to solve this problem. I don't want to do, the other columns should not be alerted.
Thank you
Richa
Hello
The issue has been resolved. In fact, I've updated the update statement, excluding items that couldnot be updated top link mappings. I had to create a new adapter and it worked.
Concerning
-
create a view, the default value of the columns are NULL
Windows XP / 10g 10.2.0.1.0
I have a table tab1 (test1, test2, test3)
And, I have to create a view as:
create or replace VW1 (test1, test2, viewtest1, viewtest2) as (select test1, test2, viewtest1, viewtest2 from tab1, double);
And need to viewtest1 and viewtest2 to be default null value column.
Thank you.You are looking for something like this?
create or replace VIEW VW1(test1, test2, viewtest1, viewtest2) as (select test1, test2, NULL, NULL from tab1);
-
update of NULL in the column with the values of the adjacent column
Examples of data
with test_data as (select 1 as one, null as two, 2 as three,5 as four, 6 as five, null as six from dual union all select 1 as one, null as two, 2 as three,5 as four, 6 as five, null as six from dual) select * from test_data;
This is one of those cases, the case may be where any value of a column can be null
or two similar columns can be null. If the column is null then I want to update the adjacent column
average value of the column, if the first column is null so I want to take the next non-null column and update, if the last column is null
so I want to take prev not zero column and to update.
In this case would be my expected output
Un Two Three Four Five Six 1 1.5 2 5 6 6 1 2 3 5 6 6 Prospects for the future the suggesion or advice.
Or, using Analytics:
SQL> with test_data (id, one, two, three, four, five, six) as ( 2 select 1, 1 , null, 2 , 5, 6, null from dual union all 3 select 2, 1 , null, 3 , 5, 6, null from dual union all 4 select 3, 1 , null, null, 5, 6, null from dual union all 5 select 4, null, null, null, 5, 6, null from dual 6 ) 7 select * 8 from ( 9 select id 10 , cell 11 , case when next_nn is not null and prev_nn is not null 12 then (next_nn + prev_nn)/2 13 else nvl(next_nn, prev_nn) 14 end val 15 from ( 16 select id 17 , cell 18 , val 19 , last_value(val) ignore nulls over(partition by id order by cell) as prev_nn 20 , first_value(val) ignore nulls over(partition by id order by cell range between current row and unbounded following) as next_nn 21 from test_data 22 unpivot include nulls (val for cell in (one as 1, two as 2, three as 3, four as 4, five as 5, six as 6) ) 23 ) 24 ) 25 pivot ( min(val) for cell in (1 as "ONE", 2 as "TWO", 3 as "THREE", 4 as "FOUR", 5 as "FIVE", 6 as "SIX") ) 26 ; ID ONE TWO THREE FOUR FIVE SIX ---------- ---------- ---------- ---------- ---------- ---------- ---------- 1 1 1,5 2 5 6 6 2 1 2 3 5 6 6 3 1 3 3 5 6 6 4 5 5 5 5 6 6
Maybe you are looking for
-
I can't find drivers for Tecra M5
I can't find drivers for Tecra M5The names do not match on the driver download page. -Intel(r) 82801GBM (ICH7-M) LPC Interface Controller - 27 b 9-Location 0 (biometric co-processor)-Driver audio location 65535 (Modem internal High Definition Audio B
-
How to convert an image to grayscale 8 bits unsigned 2D table
Hello. The "Color Utilities' Vision Development Modulde function contains the ColorImageToArray IMAQ, who only has the 32-bit unsigned integer as output values. Y at - it an option to reach a value of the integer not signed 8 bit at the exit?
-
registered dynamic events prevent playback of a video
Hello I'm busy buildin separated a video player and want to control it via a main VI. The strange thing is: when I do where I have control on the video player, she plays the vacuum (H.264), but when I record events (dynamically) and read it via my ma
-
Presario CQ60: Code password Bios 11297
Hello, excuse me that I do not write English. I forgot my bios password, none do not forget, I hope help me. the code has been send to the screen is planned: My laptop Presario CQ60, 11297 Thank you
-
error 0x0000007E (XP) when no physical disk Boot Hiren boot USB (X 60)
On my other (HP) machine boot Hiren that USB does work perfectly while no physical hard disk is present. It doesn't go into my X 60 laptop. I guess that's maybe a BIOS setting. Could you help me that that?