SQL query to restrict null values
HelloI have the following table
Procurement_id estimate_end_date revenue
1 01-oct-2012 $1000
2 02-oct-2012 $1500
3 01-dec-2012 $300
4 01-jan-2013 $500
5 21-Nov-2013 $900
.
.
.
I want only the procurement_ids that have a date of estimated that between 30 and 60 days. and if its estimated finish date is within 30 days, I show that a column monthstoend as 1 and in the 60s would be 2.If the output would be something like
ProcurementId Monthstoend revenue
1 1 $1000
2 1 $1500
5 2 $900
Basically, I want to remove all null values. the query I came wasSelect
procurement_id,
(case when (estimated_end_Date - sysdate) < = 30 then 1)
When (estimated_end_Date - sysdate) between 21 and 60, then 2
on the other
null
end) montstoend
recipes
Of
Table;
Is there a way to eliminate NULL values in the same query. I know that we can query on top of this request and then to eliminate NULL values, but I was wondering if we can do it in the same query. I use a similar in a much larger request functionality, if want to avoid that if possible.
Any suggestions?
Thank you
Published by: ryansun on September 26, 2012 01:08
It's not fair...
select procurement_id
,(case when (estimated_end_Date - sysdate) <= 30 then 1
when (estimated_end_Date - sysdate) between 31 and 60 then 2
else null end) montstoend
,revenue
from Table
where estimated_end_Date - sysdate <= 60
?
Tags: Database
Similar Questions
-
Hi all
Can I restrict null values when passing parameters in procedures. can someone explain to me with a small exampleHello
Pascale says:
The table does not allow null values. It throws an exception when the value null is passed IN parameterAre you talking about raising of arguments passed to a procedure or a table?
If a column in the table has a NOT NULL constraint, an error will be reported in the world tries to add a NULL value in this column, or if someone tries to change an existing value with a NULL value.
I don't know anyway auto to force an error when a procedure is called with a NULL argument. There may not be any built-in mechanism because it is so easy to test the NULL at the beginning of the procedure and explicitly to trigger an error.
-
Report, SQL query based on the values of the elements (question SQL)
Hello
I use APEX 4.0 with Oracle 10 g r2 under Windows XP Pro SP3.
I have an interactive report and a menu with a few items to filter the report.
It works with most of the elements, but my problem is to select lists that have additional values, for example:
and I will return null as ' (return '%').SELECT '(null)' display_value, 'NULL' return_value FROM DUAL UNION ALL select distinct(SPAT_AREA_NAME) display_value, SPAT_AREA_NAME return_value from SPATIAL_POINTS order by 1
For example, if the user selects "(null)", the report should return all rows with a NULL value in the column AREA_NAME.
If he chooses "", the report should return all the lines. "
and if the user selects a value, the report should return all the lines containing the value in column AREA_NAME.
I don't know how to build my application. I tried with the CASE statements, DECODE, etc... but I still can't!
My report query is for now:
Any idea?select SPAT_ID, SPAT_ACCL_NAME, SPAT_AREA_NAME, SPAT_CLASS, SPAT_NUMBER, SPAT_PT, SPAT_TYPE, SPAT_STATUS, from SPATIAL_POINTS where upper(SPAT_AREA_NAME) LIKE upper(:P3_FILTRE_AREA_NAME) AND upper(SPAT_ACCL_NAME) LIKE upper(:P3_FILTRE_ACC_NAME) AND upper(SPAT_CLASS) LIKE '%'||upper(:P3_SPATIAL_CLASS)||'%' AND instr(upper(:P3_SPATIAL_TYPE_VALUES),upper(SPAT_TYPE)) > 0 AND instr(upper(:P3_SPATIAL_STATUS_VALUES),upper(SPAT_STATUS)) > 0 AND instr(upper(:P3_SPATIAL_POINT_VALUES),upper(SPAT_PT)) > 0
Thank you!
Yann.Hello
Then, assuming that spat_accl_name is not a string value "NULL" then you can try this...
SELECT spat_id, spat_accl_name, spat_area_name, spat_class, spat_number, spat_pt, spat_type, spat_status, ROUND(spat_cumul, (SELECT up_number_precision FROM user_preferences WHERE UPPER(up_nice_login) = UPPER(v('APP_USER')))) AS "SPAT_CUMUL" FROM spatial_points WHERE :p3_filtre_acc_name IS NULL AND spat_accl_name IS NULL OR(CASE WHEN :p3_filtre_acc_name = '%' THEN NVL(spat_accl_name,'NULL') ELSE :p3_filtre_acc_name END = NVL(spat_accl_name, 'NULL'))
See you soon
Ben
-
SQL query to find the value of a column as well!
Hi all
I have to write a query that needs to retrieve the value of a column in table B if the column value is Null in the Table A. Please find below the sample table.
Table A:
*******
EmpNumber ID
------------------------------
1 12345
2
3 14789
4
5 74563
Table B:
*******
EmpNumber ID
-----------------------------
1 12345
2 78451
3 14789
4 12212
5 74563
In the table a second and third rows have value for EmpNumber. The query should look for table B for EmpNumber value. Please advise me to make this request.
Thank youThis?
select a.id, nvl(a.empnumber,b.empnumber) empnumber from tabA a, tabB b where a.id = b.id;
-
SQL query concat - digital or value error
I get digital error or value by concatenating the sql script...
Here's the example I have in the stored proc. Prime:_ works very well if I comment the secondpart:_. (I changed the query because I write in public forums)
V_SAMPLEQUERY VARCHAR2 (2000);
Prime:_
V_SAMPLEQUERY: = '
SELECT
AB. ABCDID AS ABCDID,
CD. MEMBER MEMBERID AS ID.
CD. FNAME AS FNAME,
CD. LNAME AS LNAME,
CD ACCOUNT AS ACCOUNT,.
MFF ZIP AS ZIP,
AB. INSERTTIME AS INSERTTIME,
AB. INSERTBY AS INSERTBY,
ES.NAME AS STATUS,
MYFUNCTION (E.ABCDID) AS AMOUNT.
PA.NAME AS SOUSENAME,
R.CODE AS BUDGETCODE,
WX. ACCOUNTID as ACCOUNTID,
AB. SOMETYPE AS SOMETYPE,
AB. ACCTREP,
ED. TYPE AS TYPE,
AB. NOTES NOTES AS,
GH. CODEZONE. '''' || GH. PHONE_NUMBER AS PHONENUMBER,
ED. REQUESTEDDATE,
ED. RESERVED (E),
ED. CALLERINFO
PEOPLES AB
CD OF PLACES,
LOCATIONTYPES EF,
ACCOUNTS OF GH,
ACCOUNTdetails IJ,
ACCOUNTstatus KL,
ACCOUNTMEMBERDETAILS, MN,
CO-OP MEMBERS,
QR TO THE BUDGET;
ST BCODES,
ACCOUNTSYSTEM UV,
INFOCALL WX,
YZ PHONE_NUMBERS
WHERE AT.NAME = "SAVINGS"
andCD.MEMBERID = PH. MEMBER ID
andCD.MEMBERID = emission factor. MEMBER ID
and at ADDRESSTYPEID = COEFFICIENT of ISSUE. ADDRESSTYPEID
andCD.MEMBERID = AB. MEMBER ID
andAB.STATUS =. STATUS (+)
andAB.ABCDID = ED. ABCDID
andAB.ABCDID = EP ABCDID (+)
and EP. MEBER_ID = PA. MEBER_ID (+)
andAB.BID = R.BID (+)
andAB.SAMPLEID = PR SAMPLEID (+)
andAB.ABCDID = BSG. ABCDID (+)
andAB.INFOCALLID = C.INFOCALLID (+)
and YZ. SOMETYPEID = "10000"
ANDAB. INSERTTIME > SYSDATE - 35
ANDAB. INSERTTIME < "
AND WX.NAME IN ('ABCD',
"ELGOUR",
"IJKL",
"MNOP",
"QRST"
UVWX ")
AND MN.NAME = "DONE" '
secondpart:_ * ERROR PART *.
V_SAMPLEQUERY: = V_SAMPLEQUERY | ' ORDER OF AB. THE USER '; -Here, I'm getting error ORA-06502 - numeric or value error savingV_SAMPLEQUERY VARCHAR2 (4000);
do as above change something?
-
Dear all,
I have the main query... And I wrote a query for the delivered quantity.
The query retrieves the accurate data. And when I add the query in main query comes with extra null data.
e.g. query for amount emitted fetches 16 records.
and I run the main question fetches 20 records... there r Archives 4 who issued the amount is null.
How can I limit who registers.
Thank you.Add in which the condition
where column_name is not null
-
How to do a validation based on the SQL query?
Hello
I have a requirement to perform a validation on a field (messageTextinput) in my page OAF.
When I click the button apply, the value in this field is validated based on a SQL query (for example, the value in the field NOT IN (value1 select from table1).)
Help, please.
Best regards
Joe
1. create a SQL query based VO, XXVO. For example:-SQL query is select xx_table;
2. Enter the "Apply" button click event in the controller and run the AM method passing the value entered by the user in the given field, for example:-value is VAL1
3. in the method of the AM, get a handle of the VO, the whereClause and run.
OAViewObjectImpl vo = findViewObject ("XXVO1"); XXVO1 is the name of the instance of the VO above, XXVO
vo.executeEmptyRowSet ();
vo.setWhereClause (null);
vo.setWhereClause ("value =" + VAL1 + "'");
vo.executeQuery ();
If (VO. GetRowCount() > 0)
A record is with the value of VAL1. Perform the required action
I hope this helps.
-
Help with APP_USER in SQL query
Hello
I would like to extract a detail of the user in a form of language element DML based on the logged in user and the standard authentication scheme.
I make this request in the element:
The user in the session is equal to the value of the EMAIL. In fact, the value in the session is a capital letter, and the other in the database is tiny. I think that's irrelevant anyway.select ANALYST_FIRST_NAME ||' '|| ANALYST_LAST_NAME d, ANALYST_ID r from QTMT_ANALYST where EMAIL = :APP_USER
The query do not of any value. Could you please let me know what I did wrong?
APEX: 4.2
Item Source type: query SQL (single return value)
Thank you and best regards,
VladimirTo be on the safe side you should uppercase both sides of the equation. It could be that the user name is entered in lowercase.
But if you think that your request is correct, test it by using a literal rather than the user name.
select ANALYST_FIRST_NAME ||' '|| ANALYST_LAST_NAME d from QTMT_ANALYST where upper(EMAIL) = upper(:APP_USER);
for testing purposes, use something like this:
select ANALYST_FIRST_NAME ||' '|| ANALYST_LAST_NAME d from QTMT_ANALYST where upper(EMAIL) = upper('[email protected]');
Published by: Sven w. October 23, 2012 13:30
APEX: 4.2
Item Source type: SQL Query ( return a single value )I just noticed that you use an element that has this as the SQL source. This only works if the sql returns a row and a column only. That's why I removed the second column in your query.
Published by: Sven w. October 23, 2012 13:33
-
Hello guru - is there a sql query to retrieve the value of the net payment in the form of accrual accounting?
Is the net value of law considered to be similar to the balance of the PTO?
Thank you
ABCreate a custom as a function:
CREATE OR REPLACE FUNCTION APPS.get_leave_accrual(p_assignment_id IN NUMBER, p_plan_id IN NUMBER, p_payroll_id IN NUMBER, p_business_group_id IN NUMBER, p_calculation_date IN DATE, p_accrual_start_date IN DATE ) RETURN NUMBER IS ld_start_date DATE; ld_end_date DATE; ld_accrual_end_date DATE; ln_accrual NUMBER; ln_entitlement NUMBER; BEGIN per_accrual_calc_functions.get_net_accrual (P_Assignment_ID => p_assignment_id, P_Plan_ID => p_plan_id, P_Payroll_ID => p_payroll_id, P_Business_Group_ID => p_business_group_id, P_Calculation_Date => p_calculation_date, P_Accrual_Start_Date => p_accrual_start_date, P_Start_Date => ld_start_date, P_End_Date => ld_end_date, P_Accrual_End_Date => ld_accrual_end_date, P_Accrual => ln_accrual, P_Net_Entitlement => ln_entitlement); RETURN(ln_entitlement); END; /
You can use this function in sql (select)
-
SQL query to display the sum of the values of each June and December
Hello having problems of construction of a query to the list SQL query to display the sum of the values of each June and December each year.
My Table;
TABLE name: MONTH_TERM
Fields with values:
TERM_KEY MONTH_ACTUAL MONTH_DATE 82 500 01/11/2015 0:00 82 450 01/12/2015 0:00 82 405 01/01/2016 0:00 82 400 01/02/2016 0:00 82 450 01/03/2016 0:00 82 425 01/04/2016 0:00 82 435 01/05/2016 0:00 82 410 06/01/2016 0:00 82 409 01/07/2016 0:00 82 415 01/08/2016 0:00 82 420 09/01/2016 0:00 82 422 10/01/2016 0:00 82 436 11/01/2016 0:00 82 556 01/12/2016 0:00 82 568 01/01/2017 0:00 82 624 02/01/2017 0:00 What I would like to see in a query result:
TERM_KEY MONTH_ACTUAL MONTH_DATE Total of 6 months 82 500 01/11/2015 0:00 82 450 01/12/2015 0:00 950 82 405 01/01/2016 0:00 82 400 01/02/2016 0:00 82 450 01/03/2016 0:00 82 425 01/04/2016 0:00 82 435 01/05/2016 0:00 82 410 06/01/2016 0:00 2525 82 409 01/07/2016 0:00 82 415 01/08/2016 0:00 82 420 09/01/2016 0:00 82 422 10/01/2016 0:00 82 436 11/01/2016 0:00 82 556 01/12/2016 0:00 2658 82 568 01/01/2017 0:00 82 624 02/01/2017 0:00 ---
Here's my query:
Select
"TERM_KEY,"
"MONTH_ACTUAL,"
to_char(MONTH_DATE,'MM/YYYY') MONTH_DATE,
DEAL to_char (MONTH_DATE, 'MM')
WHEN '06' THEN (SELECT SUM (MONTH_ACTUAL)
OF MONTH_TERM
WHERE the to_char (MONTH_DATE, 'MM') between 1 and 6
AND term_key = 82)
WHEN '12' THEN (SELECT SUM (MONTH_ACTUAL)
OF MONTH_TERM
WHERE the to_char (MONTH_DATE, 'MM') between 7 and 12
AND term_key = 82)
ELSE null
END as SIX_MO_CUMM,
of MONTH_TERM
where term_key = 82
It's my results:
TERM_KEY MONTH_ACTUAL MONTH_DATE Total of 6 months 82 500 01/11/15 0:00 82 450 01/12/15 0:00 3608 82 405 01/01/16 0:00 82 400 01/02/16 0:00 82 450 01/03/16 0:00 82 425 01/04/16 0:00 82 435 01/05/16 0:00 82 410 01/06/16 0:00 3717 82 409 01/07/16 0:00 82 415 01/08/16 0:00 82 420 01/09/16 0:00 82 422 10/01/16 0:00 82 436 01/11/16 0:00 82 556 01/12/16 0:00 3608 82 568 01/01/17 0:00 82 624 01/02/17 0:00 Any ideas on how to fix would be great
Select term_key,
month_actual,
month_date,
case mod (to_char (month_date, 'mm'), 6)
When 0 then sum (month_actual)
During)
term_key partition
order of month_date
between the previous month '5' interval and the current line
)
end '6 MONTHS in TOTAL'
from tbl
order of term_key,
month_date
/
TERM_KEY MONTH_ACTUAL MONTH_DAT 6 MONTHS TOTAL
---------- ------------ --------- --------------
82 500 NOVEMBER 1ST, 15TH
82 450 1 DECEMBER 15 950
82 405 1 JANUARY 16
82 400 1 FEBRUARY 16
82 450 1ST MARCH 16
82 425 1ST APRIL 16
82 435 1 MAY 16
82 410 2525 1 JUNE 16
82 409 1 JULY 16
82 415 1ST AUGUST 16
82 420 16 - SEP - 01TERM_KEY MONTH_ACTUAL MONTH_DAT 6 MONTHS TOTAL
---------- ------------ --------- --------------
82 422 1 OCTOBER 16
82-436 NOVEMBER 1, 16
82 556 2658 1 DECEMBER 16
82 568 1 JANUARY 17
82 624 1 FEBRUARY 1716 selected lines.
SQL >
SY.
-
How to pass the values separated by commas in SQL query
Hi all
I use Oracle APEX 4.2
I've created a report of iterative with condition 1 ITEM IS NOT NULL.
This is the SQL query
SELECT MY. ACCT_ID,
JAI DETAILS
The ACCT MA, ACCT_hist EB
WHERE MY. ACCT_IK = EB. ACCT_IK
AND MY. ACCT_ID IN (: P3_IN_MRN);
A P3_IN_MRN element is a text field. The thing is that it works if I give a value, but its does not work if I have several values with comma separated as 123,345,543.
What could be the solution for multiple values in the SELECT query.
Really appreciate your help.
I made use of this on pretty much every project I've worked on:
https://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:210612357425
Hope that helps.
Duncs
-
Replace NULL values for PIVOT query
Hello
I'm working a table for sales, for certain values, when now columns, finishing with a null value. How can I handle these values 0 (zeros).
WITH (AS PIVOT_DATA)
SELECT S.ZONE_CODE, Z.ZONE_NAME, S.YEAR, S.PERIOD, S.SALES
OF STAT_TABLE_SALES ADV
AREAS OF JOIN Z ON S.COMP = Z.COMP AND S.ZONE_CODE = Z.ZONE_CODE
WHERE S.COMP = '001'
AND S.BRAND_CODE = '001'
)
SELECT *.
OF PIVOT_DATA
PIVOT)
SUM (SALES) FOR THE PERIOD (YEAR) TO ((20091),
(2009,2),
(2009,3),
(20094)
(2009,5),
(2009,6),
(2009,7),
(2009.8),
(2009,9),
(2009.10)
(2009,11),
(2009.12),
(2010,1),
(20102)
(2010,3),
(2010,4),
(2010,5),
(2010,6),
(2010.7))
)
ORDER BY DESC NULLS LAST 14;
This query returns the following:
COD_ZONA NOM_ZONA 2009_3 2009_2 2009_1
-------- ------------------------------ ---------------------- ---------------------- --------------------
01 YEDUSIJH. 1382367.75 1559943.27 1441279.64
02 C, ASKAK 711897.82 865854,05 1583232.3
ASDFG 03 130443.03 205409,84 178633.69
04 OSOIDSD 320118.32 439008,83 409251.18
05 ODFSDF 300908.21 276301,59 260188.53
06 CH 242749.65 325196,71 464938.9
SOA 07 610312.31 606312,93 754569.82
08 SAN 89426.8 81360,04 61649.27
09 YP 284487.79 328281,31 267210.85
10 TC 87043.28 158594,43 85195.8
11 BAGNN 76778.78 68180,76 118530.04
12 CRT 122023.7 143442,21 134744.85
13 ABC 209992.79 196477,03 185222.14
IDLIB 14
15 ARE 23870.41 4137,33 16660.53
* These are not all the columns and rows, but it is a piece of what it returns.
How can I replace the NULL values with 0 (zeros).Still not sure why nvl shouldn't meet your needs:
SQL> select ename, nvl (clerk_20, 0) clerk_20, nvl (sal_30, 0) sal_30 from emp pivot (sum (sal) for (job, deptno) in ( ('CLERK', 20) clerk_20, ('SALESMAN', 30) sal_30)) / ENAME CLERK_20 SAL_30 ---------- --------------- --------------- WARD 0 1250 JONES 0 0 TURNER 0 1500 ADAMS 1100 0 ALLEN 0 1600 SMITH 800 0 CLARK 0 0 KING 0 0 BLAKE 0 0 JAMES 0 0 FORD 0 0 SCOTT 0 0 MARTIN 0 1250 MILLER 0 0 14 rows selected.
-
How to use the multiple selection list values in sql query
Hi all
In the search form, I have a multiselect llist tell (P3_STATUS) and I want to have a query using this element and fetch documents
How to do a sql query based on the selection of the value of this element.
Please could someone help me on this?SELECT "W"."START_DT" "Start Date", "W"."CAMPAIGN_CODE" "Campaign Name", "W"."MKT_CHANNEL" "Channel", "W"."MKT_SUB_CHANNEL" "Sub Channel", "W"."PROMO_CODE" "Promo Code", "W"."TRACKING_CODE" "Tracking Code", "W"."TFN" "TFN", "W"."STATUS" "Status", "W"."CAMPAIGN_CODE" "Edit" FROM "WC_MKT_CAMPAIGN_DS" "W" WHERE (MKT_CHANNEL = decode(:P1_CHANNEL,'%null%',MKT_CHANNEL,NULL,MKT_CHANNEL,:P1_CHANNEL)) AND (MKT_SUB_CHANNEL= decode(:P1_SUB_CHANNEL,'%null%',MKT_SUB_CHANNEL,NULL,MKT_SUB_CHANNEL,:P1_SUB_CHANNEL)) AND *STATUS = decode(.................*
Thanks in advance
Robert LTry to change your selection of status to
AND INSTR(':'||:P3_STATUS||':',':'||STATUS||':') > 0
-
Report Null VS discoverer view show SQL query results.
I created a simple Cross Tab discoverer of a custom SQL report that has a calculation for sales. The output is to give all null values even if there is a sale. The output does not seem fair. Then I copied the query from tools-> SQL Show and ran the query in the TOAD where I show the balances for the report. I don't understand why it does not show in the discoverer. Help, please.
Thank you
Published by: PA1B on January 27, 2010 11:40Hello
You must show the translated_flag as a dimension in the report or use it in a function group in the calculation. What calculation should be tried? And why did not work?
Rod West
-
date picker default value appears only not in the sql query
Hello
I have a page as a table with a query similar to the following:
Select emp_name, salary of emp_table where (hire_date) trunc = trunc (to_date (:P42_START_DATE))
where P42_START_DATE is the name of a date picker.
I put the date picker, "only when the current value in session state is null" and the value of being "select trunc (next_day(sysdate,'MON')-7) from dual;"-essentially the Monday of the current week, the type of source. I updated the date to 5 selector and the sequence of the region 10. Now, when I opened this page, no data gets pulled. I checked the source of the page and the value of the entry date picker is used to "November 17, 2008", but is not somehow reflected in the sql query.
Data get retrieved if I put manually the date in the date picker, but I would like that it by default on Monday of this week. What I am doing wrong?
Thank youHello
>
"Article 1 of the Expression value is NULL" where is expression 1
P42_START_DATE
>Yes, that's correct - No. colon is required here as we don't not using the item as a variable binding, just name for the condition. In my tests, I put the calculation for:
Name of article: P31_HIREDATE (put your P42_START_DATE here instead)
Type: SQL query
Point calculation: before header
Calculation: SELECT TO_CHAR (TRUNC (SYSDATE, 'DAY'), 'DD-MON-RR') FROM DUALMy report SQL statement is:
SELECT EMPNO, ENAME, HIREDATE FROM EMP WHERE NVL(HIREDATE, TRUNC(SYSDATE)) < TO_DATE(:P31_HIREDATE,'DD-MON-RR')
My datepicker object has no special parameters - so:
Name: P31_HIREDATE
Display: Date Picker (DD-MON-RR)
Source: Only when...
Source type: static...
The source value or expression: (empty)
Default: (empty)And that's what I did to get: http://htmldb.oracle.com/pls/otn/f?p=55041:31
Change the date that you like or click Reset to clear the cache (the calculation will be then reset the date to the current date and refiltrer the report)
Andy
Maybe you are looking for
-
a popup that wants to scan and I do not know whence it
Every day when I return to my office when I got the computer "sleep" there this pop up on how I have to scan my computer for viruses. "optimizer Pro" or something like that wants to do the analysis. Can I search with a unknown scan pop up? I use 'ava
-
How to go online with this 4090XCDT Satellite with Win 98
I have done with my laptop end of fathers, but have no idea if I can get online with it or how do I know?I have the old windows 98 disk so assume it's about it. Any help would be appreciated. I know its old, he died in 2000, but no idea of what he us
-
Underflow memory device Embedded PXI-4461
I use a PXI-4461 to generate one acquire a singal. When I generate the signal I get error-200621 (onboard device memory overflow) onDAQmx VI stop. I do not understand what means error. Signal information Signal type = sine waveFrequency = 3K amplitud
-
code 511 undetected fan and the fan does not turn or did not run where do replacement or this question solfware please help [Moved from the community centre of Participation]
-
How can I stop my laptop keyboard jump letters when I type
How can I stop my laptop keyboard jump letters when I type