Help with a case function
Hello
I want to create a function box where column2 is based on the value of Column1.
For example, the table below
On the underside, I would ask something like
Select status, description, l3_days, (case when status = 'Open' and DEV_DAYS = null THEN L3_DAYS = 'LOGIN_DATE-SYSDATE' WHAT status = 'open' and DEV_DAYS! = NULL THEN DEV_DAYS = L3_DAYS ELSE LOGIN_DATE-L3_DAYS-SYSDATE, DEV_DAYS END)
Not sure so clearly. Basically, I want to L3_DAYS and DEV_DAYS to be updated automatically based on the login_date. I plan to add a DEV_START_DATE column, which would facilitate the calculation of DEV_DAYS
In any case I want to know how to write a case function, where denotes Column1 Column2?
Thank you
There are two CASE statements like this
select status , description , case when status = 'Open' and dev_days is null then LOGIN_DATE-SYSDATE else l3_days end l3_days , case when status = 'Open' and dev_days is not null then LOGIN_DATE-L3_DAYS-SYSDATE else dev_days end dev_days
If this isn't what you are looking for you need to explain your best condition. Provide a CREATE TABLE script and INSERT a TABLE for examples of data and provide a few example expected output.
Also please read Re: 2. How can I ask a question on the forums?
Tags: Database
Similar Questions
-
Newbie need help with string concatenation function.
I'm totally new to LabView and am trying to work on a project that someone worked in the past. I came to a string function concatenated on one of the existing provisions and only seen on some entries of the string function has an order of 'rel' and 'g '. I don't know if it's a common command or what it is. This is VI is that it requires a user to enter a base dimension (x-axis starting point and end point) and executes the steps in the sample desired within the "point of departure" and "end point". "a3" is the name of the x-axis. but I'm not sure of the meaning 'rel' and 'g '. I posted part of the diagram. Any help would be appreciated. Thank you!
This isn't a question of LabVIEW, but very specific to the device connected to the other end of the serial port. Do you have any documentation for it?
Basically, the program needs form a consiting of command of a delimiter character, value and end of key word, etc. for example.
Who wrote this program. It seems too complex and convoluted. Under certain conditions, it seems to send two commands at the same time, and there is no way to determine the order in which they run. Maybe it doesn't matter, but maybe it does. Most likely, what you need is a single structure dealing with a case for each condition and a unique series in the end writing. You can reach the actual program? There are also a lot of duplicate code. What is the purpose of the operations 1 x? Is this a Subvi?
-
Help with packages and functions that it
Hello, I need help with the package.
I have two tables of the employee base (id, firstname, lastname, etc..) T1 and T2.
What I need, it's a package and two features inside. First function reads the data from T1 and passes to the second function, where second function reads data from T2 and concatenates the data just read with data from function1 and data T1 + T2 function2 goes on the main program that displays this data.
So far, I have:
- get_T1_emp function seems to be quite beautiful. At least it works separatelycreate or replace type emp_type as object (id number, firstname varchar(20), lastname varchar(20), salary number(9,2)); create or replace type emp_type_table as table of emp_type; create or replace package my_package is emp_table emp_type_table:= emp_type_table(); -- *not sure if this line is correct* function get_T1_emp return emp_type_table; function get_T2_emp (T1_emp in emp_type_table) return emp_type_table; end my_package; -- *confusion begins* create or replace package body my_package as function get_T1_emp return emp_type_table as emp_table emp_type_table:= emp_type_table(); begin for i in (select * from T1) loop emp_table.extend; emp_table(emp_table.count):= (emp_type(i.id, i.firstname, i.lastname, i.salary)); end loop; return emp_table; end get_T1_emp;
So basically I don't know about my tax package.function get_T2_emp (T1_emp in emp_type_table) return emp_type_table emp_table emp_type_table:= emp_type_table(); begin for i in (select * from T2) loop T1_emp.extend; T1_emp(T1_emp.count):= (emp_type(i.id, i.firstname, i.lastname, i.salary)); end loop; return T1_emp; end get_T2_emp; end my_package; DECLARE v_Return emp_type_table; v_Return2 emp_type_table; BEGIN v_Return := get_T1_emp; v_Return2 := get_T2_emp(v_Return); for i in 1..2 loop DBMS_OUTPUT.PUT_LINE(v_Return2(i).id || ', ' || v_Return2(i).firstname || ', ' || v_Return2(i).lastname || ', ' || v_Return2(i).salary || 'EUR'); end loop; END;
Most important, I don't know how to write the get_T2_emp function. And also not very sure of my main function. Please can someone help my with my problem
Published by: dber November 6, 2011 21:22
Published by: dber November 6, 2011 23:38 addedHello
Here you go
SQL> DROP TABLE t1; Table dropped. SQL> DROP TABLE t2; Table dropped. SQL> CREATE TABLE t1 (id NUMBER, 2 firstname VARCHAR2(100), 3 lastname VARCHAR2(100) ); Table created. SQL> CREATE TABLE t2 (id NUMBER, 2 firstname VARCHAR2(100), 3 lastname VARCHAR2(100) ); Table created. SQL> INSERT INTO t1 (SELECT 1,'SURI','DAMA' FROM dual 2 UNION ALL 3 SELECT 2,'SRINU','DAMA' FROM dual); 2 rows created. SQL> INSERT INTO t2 (SELECT 3,'ABC','XYZ' FROM dual 2 UNION ALL 3 SELECT 4,'DEF','PQR' FROM dual); 2 rows created.
Package code
SQL> CREATE OR REPLACE PACKAGE test_array_pkg 2 AS 3 TYPE test_array1 IS TABLE OF t1%rowtype INDEX BY PLS_INTEGER; 4 TYPE test_array2 IS TABLE OF t2%rowtype INDEX BY PLS_INTEGER; 5 6 FUNCTION get_t1 RETURN test_array1; 7 FUNCTION get_t2(p_t1 IN test_array1) 8 RETURN test_array2; 9 10 END test_array_pkg; 11 / Package created.
Package body
SQL> CREATE OR REPLACE PACKAGE BODY test_array_pkg 2 AS 3 t1_array1 test_array1; 4 t2_array2 test_array2; 5 6 FUNCTION get_t1 7 RETURN test_array1 8 IS 9 10 n NUMBER :=0; 11 12 BEGIN 13 14 FOR i IN (SELECT * FROM t1) 15 LOOP 16 17 t1_array1(n).id:= i.id; 18 t1_array1(n).firstname := i.firstname; 19 t1_array1(n).lastname := i.lastname; 20 21 n:=n+1; 22 23 END LOOP; 24 25 RETURN t1_array1; 26 27 END get_t1; 28 29 FUNCTION get_t2(p_t1 IN test_array1) 30 RETURN test_array2 31 IS 32 33 n NUMBER:=0; 34 35 BEGIN 36 37 FOR i IN p_t1.FIRST..p_t1.LAST 38 LOOP 39 40 t2_array2(n).id:=p_t1(i).id; 41 t2_array2(n).firstname:= p_t1(i).firstname; 42 t2_array2(n).lastname := p_t1(i).lastname; 43 44 n:=n+1; 45 46 END LOOP; 47 48 FOR i IN (SELECT * FROM t2) 49 LOOP 50 51 t2_array2(n).id:=i.id; 52 t2_array2(n).firstname:= i.firstname; 53 t2_array2(n).lastname := i.lastname; 54 55 n:=n+1; 56 57 END LOOP; 58 59 RETURN t2_array2; 60 61 END get_t2; 62 63 64 END test_array_pkg; 65 / Package body created.
Main script
SQL> declare 2 3 t1_result test_array_pkg.test_array1; 4 t2_result test_array_pkg.test_array2; 5 6 begin 7 8 t1_result:= test_array_pkg.get_t1; 9 t2_result:= test_array_pkg.get_t2(t1_result); 10 11 FOR i IN t2_result.first..t2_result.last 12 LOOP 13 14 dbms_output.put_line(t2_result(i).id||' '||t2_result(i).firstname||' '||t2_result(i).lastname); 15 16 END LOOP; 17 18 end; 19 / 1 SURI DAMA 2 SRINU DAMA 3 ABC XYZ 4 DEF PQR PL/SQL procedure successfully completed.
-
Help with JDBC stored functions
Hello.. Im having problems with my stored functions (java oracle), where I create the functions but then im I call them, it does not return any value (nothing happens after that I called my function). Can someone help me?
Here's how to create the registered function:
/************************************************** ****************/
create or replace FUNCTION insert_client_func (a_client_name IN CLIENTS.client_name%TYPE)
RETURN VARCHAR2
IS
BEGIN
INSERT INTO CUSTOMERS (client_name)
VALUES (a_client_name);
Return a_client_name;
END;
/************************************************** *****************/
Heres how I call it:
/************************************************** *****************/
name = "'" + name + "'";
Command string = "{call insert_client_func("+name+")}";
try {}
String url="jdbcracle:thin:@localhost:1521e; »
this.dbConnection = DriverManager.getConnection (url, "bd2009", "bd2009");
System.out.println (Command);
This.callstmt = This.DbConnection.prepareCall (command d);
this.callstmt.registerOutParameter (1, Types.VARCHAR);
this.callstmt.executeUpdate ();
String simpleArray = this.callstmt.getString (1);
System.out.println (simpleArray);
this.dbConnection.commit ();
This.callstmt.Close ();
this.dbConnection.close ();
}
/************************************************** *****************/The syntax of your call is incorrect. For functions, it should be
"{ ? = call insert_client_func (?)} »
You can also use the syntax of PL/SQL
' BEGIN?: = insert_client_func (a_client_name =>?); END; »
Then configure your settings
this.callstmt.registerOutParameter (1, Types.VARCHAR);
this.callstmt.setObject(2,); What is the data type of IN_CLIENTS.client_name?
Call the function and retrieve the return value
This.callstmt.Execute ();
String value = this.callstmt.getString (1); -
I need a little help with the INSTR function
Hello everyone,
im still new to pl sql and experienced an issue with the INSTR function. I need to analyze some values of a CLOB containing the xml code and use INSTR to determine the beginning and end of the value, I would like to analyze.
the data I need is in a <!-[CDATA [[Some Text]]]-> block. up to this point, I managed to take the start of the word, but I can't seem to capture the end of the CDATA block. I use this statement:
POS: = INSTR (TO_CHAR (input_clob) [,'] ', pos2 + 6, 1);
but it doesn't have the desired effect. [It seems to sort of go back to the length of the string, while the]-sign is actually in the xml file. my result would look to "Some Text]]--> < xmlxml >... < / xmlxml >...» ». [I tried to escape by writing ' \] "but if I do, the function returns zero and my parsed string is left blank.
Unfortunately I can't use regular expressions, because I work with oracle 9.2i. Anyone know what I'm doing wrong?
Thank you
Edited by: user8719779 the 25.08.2009 02:23with my_tab as (select '
'||chr(10)|| ' ' col1 from dual) -- end of mimicking your data; USE SQL below: select substr(col1, instr(col1, '', 1, 1) - instr(col1, ''||chr(10)|| ' '||chr(10)|| ' '||chr(10)|| 'package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; public class Main extends MovieClip { private var preLoader:PreLoader; private var mainMenu:MainMenu; private var game:Game; public function Main() { preLoader = new PreLoader; addChild(preLoader); preLoader.gotoAndStop(1); addEventListener(Event.ENTER_FRAME, barLoading); } private function barLoading(event:Event):void { var total:Number = stage.loaderInfo.bytesTotal; var loaded:Number = stage.loaderInfo.bytesLoaded; preLoader.loadingBar.scaleX = loaded/total; if (loaded==total) { removeEventListener(Event.ENTER_FRAME, barLoading); preLoader.gotoAndStop(2); preLoader.doneLoading.addEventListener(MouseEvent.CLICK, doneLoading); loaded = null; total = null; } } private function doneLoading(event:MouseEvent):void { preLoader.doneLoading.removeEventListener(MouseEvent.CLICK, doneLoading); mainMenu = new MainMenu; addChild(mainMenu); removeChild(preLoader); } static public function initializeGame():void { game = new Game; removeChild(mainMenu); addChild(game); } } }
MainMenu.as
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; public class MainMenu extends MovieClip { public function MainMenu() { playGameButton.addEventListener(MouseEvent.CLICK, playGameButtonFunction); instructionsButton.addEventListener(MouseEvent.CLICK, instructionsButtonFunction); creditsButton.addEventListener(MouseEvent.CLICK, creditsButtonFunction); } private function playGameButtonFunction(event:MouseEvent):void { playGameButton.removeEventListener(MouseEvent.CLICK, playGameButtonFunction); instructionsButton.removeEventListener(MouseEvent.CLICK, instructionsButtonFunction); creditsButton.removeEventListener(MouseEvent.CLICK, creditsButtonFunction); } private function instructionsButtonFunction(event:MouseEvent):void { instructionsButton.removeEventListener(MouseEvent.CLICK, instructionsButtonFunction); trace("instructions"); } private function creditsButtonFunction(event:MouseEvent):void { creditsButton.removeEventListener(MouseEvent.CLICK, creditsButtonFunction); trace("credits"); } } }
In addition, anny comments on my coding habits and how to improve are welcome.
in the hand
var preloader: Preloader = new Preloader (();)
preloader.addEventListener ("preloadCompleted", preloadCompletedF);
in the Preloader, loading complete:
this.dispatchEvent (new Event ("preloadCompleted"));
-
help with call library function node
I have problem with node function call library that I try to use velleman k8061 dll file to get this working labview
all I'm trying to get the same problem
but I chose one to explain it
SetDigitalChannel
Syntax
PROCEDURE SetDigitalChannel (CardAddress: Longint;) Channel: Longint);
Parameters
CardAddress: The address of the previously opened card.
Channel: Value between 1 and 8, which corresponds to the output channel to be resolved.
Description
The selected digital output channel is activated.
Example of
BEGIN
SetDigitalChannel (0, 1);now, when I try to call the function of library in k8061.dll node and set up 2 a card address and one for the channel
address of card type: type numeric & statistics: signed 32 bit intger
channel type: numeric type & data: signed 32 bit intger
function prototype
void setdigitalchannel (int32_t, intg32_t channel address);
I also configure error call library function node checking up
now that I run it, I get error 1517 produced and tell me this mismatch between the calling conventions?
problem solved
thanx
-
Need help with the analytical function select maximum and minimum of the results of the column
Hey there OTN.
I have an interesting application that I was hoping you would be able to help me with. I have a requirement to conditionally select the max and min of a column in bi-editor and since my editor works from an OBIEE analysis, I need store MAX and MIN of the column values in separate columns to match with. See the example below. You will notice that there are 4 stores including today's sales. I must have OBIEE through all the results of the column for sales, then choose the max of the dataset object. I can't use MAX here because he will choose the MAX of the line which will return only sales of this line. Instead, one must analyze all sales results and choose the appropriate column. Any idea on how to do this in OBIEE/publisher? Or is this not possible.
Day Store Sales Sales of MAX Sales MIN 05/11/15 Store 1 5000 8000 1000 05/11/15 Store 2 7500 8000 1000 05/11/15 Store 3 1000 8000 1000 05/11/15 Store 4 8000 8000 1000 I'm waiting for your answers. Thanks in advance!
PS: I will always mark messages that are useful and eventually mark it as correct answer if we come to a resolution!
See you soon.
You can't do the same thing with RANK ("dirty")?
Rank ("dirty") = 1: the max value in the result of sales
RANK (-1 * "Sales") = 1: the min in the result of sales value
I guess you can and then format the cells based on these values, where a value of 1 is the max or min according to the RANKING formula you used...
-
Need help with the listagg function
Hi all
I try to use Listagg in the query below, but not able to get the answer. It is throwing an error message saying ORA-00979: not a GROUP BY expression.
If I try to remove the Group By function and run the query, I get the following error ORA-00937: not a function of simple-group.
Help, please.
Select Distinct V.User_X, V.Original_Request_Id, (V.Support_Group_Name, ',') listagg Group (order of V.Support_group_name) as Group1,
T.Individualassignedto, T.Status, T.Groupassignedto, T.Ticketcategory, T.Tickettype, T.orgcompany, T.submitter,
T.Orgassignedto, T.Urgency
Display V
INNER JOIN K_TICKET T ON T.TICKETNUMBER = V.ORIGINAL_REQUEST_ID
V.Original_Request_ID group
Because you use a GROUP BY, you don't need SEPARATE.
All the columns you are not aggregate (list) should be in the GROUP BY.
-
Need help with the analytic function
I want to get the highest employee details and the 2nd highest employee for a particular service. But also the Department should have more than 1 employee.
I tried the query and it gave me the correct results. But I wonder if there is another solution than to use the subquery.
Here is the table and the query result:
with t as ( select 1 emp_id,3 mgr_id,'Rajesh' emp_name,3999 salary,677 bonus,'HR' dpt_nme from dual union select 2 ,3 ,'Gangz',4500,800,'Finance' from dual union select 3 ,4 ,'Sid',8000,12000,'IT' from dual union select 4 ,null,'Ram',5000,677,'HR' from dual union select 5 ,4,'Shyam',6000,677,'IT' from dual union select 6 ,4 ,'Ravi',9000,12000,'IT' from dual ) select * from (select emp_id, mgr_id, emp_name, dpt_nme, salary, row_number() over (partition by dpt_nme order by salary desc) rn from t where dpt_nme in (select dpt_nme from t group by dpt_nme having count(*) > 1)) where rn < 3
Hello
You need a subquery, but you don't need more than that.
Here's a way to eliminate the additional subquery:WITH got_analytics AS ( SELECT emp_id, mgr_id, emp_name, dpt_nme, salary , ROW_NUMBER () OVER ( PARTITION BY dpt_nme ORDER BY salary DESC ) AS rn , COUNT (*) OVER ( PARTITION BY dpt_nme ) AS dpt_cnt FROM t ) SELECT emp_id, mgr_id, emp_name, dpt_nme, salary , rn FROM got_analytics WHERE rn < 3 AND dpt_cnt > 1 ;
Analytical functions are calculated after the clause WHERE is applied. Since we need to use the results of the analytical ROW_NUMBER function in a WHERE clause, which means that we have to calculate ROW_NUMBER in a subquery and use the results in the WHERE clause of the main query. We can call the COUNT function analytical in the same auxiliary request and use the results in the same WHERE clause of the main query.
Would what results you if there is a link for the 2nd highest salary in some Department? For example, if you add this line to your sample data:
select 7 ,3 ,'Sunil',8000,12000,'IT' from dual union
? You can use RANK rather than ROW_NUMBER.
-
Need help with debugging case manipulation statement &; date
Hi people,
Can you get it someone please let me know what I am doing wrong?
Select to_date (23-seven.-10', 'DD-MON-yy') expiry_date,.
TO_DATE (23-sep-09', 'DD-MON-yy') order_date,.
TO_DATE (23-seven.-10', 'DD-MON-yy')-to_date (23-sep-09', 'DD-MON-yy') diff,.
(case diff
When < 365 then 'low '.
When > 365 then 'high '.
other 'similar '.
end)
Double;
ORA-00936: lack of expression
00936 00000 - "missing expression.
* Cause:
* Action:
Error on line: column 5:18
Thanks in advance
rogers42Here you go
WITH temp_tab AS (SELECT to_date('23-sep-09', 'DD-MON-yy') order_date, to_date('23-sep-10', 'DD-MON-yy') -to_date('23-sep-09', 'DD-MON-yy') diff, to_date('23-sep-10', 'DD-MON-yy') expiry_date FROM dual) SELECT( CASE WHEN diff < 365 THEN 'low' WHEN diff > 365 THEN 'high' ELSE 'same' END) FROM temp_tab;
-
Help with some date functions.
I need to write code that allows a person to, at the beginning of the year, to cancel all records that relate to the previous year.
For example, on 05/01/11, all records for the year 2010 should be cancelled by inserting the cancellation_date as the last date of this same year.
So I thought that the best way to proceed would be with this function:
CREATE OR REPLACE FUNCTION TEST2
DATE OF RETURN
AS
v_prior_year tank (4);
v_last_second_string VARCHAR2 (20);
v_last_second_date DATE;
BEGIN
-The year of the SYSDATE extract, convert it to a number, subtract 1, convert that year to a string.
v_prior_year: = TO_CHAR (TO_NUMBER (TO_CHAR (SYSDATE, 'YYYY'))-1);
-Build a string that consists of the last second of the same year.
"v_last_second_string: = ' 31 - DEC - ' | v_prior_year | "235959 ';
-Convert the string to a date.
v_last_second_date: = TO_DATE (v_last_second_string, ' ' MY - DD - YYYY HH24MISS);
RETURN v_last_second_date;
END Test2;
I was wondering if there is a shorter way to do this?
Thank you.TUBBY_TUBBZ?select trunc(sysdate, 'YYYY') - (1/24/60/60) from dual; TRUNC(SYSDATE,'YYYY' -------------------- 31-DEC-2009 11 59:59 1 row selected. Elapsed: 00:00:00.01 TUBBY_TUBBZ?
?
-
Need help with rewrite PLSQL function EVALUATE
Hi all
I'm trying to convert some PLSQL (from Discoverer) in a column of answers and I can't seem to get the correct formula.
The original formula:
MIN (Processed_Date) MORE (SCORE OF Business_Area, product, Serial_No)
I guess that this must be done in an evaluation function, but I can't work on the correct syntax.
This formula:
Evaluate ('MIN (%1) OVER (PARTITION OF 2%, 3%, 4%)) ", Business_Area, Processed_Date, Serial_No, product)
Has generated this error:
[nQSError: 10058] A general error occurred. [nQSError: 22027] Union of incompatible types. (HY000)
I do not know what causes the error, and tried casting explicitly throughout the column, but still getting errors.
I am open to any suggestion.
Thank you.
Published by: jasonr on Dec 14, 2010 09:54Jasonr,
highlighted in bold is the change
Try this EVALUATE ('MIN (%1) OVER (PARTITION OF 2%, 3%, 4%)) AS the DATE, Processed_Date, Business_Area, product, Serial_No)
update if it solved your problem.-bifacts
http://www.obinotes.com
JPublished by: bifacts on December 14, 2010 21:52
-
Need help with the INSTR function
I try to use SUBSTR and INSTR function to parse a variable without breaking to the top of the variable. As you can see that the problem is space, negotiating
How can I enter the number of characters in name only? It lists just to the right of the 1st blank_space.DECLARE blank_space NUMBER(2); full_name VARCHAR2(30) := 'Robert P. Simmons'); first_name VARCHAR2(30); last_name VARCHAR2(30); BEGIN blank_space := INSTR(full_name, ' '); first_name := SUBSTR(full_name, 1, (blank_space -1)); DBMS_OUTPUT.PUT_LINE( 'Your first name is ' || first_name); last_name := SUBSTR(full_name, (blank_space + 1), (LENGTH(full_name) - blank_space)); DBMS_OUTPUT.PUT_LINE( 'You have ' || LENGTH(last_name) || ' characters in your last name!'); END;
Thank youSQL> declare blank_space number (2); full_name varchar2 (30) := 'Robert P. Simmons'; first_name varchar2 (30); last_name varchar2 (30); begin blank_space := instr (full_name, ' '); first_name := substr (full_name, 1, (blank_space - 1)); dbms_output.put_line ('Your first name is ' || first_name); dbms_output.put_line ('You have ' || length (substr (full_name, instr (full_name, ' ', -1) + 1)) || ' characters in your last name!'); end; / Your first name is Robert You have 7 characters in your last name! PL/SQL procedure successfully completed.
-
Need help with the DECODE function
Hello
I try to use by default within the decode service and whenever I get a missing expression. I searched everywhere and can not know what I am doing wrong. Thank you
Select decode (request_id, 0, "no file found", by DEFAULT)select decode (request_id,0,'No files found', request_id)...
Maybe you are looking for
-
DesignJet 750 c: need help to find PL532en
All the links I found driver for PL532en seem to be broken. Can anyone provide a link to the current site, can I download this driver? Thank you Brian
-
Problem with the update of the firmware WRT160N V2 for a PC running XP.
Download of the firmware does not open! He said that it is a system file. I expected a file Zip or exe. file... What is this thing, and I'm I supposed to do with this download?
-
I need to add more memory on my c of the portion partitioned drive.
After partitioning my hard drive into different portions how can I urechi an amount of memory for different players.
-
BlackBerry Smartphones Can BB be hacked?
Hello I'm considering the purchase of a smartphone BB because their improved security features. However, a friend of mine mentioned that a user in his company reported being hacked on a trip. This person said that during his trip, the BB rebooted sev
-
Error of the obex: 192 - Bad Request
Hi guys,. I use to send files to devices supported obex obex When an error occurs, I get no error description, it is always null. following code: ... ClientSession conn = null; try { conn = (ClientSession) Connector.open("btgoep://001060a4ba8a:1;auth