cases where the declaration in decode
HelloHere is an example with the CASE WHEN statement.
SELECT empno, ename, sal,
CASE
Sal WHEN BETWEEN 800 AND 1200
THEN "low wages".
Sal WHEN BETWEEN 1200 AND 2800
THEN "moderate Pay."
ELSE "higher pay".
END sal_report
EMP;
DECODE even can be a replacement for this scenario, but it can have for flexibility as the CASE may be.
Now, I want the equivalent code to DECODE.
Can someone help me please...
Thanks in advance,
Rami Reddy.
Just to complete, here is the full replication CASE, according to what the OP has posted:
SELECT e.*,
DECODE(ABS(SIGN(sal - 800) + SIGN(sal - 1200)),
2, DECODE(ABS(SIGN(sal - 1200) + SIGN(sal - 2800)), 2, 'Highest Pay', 'Moderate Pay'),
'Lowest Pay')
p
FROM apex.emp e
ORDER BY sal;
Tags: Database
Similar Questions
-
Hello
I want to use the case (or decode etc.) in which a part of sql.
I want to find the number of rows depending on where the conditions.
For example, I have a table b, d, e, p and s are fields of this table.
If the value of the field b is 1 then my condition clause that will be value fields d, e value fields
If the value of the fields of b is 2 then my condition clause where the declaration will be p field value < s value fields.
Select count (*) of A
where
(if b = 1 then) d, e
(if b = 2 then) p < s
How can I achieve this?where (b = 1 and d
-
Problem with the case where the clause
Hello
I want to use cases in which clause. I wrote a very simple query to test how it works. However, I always got an error message. Here's what I did.
Select eid, firstname, lastname from employee where eid = 1 works fine
Select eid, name, name of the employee
where
cases where 1 = 1 then eid = 1
When 1! = 1 then eid = 2
end
I ORA-00905: lack of keyword.
Did I miss something?
Thank you
Jennifer
Hi, Jennifer.
Why do you want to use BOX in a WHERE clause? The wonderful thing about the CASE is that it allows you to do IF-THEN-ELSE logic. In a SELECT clause, or an ORDER BY clause, this is really useful, but the WHERE clause already allows you to use the IF-THEN-ELSE logic.
However, if you use the BOX in a WHERE clause, it is as it does nowhere else. Always BARGAIN instead of a single expression in a SQL data types. All the clauses THEN (and ELSE, if there is one) must return a single expression, such as the NUMBER. (There is no BOOLEAN data type in SQL). So, you can use a CASE statement like this:
...
CASES WHERE
WHEN 1 = 1 THEN 1
WHEN 1! = 1 THEN 2
END = eid
Here, the CASE expression takes the place of a NUMBER.
However, if I was not sure if 1 = 1 or not, I would write the condition in this way, without a CASE expression:
WHERE (1 = 1 AND eid = 1)
OR (1! = 1 AND eid = 2).
-
Case where the Condition when Clause Condition use
Hello
How can I use case in the where condition and in when I need to use a condition, be clearly
I need to get the following
When I run the present, I'm missing keyword error.and (case WHEN :PROMT = 'Closed' then status_date >= trunc(sysdate)) end)
How can I solve this?I think you can do it just like this:
... and ( :PROMPT != 'Closed' or status_date >= trunc(sysdate) ) ...
-
Cases where the failure of the statement
Can anyone help, where I am doing mistake here
-case when "Sales Rep". "" Sales Rep name ' ('Michele Lombardo") then"core facts ". "" Recipes "= 0 otherwise
"Basic facts '." End of revenue. "
Thank you
Veera
Hello
Check this box...
-case when "Sales Rep". "" Sales Rep Name ' to ("Michele Lombardo") then 0 else 'basic facts '. "" End of the revenue.
-
Hi I have a select query that gives question saying key word missing in a case statement else part please suggest.
/ * Formatted on 2012/11/02 16:19 (trainer more v4.8.8) * /.
SELECT a.kintana_number, a.crid, a.projectestimateid, a.reasonimpacts
FROM (SELECT p.kintana_number AS kintana_number, cr.crid AS crid,
PE.projectestimateid AS projectestimateid,
l.LookupValue AS reasonimpacts,
(SELECT COUNT (1))
FROM (SELECT p.projectestimateid
INNER JOIN projectestapplications p projectestimates PA
ON pa.projectestimateid = p.projectestimateid
AND pa.impacted = 1
INNER JOIN applicationsupproviders ASP.
ON asp.appid = pa.appid
INNER JOIN optionssupportproviders OSP
ON osp.providerid = asp.providerid
AND LOWER (TRIM (osp.provider)) = 'ibm - adm.
WHERE asp.providertypeid = 2
OR p.admvendornercid IS NOT NULL
UNION
SELECT p.projectid
PROJECT p INNER JOIN impactedgroups GI
ON ig.projectid = p.projectid
AND ig.impacted = 1
INNER JOIN optionsgroups og
ON ig.groupid = og.groupid
WHERE og.ibmtowerid IS NOT NULL)
WHERE projectestimateid = pe.projectestimateid) AS v_count
OF LEFT OUTER JOIN projectestimates project EP p
ON p.projectid = pe.projectid
INNER JOIN attcr.cr_detail ON pe.crid = cr.crid cr
LEFT OUTER JOIN attcr.cr_detail_reason r ON r.crid = cr.crid
LEFT OUTER JOIN attcr.site_lookup l ON l.lookupid =
r.crreasonid
WHERE (CASE
WHEN v_count = 0
THEN pe.estimatestatusid <>3
ELSE pe.projectestimateid (1, 2, 3)
END
)
PE.CRID AND IS NOT NULL) aWHERE (CASE
WHEN v_count = 0
THEN pe.estimatestatusid <> 3
ELSE pe.projectestimateid (1, 2, 3)
END
)You cannot use the CASE statement like this. Change your where clause like this.
WHERE ( (v_count = 0 and pe.estimatestatusid != 3) or (v_count != 0 and pe.projectestimateid IN (1, 2, 3) )
-
Cases where the undo data generated
Other than the DML activities, what are the other cancellations of cases generated?Most of the DDL statements are translated into some update database dictionary (which means DML to tables SYS) and/or DML on the application tables: so DOF also generates Cancel.
-
using members of the cast with the case of the declaration
Hi guys,.
can someone guide me how to use a "case _ of" with the members of the cast rather than sprites?OK, I see. You can use the case statement and replace the
Manager executeBranchingMenu for this example.------------------------------------------------------
on executeBranchingMenu NomMenu, commandName
commandName case
("Item 1, 1"): go to frame "an image tag.
("Item 1, 2"): go to frame "a few other image tag.
-etc.
cases of termination
end
---------------------------------------------------------But there is a solution even more simple that does not require using a case
Statement at all. Your frame labels just name "Item 1, 1", "Item 1," 2",
etc and use it. It will save you a lot of unnecessary code.---------------------------------------------
on executeBranchingMenu NomMenu, commandName
go frame commandName
end
-----------------------------------------------Furthermore, nothing new in this example of a film that holds the game
head back, then you probably want to add code to do this, otherwise, it will be
jump to the menu. It can be added to the film script.--------------------
on exitFrame
go part
end
------------------- -
Hi all
My job is: Loop While structure generates the signal for 4 seconds when you press the 'start build' button, after that data has been backed up. You press the button "generate the beginning' once again, and the loop runs one again.
My problem is: the first pressing, the loop, exactly 4 s (3, 999 s), but him second, third pressing on... The time elapsed is not 4 seconds, always smaller (even ~ s 0.003). The loop works correctly after press the "Exit" button and launch the program again.
How can I control exactly time loop work While Structure without the press "Exit".
Thank you any help!
P/S: I used the number of cycles (ms) just to look at a working time of the While loop.
NMCuong
This shows a quick solution
-
Hi all
I posted the question about CASES where the condition. It is one of the changes.
The first condition was, if the Individual is 01 extraction then all the values of the table where the column of FLG = 'Y '. If the Individual is 02 and then extract all the values of the table where the column of FLG = ' no or NULL. Here, INDI is the setting.
Select count (*) from cntl
XYZ
where NVL(FLG,'N') = decode(INDI,'01','Y','02','N');
Now the chnages is, if the Individual is 01 and then extract all the values in the table where FLG colum = 'Y '. If the Individual is 02 and then extract all the values in the table, including ('Y', ' n, NULL). no need to put the filter of the FLG columns in which contion.It's not just...
select count(*) into cntl from xyz where NVL(FLG,'N') = decode(INDI,'01','Y','02',NVL(FLG,'N'));
Or shorter:
select count(*) into cntl from xyz where NVL(FLG,'N') = decode(INDI,'01','Y',NVL(FLG,'N'));
If you are happy for 01 retreat flg of Y and any other value fold everything.
Published by: BluShadow on June 3, 2009 12:31
-
Hi guys, I'm not a developer oracle as such, but I'm trying to get some information from oracle to send to other systems of the company, since we are dealing with oracle HRMS as the master system for employee information.
In particular, we would like to create people in our training and the security system when they are created in oracle.
I was told that the oracle per_all_people_f object acts as a slowly changing dimension of type 2, where a person can have several versions, which only is always the current version and the current version can be retrieved using the standard parttern of "date of current between the effective start date and actual end date. So far so good.
However, I can see there are cases where the minimum 'effective_start_date' is greater than the current date. It is, indeed, equal to their start_date. I guess start_date represents "the first day of work" of the person.But this means then there is no "current" information known to people who have not yet really started working for the company again. This seems odd. How can I have someone for whom we have no information "currently correct? I was told that the effective_start_date of the line is automatically set to their "first day of work" date on which the information is entered into the system, IE, the user to enter information doesn't have the ability to say 'this is the current version of the data for that person, who starts at a date in the future. "
For this reason, I cannot know these new people (who have been entered in oracle, but did not have actually to their first day of work still) training system. But we would obviously get people established in related systems so that they can use all of these systems on their first day of work.
Have I misunderstood something here? How can there be no correct version for a person at the date and time?
Hello
How normally "inform you" the training system on a new person record? If it's a kind of report or an interface, it may be useful changed to examine a number of days in the future, for example
+ 7 It is important to understand when you look at an Oracle HRMS instance through enforcement (i.e. the ' front end'), you look at the data on a date date (of the session) - by default, the date is the system date, but it is possible for a user to change this date to be in the future or the past as they see fit. The ability to implement the records in person in the future is a great feature to have, of course, but it must be understood that in this situation, at the date of the day the person's file logically does not exist yet from the point of view of the MFC features. Behind the scenes, however, in the per_all_people_f of the table, the line exist. Similarly, future update of changes to a person (e.g. marital status from Single to married) could be implemented, and the change in status would be visible if the session has been scheduled on a date or after the date of the marriage. As correctly observe you, behind the scenes, the table will hold all historic entries for this person_id with contiguous effective_start_date and effective_end_date beaches.
Either way, date_start value is not related to as such hiring date; It is actually the value of effective_start_date earlier for the person_id. All changes, regardless of how many or what the effective_start_date is in each case, will always carry this same start_date value. It * may * be identical to the hiring date (certainly the fact that you configure their hire date person records would cause that), but if the person has been created as a postulant effective from 1 September and was then hired has effect from 21 September, column start_date value would be still 1 September. The record of the person would be visible when the current date is on or after this date - the only difference is that they show that an employee until the 21st.
I hope this helps, but it is possible, that I just confused you more!
Clive
-
using the function to decode or case in query
Hi experts
I use the Oracle 11 G server, I need to check the length of the value in the name column of the table employee and if length (name) > 39 then the value should be substr (name, 0, 39)
else value should be the name.
I tried code below
but it's not working... can I do this using decode too? which one would be better or this is not a good way?select CASE when length(name) > 39,substr(name,0,39) else name END from employee
Thank youHello
siebelD wrote:
Hi expertsI use the Oracle 11 G server, I need to check the length of the value in the name column of the table employee and if length (name) > 39 then the value should be substr (name, 0, 39)
else value should be the name.
I tried code belowselect CASE when length(name) > 39,substr(name,0,39) else name END from employee
but it's not working...
Review the syntax of the CASE expression in the Manual of the SQL language. An expression BOX always at least a THEN clause. Commas are not part of the syntax of the CASE expression.
can I do this using decode too?
Of course, everything you can do with CASE, you can also do it with DECODE.
that it would be better
This is one of the many situations where the CASE is much shorter, clearer and more effective than DECODE.
or is not a good way?
What is
SELECT SUBSTR (name, 1, 39) AS employee_name FROM employee;
?
If the name is 39 characters (or less), then SUBSTR (name, 1, 39) will ship itself, unchanged.Published by: Frank Kulash on 3 March 2013 14:07
-
I have windowsimagebackup folder where I want to restore the file. This is not the case in the menu catering
Hello
see if this information helps you
How to make a backup of your data
http://www.vista4beginners.com/how-to-backup-your-data
How to restore your files
http://www.vista4beginners.com/how-to-restore-files
the 1st link below is how do the backup complete pc
http://www.bleepingcomputer.com/tutorials/tutorial145.html
and that is how do to recover the backup complete pc
http://www.bleepingcomputer.com/tutorials/tutorial144.html
and here is the information of microsoft in restoring a system image backup
http://Windows.Microsoft.com/en-us/Windows-Vista/restore-your-computer-from-a-system-image-backup
If you have problems, it's in here is a forum for microsoft specifically for backup issues
http://social.technet.Microsoft.com/forums/en-us/WindowsBackup/threads
-
Need all the data in the case where if I pass null
Oracle 10 g version
Hi gurus
I appreciate if someone help out me.
Examples of data
as with a reference
(
Select 'AAA' crt_file, 'A1' scode of union double all the
Select 'AAA' crt_file, 'A2' from dual union all
Select "AAA" crt_file, null of union double all the
Select 'BBB' crt_file, 'A1' scode of union double all the
Select 'BBB' crt_file, 'A2' from dual union all
Select 'BBB' crt_file, the double null)
Select * reference
where crt_file = "AAA".
and nvl (scode, 'x') = nvl (& s_cd, 'x')
;Rule result
I need to extract the result as in & s_cd and it works very well.
but in case where if I put a value zero in & s_cd my query should return all data related to "AAA", something like below:
Result if I pass NULL to & s_cd that then it shows all the results
CRT_FILE, SCODE
AAA A1
AAA A2
AAA
Concerning
Mitt
as with a reference
(
Select 'AAA' crt_file, 'A1' scode of union double all the
Select 'AAA' crt_file, 'A2' from dual union all
Select "AAA" crt_file, null of union double all the
Select 'BBB' crt_file, 'A1' scode of union double all the
Select 'BBB' crt_file, 'A2' from dual union all
Select 'BBB' crt_file, the double null
)
Select * reference
where crt_file = "AAA".
and (scode = & s_cd and & s_cd is null)
-
Hi I have the code what value of query of database, the use case is the user enter the value as 1,01,11 in the database, but when the user enters the value in the xml file may not enter 11,01,12 in the database there are two columns leave say column = 1 test1 and test2 = 2 combination of 12 which is the value of the use will be xml, but sometimes use can enter 04 = test1 test2 = 00 column how I approach this
I called myself map with crdind, crdpos1, cardpos2 as the primary key of table column
using can enter the value that
crdind = 1
crdpos1 = 5
crdpos2 = 3
inactivedate = 2013-05-24
activedate = null
another line
crdind = 1
crdpos1 = 5
crdpos2 = 5
inactivedate = 2013-05-24
activedate = null
another line
crdind = 6
crdpos1 = 02
crdpos2 = 00
inactivedate = 2013-05-24
activedate = null
the rule says that if you enter a number in the crdpos1 example 2 you must enter the value in crdpos2 it can be any number 1-9 but if you enter crdpos1 crdpos2 is 00 00-09
the challenge I
is to query this value after they entered
I have the xml file that got crdpos of land use enter 15 which is the combination of colunm crdpos1 = 1 and crdpos2 = 5
How do I hit the crdpos value and got and able to query in the database in two columns of storage
something like
Select inactivedate from the map
where crdind = '1 ' ".
and crdpos1 = '5'
and crdpos2 = "3"
but my problem is crdpos1 maybe 05 and crdpos2 00
How can I have one where the clues that return values in both cases based on what the user enters
am in oracle 11g release 2
I posted the request as below:
SELECT *.
CARD
WHERE crdpos1 = CASE WHEN: inp1 = '0' THEN: inp1. : ELSE inp2: inp1 END
AND crdpos2 = CASE WHEN: inp1 = '0' THEN '00' ELSE: inp2.
To run Java, replace all occurrences of the bind variables (: inp1,: inp2) with? in the above query example
SELECT *.
CARD
WHERE crdpos1 = BOX WHEN? = '0' THEN? ? ON THE OTHER? END
AND crdpos2 = BOX WHEN? = '0' THEN '00' ELSE? END;
In Java, I guess you must be passing two values. If you the user enter '01', you will pass two values, one is '0', and other is 1' i.e. after splitting from the entrance
Now, in the query, the first question mark refers to inp1, the statement should be:
ps_getValue.SetString (1, sValue1);
The second question mark also refers to inp1, so the statement should be:
ps_getValue.SetString (2, sValue1);
Given that the third question mark relates to inp2, the statement should be:
ps_getValue.SetString (3, sValue2);
and so on...
Maybe you are looking for
-
Second Airport Extreme in Bridge mode, ethernet ports does not
I have two routers, I want to use. The first is a time Capsule (old model 2 TB) connected to a single cable modem. The second is an Airport Extreme (also a little older, the 'flat' last body model until they began to sell towers). Both have the 7.6.4
-
D530 Convertible: video update for Win10
I want to update my video card to be compatible for Windows 10. Is there a compatible with my computer and Windows 10 video card?
-
the cartridge with the bowtie icon has no configuration of Word under number of cartridge as the other cartridges, which is why the message on the printer screen says "use the provided INSTALLATION with your printer cartridges"? I already took each c
-
While downloading my pictures from my camera I clicked on a spin on one of them before copying, and it disappeared, where can I find it?
-
Can I transfer Xbox to a Microsoft Account different live accounts?
My original Microsoft account has been blocked or pirate, is there a way I can transfer my Xbox Live account to my Microsoft account without access to the other?