Distinct var1, var2
what is a syntax to do a count on distinct?
ie.
select
count(
distinct (col1, col2)
from myTbl;
Hi,
COUNT can take only one argument.
If you can combine you varuiables into one argument, you can do something like this:
SELECT COUNT (DISTINCT deptno || '/' || job)
FROM scott.emp;This assumes that the magic character '/' never appears in one of the columns.
Another approach is tio use nested aggregate functions, and GROUP BY the columns:
SELECT COUNT (COUNT (*))
FROM scott.emp
GROUP BY deptno, job
;You don't have to know anything about the values, and the data types don't matter.
Similar Messages
-
Select *, rowid into var1, var2 from...
Hello,
as mentioned in the subject, I want to do the following in plsql:
var1 table%rowtype;
var2 rowid;
select *, rowid into var1, var2 from table where ...;
So this is not possible yet, what else can I do instead as I ...
1. don't want to split one select statement into two.
2. don't know the columns of the table at compile time.
3. would like to use the rowtype, if possible.
Any ideas?
Thanx a lot
MatthiasIf you do not know the columns at compile-time then how is your update-statement working? Is that getting generated dynamically too? And are your updating all the columns in the table?
PS: Btw, you can declare a cursor and have a %rowtype variable based on that. Like this:
declare
cursor c1
is
select t.*,
t.rowid
from table1 t
r_cursor c1%rowtype;
begin
for r_cursor in c1
loop
dbms_output.put_line ( 'Col2: [' || r_cursor.col2 || ']' );
update table1
set col2 = r_cursor.col2 + 10
where table1.rowid = r_cursor.rowid
end loop;
end;
/ -
To get data from diff tables.
Hello,
I am using obiee 11g.
Would like to know the best approach.
I have 2 tables.TableA and TableB which are just not related with each other.
TableA->ColA1,ColA2,ColA3.
TableB->ColB1,ColB2,ColB3.
Now i want to have one prompt with 2 values.
Prompt1 ->value1 and value2 (variable prompt with 2 custom values)
Now
The report i want is if the prompt value is value1->then i need to display values count(distinct(ColA1)) from TableA.
if the prompt value is value2->then i need to display values count(distinct(ColB1)) from TableB.
If the user selects value1 and value2 both then the user should see like sum(count(distinct(colA1))+count(distinct(colB1))) in the report.
How should i do this?
Is this possible to do this in one report itself in anyway?Or do i need to create multiple reports to achieve this?
Any help????
Thanks
Edited by: user123 on Dec 16, 2011 10:36 AMHi,
Create a session init block with two session variables as target as shown
Init block query : select 'dummy','dummy' from dual
Target variables : var1,var2(both having default values also as dummy)
In your prompt definitions set the variable type as "Request variable" and names of the request variables as var1,var2(so that values passed via prompts will take precedence over values existing in session variables)
Now create a column in your report with below formula...
COUNT(DISTINCT CASE WHEN VALUEOF(NQ_SESSION.var1)='dummy' THEN NULL ELSE 1 END) + COUNT(DISTINCT CASE WHEN VALUEOF(NQ_SESSION.var2)='dummy' THEN NULL ELSE 1 END)
Instead of 1 in else case use the column which you want to count. This will work your 3 cases in a single report.
Note: I have tried using "presentation variable" instead of "request variable" assuming same logic should work. For some reason i am always getting required column value as 0(even after trying cast,ifnull etc functions) in table view irrespective of the value selected in prompt. But at the same time i am able to see the selected values in narrative view. Let me know if you are able to identify the mistake i am doing.
Regards,
Rajendra -
Show something different insted of "no rows selected"
My aim is quite simple. Show values from var1, var2 and var3 if count(*) is bigger that 0 and show empty strings ' ' where there is no values with meet a condition. I try do this on several ways. Actually my query looks like this below:
WITH cntct AS
(select CONTACT_NAME as var1, LAST_NAME as var2, FIRST_NAME as var3, CONTACT_PHONE as P from dmo.contact_view)
select distinct decode(cnt.cntall,0,'',ct.var1) as var1, decode(cnt.cntall,0,'',ct.var2) as var2, decode(cnt.cntall,0,'',ct.var3) as var3, ct.P as P from
(select count(*) as cntall from cntct) cnt, cntct ct where P = 'not existing value';Can you provide me some idea, what to change to show ' ' if P will be not existing value?Hi,
lesak wrote:
Of course, you're right. So let's start from begining. My Oracle version is 11.2.0.1.
And what I'm trying to say is that a query from below works great after your remarks:
WITH cntct AS
(select CONTACT_NAME as var1, LAST_NAME as var2, FIRST_NAME as var3, CONTACT_PHONE as P from dmo.contact_view)
select distinct decode(cnt.cntall,0,'',ct.var1) as var1, decode(cnt.cntall,0,'',ct.var2) as var2, decode(cnt.cntall,0,'',ct.var3) as var3, ct.P as P from
(select count(*) as cntall from cntct) cnt left outer join cntct ct on ct.P = 'not existing value';But, when I'm trying to create a view base on that query, Oracle qives me such error:
SQL> CREATE OR REPLACE FORCE VIEW some_view AS
2 WITH cntct AS
3 (select CONTACT_NAME as var1, LAST_NAME as var2, FIRST_NAME as var3, CONTACT_PHONE as P from dmo.contact_view)
4 select distinct decode(cnt.cntall,0,'',ct.var1) as var1, decode(cnt.cntall,0,'',ct.var2) as var2, decode(cnt.cntall,0,'',ct.var3) as var3, ct.P as P from
5 (select count(*) as cntall from cntct) cnt left outer join cntct ct;
(select count(*) as cntall from cntct) cnt left outer join cntct ct
ERROR at line 5:
ORA-00905: missing keyword
If you don't post CREATE TABLE and INSERT statements for contact_view, or use a commonly available table, (such as scciott.emp) in place of contact_view, then I can't reproduce the problem. If contact_view really is a view, you can pretend it's a table, and post CREATE TABLE and INSERT statements that mimic the contents of your real contact_view. Post some sample data for contact_view, and what you want some_view to contain given that data.
I suspect you're getting an error becuase there is jo join condition after the column alias ct at the end of line 5.
I need to create that view, because my final query should look like:
select * from some_view where P = 'existing or not existing value';
If that's your query, then it will return 0 rows (and NOT 1 row containing all NULLs) if P is never equal to the given value. If you want to query table y, and get a row of all NULLs when condition c is never true, then use:
SELECT y.*
FROM x
LEFT OUTER JOIN y ON c
;where x is an table, view or sub-query that contains exactly 1 row.
Are you trying to create a view based on a parameter (e.g., :target_p := 'existing or not existing value')? Please give a concrete example of what you're trying to do. -
Nececito ayuda para desautorisar un equipo de mi cuenta de itunes
necesito ayuda para desautorisar un equiupo de la cuentya de Itunes
ya no tengo acceso alequipo pues fue destruidoHola
Bueno, te explicare lo esencial del SP_TN
Cada transaccion en SAP B1 tiene un ID unico, como la huella digital, a esto en SAP B1 se le conoce como ObjectType, abreviado ObjType, por ejemplo el de la factura de clientes es 13, factura proveedores 18, y asi hay bastantes.
Para saber el tipo de objeto de un docuemento, hay que ejecutar una query simple
SELECT DISTINCT ObjType
FROM TABLA -- vas cambiando la tabla para saber el de cada documento
Ahora bien, existen 5 tipos de transacciones en SAP B1
(A)dd, (U)pdate, (D)elete, (C)ancel, C(L)ose
Para comenzar una validacion debes declarar primero que vas a validar
IF @ObjectType = '' AND @TransactionType IN ('') -- entre las comillas se colocan los parametros para empezar la validacion
BEGIN
Ejemplo
IF @ObjectType = '13' AND @TransactionType IN ('A','U') --con esto cada vez que se cree o actualize una factura de clientes se ejecutara la validacion A= ADD(añadir) U= UPDATE(actualizar)
BEGIN -- aqui comienza mi validacion, se declaran los valores a comparar y se hace la comparacion
@declare var1 int
select @var1 = X
@declare var2 int
select @var2 = X
IF @var1 = @var2
BEGIN
SET @error = 101 --Nº error del usuario, debe ser distinto en cada validacion
SET @error_message = 'HOLA' --mensaje que aparecera al cumplirse la validacion
END --cierre del 1º begin
END --cierre 2º begin
y con esto termina la validacion, con un poco mas de conocimientos de las tablas y campos de SAP B1 podras hacer validaciones mas complejas
Espero te sirva
Slds
Edited by: Floyola on Mar 24, 2011 5:17 PM -
Hi,
I have an SP as follows?
CREATE OR REPLACE PROCEDURE p_temp (
in_rc IN VARCHAR2,
out_table OUT sys_refcursor
IS
BEGIN
OPEN out_table FOR
SELECT DISTINCT rcs.rc, rcs.description AS rc_description
FROM ucweb.rcs
END p_temp;
I wanted to view the various values of column rc obtained from the cursor in TOAD.
how should I write my PL/SQL block to view this O/p.
I had done this few years back, but not remebering now ( did something like fetch cur into ........then cur.rc....somthing like that.......just cant remember)
Please help me rgdng this
P.S. ( need the o/p in toad and not sql*plus)
Regds
sHi,
You will have to write a PL/SQL block which will FETCH the cursor contents and then you can print like this.
BEGIN
LOOP
FETCH ref_cur_var INTO var1,var2;
EXIT WHEN ref_cur_var%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(var1||var2);
END LOOP;
END;
Note: Run this block in toad in PL/SQL window or as a script.
Regards -
I have some doubts/questions .
What is the difference between open and closed cursor?
Are library cache locks same as parse locks?
What is the difference between latch and mutex?
I would be grateful if experts could answer these questions.
RegardsAlmost correct. The terminology is however nor correct.
Simplistically:
The SQL engine receives a SQL. It attempts a soft parse first. This means looking for an existing cursor in the Shared Pool with the same SQL. This existing cursor can be in use by other sessions. It does not matter - if that cursor is in used (opend by other sessions), or not. It may not be in use at all and simply sitting there in the cache. If such a cursor is found, it is used for that session's SQL - and that session gets a cursor handle (reference/pointer) to that existing cursor.
If the SQL engine does not find an existing cursor to use, it needs to create a brand new cursor in the Shared Pool. This is a hard parse. Again, the session receives a cursor handle for that new cursor created.
And that is it.
You now need to decide how to use that cursor handle. The cursor itself is a program. You have a handle to execute that cursor program. Via its bind interface you can input data to this cursor program. Then execute it and receive (fetch) output of that cursor program.
So the ideal is to re-use the cursor handle again and again.
Basic example: the following is not optimal as the same cursor is opened and closed, opened and closed, for each read from the file. A lot of soft parsing results.
while not-eof( filehandle ) // read data from a file
read file data into var1, var2
open cursor for 'insert into testtab values( :1, :2)' // create a cursor
bind cursor :1 = var, :2 = var2 // bind values to cursor (for insert)
exec cursor // do SQL insert
close cursor
end whileThis is a lot better. A single cursor is used and executed again and again:
open cursor for 'insert into testtab values( :1, :2)' // create a cursor
while not-eof( filehandle ) // read data from a file
read file data into var1, var2
bind cursor :1 = var, :2 = var2 // bind values to cursor (for insert)
exec cursor // do SQL insert
end while
close cursor In this case a single soft/hard parse - and the client uses that cursor handle to execute that cursor (insert data) program again and again. -
Compilation error while calling static method from another class
Hi,
I am new to Java Programming. I have written two class files Dummy1 and Dummy2.java in the same package Test.
In Dummy1.java I have declared a static final variable and a static method as you can see it below.
package Test;
import java.io.*;
public class Dummy1
public static final int var1= 10;
public static int varDisp(int var2)
return(var1+var2);
This is program is compiling fine.
I have called the static method varDisp from the class Dummy2 and it is as follows
package Test;
import java.io.*;
public class Dummy2
public int var3=15;
public int test=0;
test+=Dummy1.varDisp(var3);
and when i compile Dummy2.java, there is a compilation error <identifier > expected.
Please help me in this program.public class Dummy2
public int var3=15;
public int test=0;
test+=Dummy1.varDisp(var3);
}test+=Dummy1.varDisplay(var3);
must be in a method, it cannot just be out somewhere in the class! -
Date and Time in Sender File Adapter Target Directory
Hi there,
is there a way of using Date and Time from XI to the Target Directory naming? To use variable substitution some fields of the message had to contain that date and time information, which is not our case.
For filename you can use "add time stamp" option, but and for target directory?
Thanks and regards,
Henrique.> <i>Do you have further information on how to perform
> this with shell commands?</i>
> >> You need to write a shell script. This script will
> add the date/time stamp into the folder in the target
> system. This shell script is executed from the File
> adapter. So once the file is written into the target
> directory, then it will rename the directory.
Hi there, Moorthy
We've tried to write that shell script that you mentioned, but now we have a few doubts on how to make it create the proper directory.
In the file adapter, my target directory is "/%var1%/%var2%/", where %var1% and %var2% are variable substitutions, referencing data which comes from the payload. Now, I need the shell script to append "/<Year>/<Month>/" in the target directory. But where to archive the script? If it stays in the root directory, than how to make it create "/<Year>/<Month>/" folders inside a directory which is variable (/%var1%/%var2%/)?
Is there a way of passing %var1% and %var2% as parameters for the shell script?
Thanks a lot,
Henrique. -
Query in Select query operation
Please excuse me for posting this again.
I'm stuck up with this for 3 days. Lenghty post pls do read and help me.
How is the select query going to be changed in the SAP so that the original database behind it understands it. I want to know the operation of IN operation in where clause where in we can use ranges.
I'm asking this because I'm facing a problem using Native SQL.
Query is like this:
EXEC SQl.
OPEN C1 for
SELECT field1 from table@domain where field2 IN :ABAP_VAR.
ENDEXEC.
EXEC SQL.
FETCH C1 NEXT INTO :VAR1 , :VAR2
ENDEXEC.
Oracle usually recognises this statement IN ( '2222' , '3658' , '6895' )
But here this field that is build dynamically like this is not recognising them as seperate fileds but instead it is taking them as a single string and not selecting anything.
But if a single value is passed it is fetching the data into the cursor. And the code is working fine.
Any help in this is highly appreciable."if a in r_range" is is effectively: does the value held in 'a' comply with the values held in range 'r_range'. Ranges can hold NE, patterns etc so this can get quite complex.
You can see that it is very different from the SQL type IN.
If your range hold several values you could unstrip it into a string varaible so that it ended up having a value something like: ( '2222' , '3658' , '6895' ). Not sure if you need the '(' but it would be something like this:
eg,
assuming your range is simple and only holds 'I' and 'EQ' values:
data v_string type string.
loop at r_range.
concatenate v_string '@''' r_range-low '''@' into v_string.
endloop.
REPLACE
ALL OCCURRENCES OF '@'
IN v_string
WITH ' '.
Then you can use:
SELECT field1 from table@domain where field2 IN :v_string. -
Select statement in a for loop
Hi all,
Can a select stmt be used in the body of the for loop/ nested for loop ?
I tries using (even if its very simple for loop) it gives the following error
PL/SQL: ORA-00933: SQL command not properly ended...
code is
DECLARE
CURSOR C1 is select 'Monday' from dual
union all
select 'Tuesday' from dual
union all
select 'Wednesday' from dual
union all
select 'Thursday' from dual
union all
select 'Friday' from dual
union all
select 'Saturday' from dual
union all
select 'Sunday' from dual;
type rec_info is record
name varchar2(20),
FNAME varchar2(20),
LNAME varchar2(20)
type ty_info is table of rec_info;
info ty_info;
type rec_abc is record
day varchar2(3000)
type ty_abc is table of rec_abc;
abc ty_abc;
Cursor C2 is
select t.name, u.first_name, u.last_name
from territories t, users u, territories_users tu
where t.ID = tu.TERRITORY_ID
and tu.USER_ID = u.ID ;
BEGIN
OPEN C1;
Loop
FETCH C1 into abc;
EXIT when C1%notfound;
DBMS_OUTPUT.PUT_LINE(abc);
END LOOP;
CLOSE C1;
OPEN C2;
FETCH C2 BULK COLLECT into info;
CLOSE C2;
for i in info.first .. info.last
LOOP
for j in abc.first .. abc.last
LOOP
select --info(i).name, info(i).FNAME, info(i),LNAME,'AM' "AM/PM",
to_char(c.name)||' '||ct.PRIMARY_ADDRESS_CITY||','||ct.PRIMARY_ADDRESS_STATE||','||ct.PRIMARY_ADDRESS_COUNTRY
from
territories t, territories_users tu,
users u, calls_users cu, calls c,
calls_contacts cc, contacts ct
where
tu.TERRITORY_ID = t.id
and t.name = info(i).name
and u.first_name = info(i).FNAME
and u.last_name = info(i).LNAME
and (c.date_start between trim(next_day(sysdate,abc(j).day)) and trim(next_day(sysdate,abc(j).day)))
and tu.USER_ID = u.id
and cu.USER_ID = u.id
and cu.CALL_ID = c.id
and to_char(c.time_start,'hh24') < '12'
and cc.CALL_ID = c.ID
and cc.CONTACT_ID = ct.id
and rownum < 2
END LOOP;
END LOOP;
END;"Can a select stmt be used in the body of the for loop/ nested for loop "
Yes.... but with an INTO part.....
select c1 , c2 , c3 into var1 , var2 , var3 from table1
Sim -
Across row validation in tabular form and across items in row validations.
Hi,
We are upgrading to APEX 4.0.
I need to create a tabular form that will have a start date and an end date. FOr each new row or updated row I need ensure its start date is after the end date of all rows already entered and its end date is after the start date of row being entered. Also that if no end date is entered then no other rows can be found with a null end date.
SO I need across field validations with in a row and across row validattions. That is I need rowset validations as well.
Is it possible to do this with APEX? WHat kind of tabular solution would allow these type of validations. How might these validations be done?Okay, Here's a quick rundown on how to build a manual form using APEX_ITEM and collections. The process goes in 4 steps: gather the data, display the data, update based on user input, then write the changes. Each step requires it's own piece of code, but you can extend this out as far as you want. I have a complex form that has no less than a master table and 4 children I write to based on user input, so this can get as complex as you need. Let me know if anything doesn't make sense.
First, create the basic dataset you are going to work with. This usually includes existing data + empty rows for input. Create a Procedure that fires BEFORE HEADER or AFTER HEADER but definitely BEFORE the first region.
DECLARE
v_id NUMBER;
var1 NUMBER;
var2 NUMBER;
var3 VARCHAR2(10);
var4 VARCHAR2(8);
cursor c_prepop is
select KEY, col1, col2, col3, to_char(col4,'MMDDYYYY')
from table1
where ...;
i NUMBER;
cntr NUMBER := 5; --sets the number of blank rows
BEGIN
OPEN c_prepop;
LOOP
FETCH c_prepop into v_id, var1, var2, var3, var4;
EXIT WHEN c_prepop%NOTFOUND;
APEX_COLLECTION.ADD_MEMBER(
p_collection_name => 'MY_COLLECTION',
p_c001 => v_id, --Primary Key
p_c002 => var1, --Number placeholder
p_c003 => var2, --Number placeholder
p_c004 => var3, --text placeholder
p_c005 => var4 --Date placeholder
END LOOP;
CLOSE c_prepop;
for i in 1..cntr loop
APEX_COLLECTION.ADD_MEMBER(
p_collection_name => 'MY_COLLECTION',
p_c001 => 0, --designates this as a new record
p_c002 => 0, --Number placeholder
p_c003 => 0, --Number placeholder
p_c004 => NULL, --text placeholder
p_c005 => to_char(SYSDATE,'MMDDYYYY') --Date placeholder
end loop;
END;Now I have a collection populated with rows I can use. In this example I have 2 NUMBERS, a TEXT value, and a DATE value stored as text. Collections can't store DATE datatypes, so you have to cast it to text and play with it that way. The reason is because the user is going to see and manipulate text - not a DATE datatype.
Now build the form/report region so your users can see/manipulate the data. Here is a sample query:
SELECT rownum, apex_item.hidden(1, c001), --Key ID
apex_item.text(2, c002, 8, 8) VALUE1,
apex_item.text(3, c003, 3, 3) VALUE2,
apex_item.text(4, c004, 8, 8) VALUE3,
apex_item.date_popup(5, null,c005,'MMDDYYYY',10,10) MY_DATE
FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'MY_COLLECTION'This will be a report just like an SQL report - you're just pulling the data from the collection. You can still apply the nice formatting, naming, sorting, etc. of a standard report. In the report the user will have 3 "text" values and one Date with Date Picker. You can change the format, just make sure to change it in all four procedures.
What is critical to note here are the numbers that come right before the column names. These numbers become identifiers in the array used to capture the data. What APEX does is creates an array of up to 50 items it designates as F01-F50. The F is static, but the number following it corresponds to the number in your report declaration above, ie, F01 will contain the primary key value, F02 will contain the first numeric value, etc. While not strictly necessary, it is good practice to assign these values so you don't have to guess.
One more note: I try to align the c00x values from the columns in the collection with the F0X values in the array to keep myself straight, but they are separate values that do NOT have to match. If you have an application you think might get expanded on, you can leave gaps wherever you want. Keep in mind, however, that you only have 50 array columns to use for data input. That's the limit of the F0X array even though a collection may have up to 1000 values.
Now you need a way to capture user input. I like to create this as a BEFORE COMPUTATIONS/VALIDATIONS procedure that way the user can see what they changed (even if it is wrong). Use the Validations to catch mistakes.
declare
j pls_integer := 0;
begin
for j1 in (
select seq_id from apex_collections
where collection_name = 'MY_COLLECTION'
order by seq_id) loop
j := j+1;
--VAL1 (number)
apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
p_seq=> j1.seq_id,p_attr_number =>2,p_attr_value=>wwv_flow.g_f02(j));
--VAL2 (number)
apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
p_seq=> j1.seq_id,p_attr_number =>3,p_attr_value=>wwv_flow.g_f03(j));
--VAL3 (text)
apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
p_seq=> j1.seq_id,p_attr_number =>4,p_attr_value=>wwv_flow.g_f04(j));
--VAL4 (Date)
apex_collection.update_member_attribute (p_collection_name=> 'MY_COLLECTION',
p_seq=> j1.seq_id,p_attr_number =>5,p_attr_value=>wwv_flow.g_f05(j));
end loop;
end;Clear as mud? Walk through it slowly. The syntax tells APEX which Collection (p_collection_name), then which row (p_seq), then which column/attribute (p_attr_number) to update with which value (wwv_flow.g_f0X(j)). The attribute number is the column number from the collection without the "c" in front (ie c004 in the collection = attribute 4).
The last one is your procedure to write the changes to the Database. This one should be a procedure that fires AFTER COMPUTATIONS AND VALIDATIONS. It uses that hidden KEY value to determine whether the row exists and needs to be updated, or new and needs to be inserted.
declare
begin
--Get records from Collection
for y in (select TO_NUMBER(c001) x_key, TO_NUMBER(c002) x_1,
TO_NUMBER(c003) x_2,
c004 x_3,
TO_DATE(c005,'MMDDYYYY') x_dt
FROM APEX_COLLECTIONS
WHERE COLLECTION_NAME = 'MY_COLLECTION') loop
if y.x_key = 0 then --New record
insert into MY_TABLE (KEY_ID, COL1,
COL2, COL3, COL4, COL5)
values (SEQ_MY_TABLE.nextval, y.x_1,
y.x_2, y.x_3, y.x_4, y.x_dt);
elsif y.x_key > 0 then --Existing record
update MY_TABLE set COL1=y.x_1, COL2=y.x_2,
COL3=y.x_3, COL4=y.x_4, COL5=y.x_dt
where KEY_ID = y.x_key;
else
--THROW ERROR CONDITION
end if;
end loop;
end;Now I usually include something to distinguish the empty new rows from the full new rows, but for simplicity I'm not including it here.
Anyway, this works very well and allows me complete control over what I display on the screen and where all the data goes. I suggest using the APEX forms where you can, but for complex situations, this works nicely. Let me know if you need further clarifications. -
Order of Operations with Parentheses
I have a query that is returning unexpected results. I'm under the impression that when parentheses are included that they override operator precedence. If that is the case, the NOT_EQUAL_CHECK should be the negation of the EQUAL_CHECK, right? Using 10.2.0.4 on an AIX machine.
WITH src AS
(SELECT 'T' AS var1, 'T' AS var2 FROM dual
UNION ALL
SELECT 'T' AS var1, 'F' AS var2 FROM dual
UNION ALL
SELECT 'T' AS var1, NULL AS var2 FROM dual
UNION ALL
SELECT NULL AS var1, 'F' AS var2 FROM dual
UNION ALL
SELECT NULL AS var1, NULL AS var2 FROM dual
SELECT nvl(var1, 'NULL') AS var1,
nvl(var2, 'NULL') as var2 ,
CASE
WHEN((var1 = var2) OR (var1 IS NULL AND var2 IS NULL))
THEN 'T'
ELSE 'F'
END AS equal_check,
CASE
WHEN NOT((var1 = var2) OR (var1 IS NULL AND var2 IS NULL))
THEN 'T'
ELSE 'F'
END AS not_equal_check
FROM src
ORDER BY var1,
var2;
VAR1 VAR2 EQUAL_CHECK NOT_EQUAL_CHECK
NULL F F F
NULL NULL T F
T F F T
T NULL F F
T T T FHi,
Remember how SQL's 3-value logic works.
'T' = NULLis neither TRUE nor FALSE, but rather the 3rd possibility: UNKNOWN.
NOT UNKNOWN is, paradoxically, UNKNOWN.
That is to say, the truth table of NOT is:
X NOT X
TRUE FALSE
FALSE TRUE
UNKNOWN UNKNOWNThe CASE expression
CASE
WHEN <condition_x>
THEN 'T'
ELSE 'F'
ENDreturns 'T' when condition_x evaluates to TRUE, and it returns 'F' in all other events, that is, whether condition_x is FALSE or condition_x is UNKNOWN.
Putting NOT in fron of that condition:
CASE
WHEN NOT <condition_x>
THEN 'T'
ELSE 'F'
ENDchanges what happens when condition_x is either TRUE or FALSE, but it has no effect on the results when condition_x is UNKNOWN.
If you want a CASE expression that is the opposite of equal_check, just swap the values in the THEN and ELSE clauses.
Alternatively, you can negate the condition piece by piece, as shown in the last CASE expression below.
SELECT nvl(var1, 'NULL') AS var1,
nvl(var2, 'NULL') as var2 ,
CASE
WHEN((var1 = var2) OR (var1 IS NULL AND var2 IS NULL))
THEN 'T'
ELSE 'F'
END AS equal_check,
CASE
WHEN((var1 = var2) OR (var1 IS NULL AND var2 IS NULL))
THEN 'F'
ELSE 'T'
END AS swap,
CASE
WHEN LNNVL (var1 = var2)
AND NVL (var1, var2) IS NOT NULL
THEN 'T'
ELSE 'F'
END AS piece_by_piece
FROM src
ORDER BY var1,
var2;Output:
VAR1 VAR2 E S P
NULL F F T T
NULL NULL T F F
T F F T T
T NULL F T T
T T T F FNOT has a similar effect on 3-valued boolean values that multiplying by -1 has on numbers. If you multiply a positive number x by -1, the result will be different than x, and if you mutiply a negative number x by -1 then the result will also be different than x. But if you multiply 0 by -1, the result is still 0.
Edited by: Frank Kulash on May 20, 2010 2:13 PM -
Store values of different data types into single database field
Hi Friends,
I have to store values of different data types(character, numeric, date, time, text, etc) into a single database field(Char 80). Then read the same values and display it into ABAP Webdynpro report.
Appreciate any ideas, examples, suggestions.
Thanks
JBHi,
Try like this:
data: txt1 type string,
var1(1) type c,
var2(1) type n,
var3 like sy-datum,
var4 like sy-uzeit.
parameters: a type c,
b type n,
c like sy-datum,
d like sy-uzeit.
concatenate a b c d into txt1.
write txt1.
var1 = txt1+0(1).
var2 = txt1+1(1).
var3 = txt1+2(8).
var4 = txt1+8(8).
write: / var1,
/ var2,
/ var3,
/ var4.
Regards,
Bhaskar -
Query Stripping not working properly when using variable in the report
We have issue with WEBI document that have query stripping enable.
Once the query stripping enabled there is no data return in the report.
We have investigate on the problem, the query stripping function are notable to retrieve objects that indirectly used in the report
as we have
many variable in the reports.
Ex.
Var1 = object1 + object2
Var2 = Object3 + Object4
Var3 = Var1 + Var2
Var4 = Object1 + Object2 + Object3 + Object4
If we use only Var3 in the report, the object1,2,3,and 4 will not be
retrieve.
But if we are using Var4 in the report, the object1,2,3,and 4 will be
retrieve properly.
Please let me know is it a by-design behavior, if yes please share points on itHi Amit,
Thank you for response, however i already had alook on that VIdeo and it tells us about the basic enabling of query stripping.
But my question is when we have a Variable in a report which is dependent on the other two variables it gives me #error so is it by design or not.
Regards,
Abhinav
Maybe you are looking for
-
Iphone 3gs battery-my story-please help
hi all i expierenced issues with my iphone 3gs since iOS 4.1,my battery drain was terrible but after iOS 4.2 i thought it becomes better but no,after 2 weeks i observed what my battery is draining sometimes very fast-for example when i charge it yest
-
Slow Moving/Dead Stock Report
Hi Guys BEsides T.COdes MC46 and MC50 what other reports that are available on SAP to give the same information and also their Current Stock Balances Vishnu
-
Hello all, I have a question regarding Activity Report iView. We are using two portals. The support package level is SPS11 patch 6. The activity Report iView only works on one of the portals correctly. The data are displayed well. But the same iView
-
I cannot print any of my old pdf files. there is no option anywhere.
i have a new computer with windows 8 but not a touch screen and i cannot find a way to print any pdf documents
-
Ignore stroke weight in the transform box
Hi, I'd like to know how to ignore the stroke weight of a shape in the transform box. In other terms, to only consider the surface. For example, I trace a square with no stroke, and measures 100mm. When I add a 1pt stroke on it, I would still like th