How to compare values in collection.
Hi,
I am using oracle 11g XE, I am doing a validation using bulk collect collection.
DECLARE
TYPE TEM IS TABLE OF VARCHAR2(1000);
EM TEM;
P_MAIL VARCHAR2(1000);
BEGIN
P_MAIL := UPPER('[email protected]');
SELECT EMAIL BULK COLLECT INTO EM FROM
SELECT UPPER(EMAIL_ID) AS EMAIL FROM SONARA_CONSULTANT_DETAILS
UNION
SELECT EMAIL_ID_2 AS EMAIL FROM SONARA_CONSULTANT_DETAILS
) WHERE EMAIL IS NOT NULL;
FOR I IN EM.FIRST..EM.LAST LOOP
IF P_MAIL = EM(I) THEN // Here i am comparing the mail id with collection but it always goes to INVALID
DBMS_OUTPUT.PUT_LINE('VALID');
ELSE
DBMS_OUTPUT.PUT_LINE('INVALID');
END IF;
END LOOP;
END;
} Please suggest me how to do the comparison
Thanks
Sudhir
It seems that you don't compare everywhere in uppercase, so for me this is rather a letter case problem in your string addresses. The following works for me
DECLARE
TYPE TEM IS TABLE OF VARCHAR2(1000);
EM TEM;
P_EMAIL VARCHAR2(1000) := '[email protected]';
BEGIN
WITH SONARA_CONSULTANT_DETAILS AS
SELECT '[email protected]' AS emailAddr FROM DUAL UNION
SELECT '[email protected]' AS emailAddr FROM DUAL UNION
SELECT '[email protected]' AS emailAddr FROM DUAL UNION
SELECT '[email protected]' AS emailAddr FROM DUAL UNION
SELECT '[email protected]' AS emailAddr FROM DUAL UNION
SELECT '[email protected]' AS emailAddr FROM DUAL UNION
SELECT '[email protected]' AS emailAddr FROM DUAL UNION
SELECT '[email protected]' AS emailAddr FROM DUAL
SELECT emailAddr BULK COLLECT INTO EM
FROM SONARA_CONSULTANT_DETAILS;
FOR indx IN EM.FIRST .. EM.LAST
LOOP
IF UPPER(P_EMAIL) = UPPER(EM(indx))
THEN
DBMS_OUTPUT.PUT_LINE('VALID');
ELSE
DBMS_OUTPUT.PUT_LINE('INVALID');
END IF;
END LOOP;
END;
/Which gives me the following result
INVALID
INVALID
INVALID
INVALID
INVALID
INVALID
INVALID
VALID
PL/SQL procedure successfully completed.
SQL> Regards,
Dariyoosh
Similar Messages
-
How to compare values in table control
Hi Experts,
How to compare two values of a field in table control. Like the frist row of feld1 with the second row of field1.
because when ever two values are same i need to display error message that we are entring duplicate entry.
i have been tring for a very log time but not getting any solution for this.
Thanks and Regards,
Ashwin.you need to write in code for this..
A possible solution is given below..
Suppose your internal table fields are col1 and col2.
in the loop .....endloop of yout internal table in your PAI..there will be following(if your table control is made using wizard. otherwise you might have to add it..
loop at itab.
chain.
field col1.
field col2.
"some module
endchain.
endloop.
now make changes as shown to the above code..
loop at itab.
chain.
field wa-col1.
field wa-col2.
module table_modify on chain-request.
endchain.
now in your program add module table modify.
module table_modify input.
read table itab with key col1(which shud be unique) = wa-col1 transporting no-fields.
if sy-subrc = 0. " there exists another record with the same value
message e001(your message class).
endif.
endmodule.
i guess that shud work. get back if it dosnt.
regards
Suzie -
How to default value in collection after intial collection field entered
Hi there,
Am working on gettting to know collections but not really had much to do with them so far.
I have a multi row data entry screen that works great using a collection. Now the boss has decided that the new records require a default value that the users can overwrite if required.
The value i need to default is the second field in the collection but i only want to populate the value after the first field in the collection has been entered.
Could anyone talk me through how i do this please or point me to any relevant documents.
Cheers
LisaHi Lisa,
If you want to default value only after user enters data in another row column, you ll have to write a javascript code that executes after the column is entered
If you have jQuery(already included in apex 4.0) it would make the task of accessing that other column easy.
Otherwise its much more harder work to get I can think of setting the ID's using the pitem_id_* while rendering the editable fields(set it for both the columns..say as COL1_ROWNUM , COL2_ROWNUM ) using APEX_ITEM. Then add an onblur event(using the html attributes parameter of APEX_ITEM api) call a JS function with the rownumber(to identify the row). You can then write the logic for default value inside the function and set the corresponding column with the value.
If you can update about your version and/or if you use any JS libraries, it would be easier to help you any further. -
How to compare values in resultset
i am having problem in comparing result set values. Actually my store proc returns me the following resultset:
Month | Year | Deductible | Troop | TDC | ReasonCode
------------|-----------|-----------------|------------|-------------|--------------------------
January | 2008 | $100.0 | $0.0 | $0.0 | 1
------------|-----------|-----------------|------------|--------------|--------------------------
January | 2008 | $0.0 | $10.0 | $0.0 | 1
------------|-----------|---------------- |-------------|-------------|-------------------------
January | 2008 | $0.0 | $0.0 | $20.0 | 1
------------|-----------|-----------------|-------------|-------------|-------------------------
March | 2008 | $150.0 | $0.0 | $0.0 | 2
------------|-----------|-----------------|-------------|-------------|--------------------------
March | 2008 | $0.0 | $15.0 | $0.0 | 2
------------|-----------|-----------------|-------------|-------------|-------------------------
March | 2008 | $0.0 | $0.0 | $30.0 | 2
i will compare month and year fields. i.e if year is same the compare month and if month is same (e.g. January) the first three row of the above table will be clubbed in one row i.e.
Month | Year | Deductible | Troop | TDC | ReasonCode
------------|-----------|-----------------|------------|--------------|--------------------------
January | 2008 | $100.0 | $10.0 | $20.0 | 1
how can i do it in my result set?Learn SQL
"Select Month, Year, SUM(Deductible), SUM(Troop), SUM(TDC), ReasonCode from table Group By Month, Year, ReasonCode"Otherwise, loop through the resultset and compare the fields you want to compare using .equals() and sum the values yourself (of course). -
How to compare value before and after
hi,
one of the queried Values is the number of defective frames.Here, this value is compared with a previously sampled value
If now (after 10 s) this value is bigger than previous one ,then It saves new value otherwise loop will be continue.If again after (10s) the new value is bigger than previous new value then again saves this new point.how can i comapre value before and after?thanks.
TadhikaDo you know what a shift register is? It preserves a value from one loop iteration to the next. Please read the LabVIEW Help on shift registers. There's is also a simple example that ships with LabVIEW that will give you the basic idea (Help -> Find Examples).
You can also use a Feedback Node in lieu of a shift register. Same concept, different implementation. -
How to compare value of two Combo Box
I've two Combo Box(cbFirst & cbSecond). I want to compare the value that has been selected by the user and based on the result, output is displayed. In both Combo Box I've provided the value.
Here is my code:
var a:Number;
var b:Number;
function First(evt:Event):void{
a = evt.target.value;
trace(a);
cbFirst.addEventListener(Event.CHANGE, First);
function Second(evt:Event):void{
b = evt.target.value;
trace(b);
cbSecond.addEventListener(Event.CHANGE, Second);
If (a > b){
trace("a is greater")
else
trace(b is greater);
The trace statement inside the functions are working fine and the correct value of a & b is printed. But the comparison in the if statement doesn't seem to work. Could you please help me out.there's a typo. fix it or remove it:
var a:Number;
var b:Number;
function First(evt:Event):void{
a = evt.target.value;
trace(a);
compareF();
cbFirst.addEventListener(Event.CHANGE, First);
function Second(evt:Event):void{
b = evt.target.value;
trace(b);
compareF()
cbSecond.addEventListener(Event.CHANGE, Second);
function compareF(){
If (a > b){
trace("a is greater")
else
trace(b is greater); -
How to compare value in input field to value in database?
Hi all. I need to clear up if the value in the input field (e.g. input_field) is equal to at least one record in the field (e.g. name) in database table (e.g. customers), or not. The code should be like this:
IF...
message001. "(there's such a record in database)
ELSEIF...
message002. "(there's no such record in database)
ENDIF.
thanks all.Hi,
I think u r asking about validating the selction screen and displaying a mess if that input is not in the DB right?
AT SELECTION-SCREEN ON s_matnr.
*Validate material no details
PERFORM validate_matno.
FORM validate_matno.
SELECT SINGLE matnr INTO v_matnr
FROM mara
WHERE matnr IN s_matnr.
IF sy-subrc NE 0.
MESSAGE i128.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
Make sure that u are validating against the header table.
say eg if u wnat t validate matnr in marc, then do as below.
SELECT-OPTIONS: s_matnr FOR marc-matnr. "Material No
AT SELECTION-SCREEN ON s_matnr.
*Validate material no details
PERFORM validate_matno.
FORM validate_matno.
DATA: v_matnr LIEK mara-matnr.
SELECT SINGLE matnr INTO v_matnr
FROM <b>mara</b>
WHERE matnr IN s_matnr.
IF sy-subrc NE 0.
MESSAGE i128.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
Dont select from marc.
Hope this is clear. -
How to compare records in singe internal table
Hi Folks,
iam having 3 records in my first itab( T_FINAL) with fields
material no, descrip , mat type and group.
and 16 records in second itab(T_MVKE ) with fields
mat no , distri.chanel and division
now I want to fetch the records from T_MVKE by comparing the records in
T_FINAL .my requirement is to check the given mat no. in sales org.2000,2100. if yes then i have to consider 2000 only, if it is in only 2100 then consider 2100 only . is it is in 2000 only then consider 2100 only
my code is
LOOP AT T_FINAL.
READ TABLE T_MVKE WITH KEY MATNR = T_FINAL-MATNR.
IF SY-SUBRC = 0.
ON CHANGE OF T_MVKE-MATNR OR T_MVKE-VKORG.
IF T_MVKE-VKORG = '2000' and SY-TABIX > 1.
CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
ELSEIF T_MVKE-VKORG = '2000' AND SY-TABIX = 1.
CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
ELSE.
CONCATENATE '2100' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.
ENDIF.
this logic fails ,. could tell me how to compare values in single itab?
Thanks
nehaHi ,
if i've understand you correctly , try that:
LOOP AT t_final.
AT NEW matnr.
CLEAR: v_2000, v_2100.
*1) 2000
READ TABLE t_mvke WITH KEY matnr = t_final-matnr
vkorg = 2000.
IF sy-subrc = 0.
v_2000 = 'X'.
ENDIF.
*2) 2100
READ TABLE t_mvke WITH KEY matnr = t_final-matnr
vkorg = 2100.
IF sy-subrc = 0.
v_2100 = 'X'.
ENDIF.
*compare
IF v_2000 = 'X' AND v_2100 = 'X'.
*read 2000 only
ELSEIF v_2000 = ' ' AND v_2100 = ' '.
*nothing found
ELSE.
*all other combinations
*read 2100 only
ENDIF.
ENDAT.
ENDLOOP.
regards Andreas -
How to compare, current value in :block.text_item with the database value
Hi
Could you please tell me
How to compare the current value in :block.text_item with the corresponding database column value.
I am using forms 10g
There is block and there is an text Item in that block.
When I run the form and query the block (tabular), the :block.text_item shows me, whatever value there in the database.
Now I add some value in the :block.text_item to the existing value.
now
the :block.text_item contains old+ new added value
whereas
the database table contains 'old' value
Now on a button click , I want to find out what is the value that I have added
Could you please tell me, is it possible without writing a select query?Hello,
Now on a button click , I want to find out what is the value that I have addedSo you mean always user will add value in the existing value. Because this way will fail in one case. Let say
Value in Database is = ABCD
User opened the form and he removed the D and write E and now value is ABCE and length is still same 4. So, there is no addition.
Anyway you can know the database value at runtime there is one property for item called DATABASE_VALUE. It gives the value which is in database while you are running the form before save. and you can use like this..
Trigger = WHEN-MOUSE-DOUBLE-CLICK on item level
DECLARE
vItemValue DATATYPE; -- Set the data type according to your desired field.
vValueAdded DATATYPE; -- Set the data type according to your desired field.
BEGIN
vItemValue:=GET_ITEM_PROPERTY('ITEM_NAME',DATABASE_VALUE); -- It will return you the database value in vItemValue variable.
IF LENGTH(vItemValue)>LENGTH(:FORM_ITEM_NAME) THEN -- It mean something change or added
vValueAdded:=SUBSTR(:FORM_ITEM_NAME,LENGTH(vItemValue)+1);
MESSAGE('Added value is : '||vValueAdded); -- It will show you the added value.
END IF;
-- now suppose you want to show the old and new value in message not the added one
-- Then no need of IF condition. You can just use message like this
-- And i would prefer to use like this way
MESSAGE('Old Value : '||vItemValue||' New Value - '||:FORM_ITEM_NAME);
MESSAGE('Old Value : '||vItemValue||' New Value - '||:FORM_ITEM_NAME);
END;Hope it is clear.
-Ammad -
Friends
Could some one help me with Time values...
I would like to compare two time values one of which is stored as a string. so i would like to how to compare the system time with another column which has a string stored in time format..
i mean Sysdate - 10:30:00
Thanks in advance..select 'Y' from dual
where to_char(sysdate, 'HH24:MI:SS') = '10:30:00'
SQL> ed
Wrote file afiedt.buf
1 select 'Y' from dual
2* where to_char(to_date('10-02-2006 10:30:00', 'DD-MM-YYYY HH24:MI:SS'), 'HH24:MI:SS') = '10:30:0
SQL> /
Y
SQL> Cheers
Sarma.
Message was edited by:
Radhakrishna Sarma -
How to compare the value of a specied attribute to a string
I am looking for an example of how to compare the value of an attribute to a string. (I think)
I have been trying to:
if (attrs.get("title")== "Vampire") -- you already know this did not work.
How can I check to see if the title="Vampire"?
The code below will get me the title of admin (which should be Vampire)
import javax.naming.Context;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.DirContext;
import javax.naming.directory.Attributes;
import javax.naming.NamingException;
import java.util.Hashtable;
class Giles {
public static void main(String[] args) {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.1.55:389/o=sunnydale");
try {
DirContext ctx = new InitialDirContext(env);
Attributes attrs = ctx.getAttributes("cn=admin");
System.out.println("Title: " + attrs.get("title").get());
ctx.close();
} catch (NamingException e) {
System.err.println("Problem getting attribute: " + e);
Thank you!!
SteveI guess, you are looking for searching for attributes of an user object.
Here is the sample code to list all the attributes of an 'user' objectclass.
Tell me if it helps or not.
import java.util.Hashtable;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import javax.naming.*;
public class GetAttributes
public static void main (String[] args)
Hashtable env = new Hashtable();
//Must use either the userPrincipalName or samAccountName,
//Cannot use the distinguished name
String adminName = "cn=abcd,cn=Users,dc=ssotest,dc=com";
String adminPassword = "DEF1234";
String ldapURL = "ldap://pni3w067:389";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
//connect to my domain controller
env.put(Context.PROVIDER_URL,ldapURL);
try {
// Create the initial directory context
DirContext ctx = new InitialLdapContext(env,null);
// Create the search controls
SearchControls searchCtls = new SearchControls();
//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//specify the LDAP search filter
String searchFilter = "(&(objectClass=user))";
//Specify the Base for the search
//cn=policygroup,ou=policyusers,ou=ssoanay,;
//String searchBase = "ou=policyusers,ou=ssoanay,dc=ssotest,dc=com";
String searchBase = "cn=abcd,cn=users,dc=ssotest,dc=com";
//initialize counter to total the results
int totalResults = 0;
// Search for objects using the filter
NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls);
//Loop through the search results
while (answer.hasMoreElements()) {
SearchResult sr = (SearchResult)answer.next();
totalResults++;
System.out.println("\nName of Object : " + sr.getName());
// Print out some of the attributes, catch the exception if the attributes have no values
Attributes attrs = sr.getAttributes();
//System.out.println("6");
if (attrs != null) {
try {
/*NamingEnumeration enum = attrs.getIDs();
while(enum.hasMore()) {
System.out.println("IDs:"+enum.next().toString());
NamingEnumeration enum2 = attrs.getAll();
while(enum2.hasMore()) {
System.out.println("Attribute - "+enum2.next().toString());
catch (Exception e) {
System.out.println("Exception:" +e.getMessage());
else {
System.out.println("attribute is null");
System.out.println("Total results: " + totalResults);
ctx.close();
catch (NamingException e) {
System.err.println("Problem searching directory: " + e);
//return 0;
} -
How to create an apex collection to store and loop through the values
I couldn't find any simple example to do this
Apex 4.2
I need to create an apex collection. I have a query that returns multiple roles for a user. I need to check to see if one of my item values is within the collection but am not sure how to do so. So far I have:
begin
APEX_COLLECTION.CREATE_COLLECTION (
p_collection_name => 'ALL_ROLES');
select count(granted_role) into count from dba_role_privs where upper(grantee) = upper(:APP_USER);
end;
How would I store the query results in the collection?Trying to understand your code and a better suggestion:
declare
is_viewable boolean;
v_count number;
l_query varchar2(2000);
i_counter number(10) :=1;
begin
--l_query := 'select granted_role from dba_role_privs where upper(grantee) = upper(:APP_USER)';
--why do you need a collection, this is a simple select count(1) question
APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY (
p_collection_name => 'ALL_ROLES',
p_query => l_query,
p_generate_md5 => 'YES');
-- You create a collection, but where are you using it?
-- select count(granted_role) into count from dba_role_privs where upper(grantee) = upper(:APP_USER);
-- discard the above code
-- If you want to see how many elements in a collection
-- determine # of elements in a collection
http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/apex_collection.htm#CJAFFEAH
v_count := APEX_COLLECTION.COLLECTION_MEMBER_COUNT ('ALL_ROLES');
IF :P32_SUBMISSION_DATE IS NOT NULL THEN
begin
select count(granted_role) into v_count
from dba_role_privs
where upper(grantee) = upper(:APP_USER) and
granted_role in ('SURVEY_SUID','SURVEY_JOB_SUID');
exception
when no_rows_found then
v_count := 0;
end;
if v_count > 0 then
is_viewable := true;
else
is_viewable := false;
endif;
else
is_viewable := false;
endif;
return is_viewable;
end;Thank you,
Tony Miller
Ruckersville, VA -
How to compare dropdown pre value with post value in sharepoint designer list workflow
How to compare dropdown pre value with post value in sharepoint designer list workflow
Hi,
Can you provide more details about your requirement? It would make others easier to find a solution for you.
By default, a workflow will be triggered after submitting data in the NewForm or EditForm.
If you want to monitor the value changed in a drop down menu which is supposed to be in NewForm or EditForm, it would be more appropriate to apply custom JavaScript in the NewForm
or EditForm page.
About how to detect the value changed using JavaScript, the demos in this thread would be helpful:
http://stackoverflow.com/questions/12080098/dropdown-using-javascript-onchange
Thanks
Patrick Liang
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Compare fields in collection model to display which fields differ
Hi all
I have a previous post, which I may not have clearly enough stated my objective, and hence I feel as I may have been given an incorrect directive.
Anyway, I aim to be able to compare fields in collection model to display which fields differ between records. Ie, in my collection model, the SQL query may return 3 records. I want to be able to compare field A (rowindex 1) to field A (rowindex 2). I want to do this, so that I can use some EL or other method to change the text color presented to the user.
The problem here is that the SQL query has over 100 fields, so I definitely need a generic / reusable / programmatic way of doing this.
My initial approach was to create a bean that referenced values in the current and previous record set / iterator. Really, I am looking for a validation of my approach or any other alternatives.
My last resort will be to modify the SQL query, and duplicate each column with a 'changed flag'.
Thanks in advance,
SimoSure,
you should create a transient attribute in your VO and in method getters and setters in the view row class implement your bussiness logic. There are several posts in this forum about this subject. For example, how to create a transient attribute in a VO in r12
Regards, -
Comparing values of enumeration
can any body plz tell me how should i comapire values in enumeration
while(enuJob.hasMoreElements()){
jobFBean = (jobFlowBean)enuJob.nextElement();
this is my loop
n i want to compaire one value in tht with the next value of enumeration??
I think this code is used for that
for(out=nElems-1; out>1; out--)
for(in=0; in<out; in++)
if( a[in] >a[in+1] )
swap(in, in+1);
} But how can i find the length of enumeration here out=nElems-1??can any body plz tell me how should i comapire values
in enumeration
while(enuJob.hasMoreElements()){
jobFBean =
(jobFlowBean)enuJob.nextElement();
this is my loop
n i want to compaire one value in tht with the next
value of enumeration??
I think this code is used for that
for(out=nElems-1; out>1; out--)
for(in=0; in<out; in++)
if( a[in] >a[in+1] )
swap(in, in+1);
But how can i find the length of enumeration here
out=nElems-1??Enumerations are designed to iterate over members of a collection and operate on each member separately, they aren't really meant for operating on the collection as a whole (such as swaping the positions of elements). I can show you how to compare two adjacent elements, but it wouldn't do you any good, because you don't have random access to elements in an enumeration. You can't do a swap operation.
What you would want to do is have a simple, 1 element cache that stores the previous element, so you could do this:
Object oldObject = enu.nextElement();
while (enu.hasMoreElements()) {
Object ofInterest = enu.nextElement();
// I can do what ever I need to do to compare the two elements here.
// here, I rotate out the oldObject and ofInterest
oldObject = ofInterest;
}Again, I don't see that doing you any good, because you can't modify the collection from the Enumeration. You need to have the actual collection object to do that.
- Adam
Maybe you are looking for
-
Summarizing open items in down payment request from SD
Hello! We have a sales order with a billing plan, let say, 20% down payment, 80% - final invoice. There are 3 items in the sales order. When creating the down payment request the system creates 1 document with 3 customer lines. We would like to ha
-
Error in bapi while changing and add items in transparant table
data : t_poitems type standard table of bapimepoitem, t_poitemx type standard table of bapimepoitemx, w_poitems type bapimepoitem, w_poitemx type bapimepoitemx, t_return type standard table of bapiret2, w_return typ
-
We are a print shop, if we need to print white, we normally just change white to a cream color, and know its white for making our Flexo plates. We sent a 5 color spot image to a digital house, that is going to output our label digital with an HP ind
-
"fatal execution engine" error when launching labview--I just installed it?
I just installed Labview (I still have the CD in my computer) but when I double click the icon to start the program it starts the splash screen, but then issues an "internal execution engine fatal error." The only option to enter is into the JIT debu
-
Help please!