Please Help: query the value of the WHERE clause string
Hello worldI try the customers request that has corresponding name, but I get the result of every customer that has the name and surname. Here is my query:
SELECT * FROM CUSTOMERS WHERE
CUSTOMER_FNAME IN
(
'JOHN', 'MIKE'
)
AND CUSTOMER_LNAME IN
(
'DOE', 'MILLER'
);
I am trying to query customer name JOHN DOE and MIKE MILLER, but I get the results of all names with the names of first/last is not exact match. Is there a way I can get the exact match?Thank you
SM
Something like
SQL> -- generating sample data:
SQL> with customers as (
2 select 'JOHN' fname, 'DOE' lname from dual union
3 select 'JO' fname, 'HNDOE' lname from dual union
4 select 'MIKE' fname, 'DOE' lname from dual union
5 select 'JOHN' fname, 'MILLER' lname from dual union
6 select 'MIKE' fname, 'MILLER' lname from dual
7 )
8 --
9 -- actual query:
10 --
11 select *
12 from customers
13 where fname||'~'||lname in ('JOHN~DOE', 'MIKE~MILLER');
FNAM LNAME
---- ------
JOHN DOE
MIKE MILLER
2 rows selected.
but it's just a way, there is more...
Published by: Hoek on 2 April 2013 18:20 example change changed, thanks to Frank and APC to report that I really need a break now ;)
Tags: Database
Similar Questions
-
In the WHERE clause string variable
I have the procedure
CREATE OR REPLACE PROCEDURE proc1 (p_1 IN varchar2)
IS
BEGIN
DELETE FROM TABLE1
WHERE
Col1 = '@p_1. '
;
Dbms_output.put_line (number of rows sql %);
COMMIT;
EXCEPTION
WHILE OTHERS THEN
ROLLBACK;
RAISE_APPLICATION_ERROR (-20000, SQLERRM);
Proc1 END;
/
You will need to pass a string input parameter to the procedure. This string is applied to the WHERE clause. The foregoing does not work correctly the value of @p1 is in the WHERE clause. The value passed to the stored procedure does not run.
Please let me know the solution. I have to use BIND variables only.
Thank youuser12038051 wrote:
Thank you all. Yes, the underside of the works.DELETE FROM TABLE1
WHERE
Col1 = p_1
;PS: Both COL1 and p_1 are string values. Would like to know how it works with out the quotes because it is a string.
In addition I would like to follow the number of lines executed in each statement. Preference will have to use sql % rowcount. Are there other alternatives. Please let me know. Thanks in advance.
Oracle 'knows' that the variable p_1 is a varchar2 data type and that col1 is a varchar2 data type, so he makes a comparison between them strinf. This is how variables work in any programming language that I am aware. The only time that you must provide a value is when you use a literal value (for example in an assignment variable, or as a parameter of a procedure).
If you need to know the number of deleted rows, then sql % rowcount is the only sensible option. Just be aware that you need to get the value before committing yourself ot other options of SQL.
John
-
I have a Select statement where I want to select rows where weighs only 1 of the selected date 3 columns is null. Is this possible?
Select rec_date, prior_rec_date2, prev_rec_date3
of my_receipts
where (not more than 1 or the date 3 fields is null)
Any help would be greatly appreciated.Hello
WHERE NVL2 (rec_date, 1, 0) + NVL2 (prior_rec_date2, 1, 0) + NVL2 (prev_rec_date3, 1, 0) >= 2
-
Tuning - using the CASE statement in the WHERE clause of the query
Hi all
My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:
Query:
Description of the table:SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date, os.acctnum, os.avieworigin_refid, COUNT(1) cnt_articleview, SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm FROM TABLE1 os WHERE os.acctnum IS NOT NULL AND os.avieworigin_refid IS NOT NULL AND os.requestdatetime IS NOT NULL AND UPPER(os.success_ind) = 'S' AND CASE WHEN Param_ValueToCheck = 'FULL' AND get_date_timestamp(os.requestdatetime) BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' AND os.entry_createddate BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 END = 1 AND CASE WHEN Param_ValueToCheck = 'FULL' AND os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') THEN 1 WHEN Param_ValueToCheck = 'INCR' THEN 1 END = 1 GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
(Number of lines: approx. > amount 600 000 000)
Explain PlanName Null Type ------------------------------ -------- ------------ ARTICLEID NOT NULL NUMBER(20) USERKEY NUMBER(10) AVIEWORIGIN_REFID VARCHAR2(10) SUCCESS_IND VARCHAR2(2) ENTRY_CREATEDDATE DATE CREATED_BY VARCHAR2(10) FILENUMBER NUMBER(10) LINENUMBER NUMBER(10) ACCTNUM VARCHAR2(10) AUTOCOMPLETEDTERM NUMBER(2) REQUESTDATETIME VARCHAR2(19)
Published by: Chaitanya on June 9, 2011 02:44SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 2224314832 ---------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | ---------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 1 | HASH GROUP BY | | 590 | 33040 | 2501K (1)| 08:20:15 | | | | 2 | PARTITION RANGE ALL| | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| |* 3 | TABLE ACCESS FULL | TABLE1 | 590 | 33040 | 2501K (1)| 08:20:15 | 1 |1048575| ---------------------------------------------------------------------------------------------------------- PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE WHEN ('FULL'='FULL' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN 'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE WHEN ('FULL'='FULL' AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
Published by: Chaitanya on June 9, 2011 02:47When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.
BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
Are compare us like with like? -
Please help on the binding of variables
Hello
I need to bind the variable into the next function.
If the only deptno is passed to the function, the function will return correct result. However, if all of the deptno is passed, the function cannot give correct result.
Could someone help me please in this topic...
Thanks in advance!
Scott@ORA111 > create or replace function my_test (p_deptno_list varchar2)
2 return sys_refcursor
3 as
4 rec sys_refcursor;
VARCHAR2 (1000) v_sql 5.
6
7. start
8 v_sql: = ' select * from emp where deptno in (: 1)';
9. open rec for v_sql using p_deptno_list;
10 return rec.
11
12 end;
13.
The function is created.
Elapsed time: 00:00:00.04
Scott@ORA111 > var my_rec refcursor
Scott@ORA111 > run: my_rec: = my_test('10');
PL/SQL procedure successfully completed.
Elapsed time: 00:00:00.00
Scott@ORA111 > print: my_rec
EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 2450 JUNE 9 81 10
PRESIDENT OF 7839 17 NOVEMBER KING 81 5000 10
7934 MILLER COMMITTED JANUARY 7782 1300 23 82 10
SELLER OF TEMP 9999 7782 6000 27 APRIL 09 10
Elapsed time: 00:00:00.01
Scott@ORA111 > var my_rec refcursor
Scott@ORA111 > run: my_rec: = my_test (10, 20');
PL/SQL procedure successfully completed.
Elapsed time: 00:00:00.01
Scott@ORA111 > print: my_rec
ERROR:
ORA-12801: error reported in the parallel query P000 Server
ORA-01722: invalid number
no selected line
Elapsed time: 00:00:00.01You can also do this by changing the where clause with INSTR function
SELECT * FROM EMP WHERE INSTR(:P_DEPTNO,DEPTNO) > 0
-
by the way check box values in the WHERE clause
Hello
I created a data block - 'CONTACT' (block of data in database)
and has an element of database - 'Code', 'Descr '.
The number of records displayed has the value 5.
When enabled - value 'Y '.
Value when disabled - n
Box mapping of other values - "unchecked."
I write the code inside "WHEN the BUTTON PRESS. My main goal is to return the number of records from
According to several conditions and one among them is the CODE which can be single or multiple based on the checked checkbox.
The requirement is when I check one or more boxes, I should pass the "Code" element values in the WHERE clause.
I tried to use the simple loop but things havmt worked as shown below.
The next_record refers to the COCHEE BOX as well, and thus return all the eventhough lines if it is not checked.
----------------------------------------------------------------------------
-LOOP
IF: contact.cb = 'Y' THEN
LOOP
IF p_where is null then
p_where: =: contact.code;
on the other
p_where: = p_where | «, » || : contact.code;
end if;
When the output: system.last_record = "TRUE";
next_record;
END LOOP;
end if;
-END LOOP;
MESSAGE ("p_where :'|| p_where);
MESSAGE (' ');
END;
------------------------------------
And even if I write the LOOP before the first CASE, it returns me the current value and move to the last record.
Please suggest
Try something like this:
FIRST_RECORD; LOOP IF :contact.cb = 'Y' THEN IF p_where is null then p_where := :contact.code; else p_where := p_where ||','||:contact.code; end if; END IF; exit when :system.last_record = 'TRUE'; next_record; END LOOP; -- END LOOP; MESSAGE ( 'p_where :'||p_where); MESSAGE (' '); END;
-
Please help about the FRM-47023 - parameter does not exist in form
Dear all,
Best wishes...
I'm currently doing some additions to existing forms.
in fact, I have two forms, form and b. (form A) based on the tables and B form based on table B
Existing scenario.
Formula A-> table A contains the columns as
A1Col1 - Primary key
A1Col2 - Primary key
A1Col3 - Primary key
A1Col4 - Primay key
A1Col5
A1Col6
Form B-> table B
B1Col1 = A1Col1
B1Col2 = A1Col2
B1Col3 = A1Col3
B1Col4 = B1Col4 (this is newly added column in TableB and form present I do not have this relationship, so I
Add an element of text in form B and made it point to databases and give the coloumn name)
B1Col5
B1Col6
Existing features:
Form A is the main form and there is a button pressed, it will pass (A1Col1 parameters
A1Col2, A1Col3 to the B shape based on what form B will ask details.
Existing for this push in FormA button code is:
DECLARE
Code for the new instance of the form to FormB:
pl_id ParamList;
pl_name VARCHAR2(15) := 'ls_parm_list';
BEGIN
if :TableA.A1Col1 > ' ' and
:TableA.A1Col2 > ' ' and
:TableA.A1Col3 > ' ' and
:TableA.A1Col4 > ' ' then (-- (newly added line for current requirement)
pl_id := Get_Parameter_List(pl_name);
if NOT Id_Null(pl_id) then
Destroy_Parameter_List(pl_id);
end if;
pl_id := Create_Parameter_List(pl_name);
Add_Parameter(pl_id,'A1Col1',TEXT_PARAMETER,:TableA.A1Col1);
Add_Parameter(pl_id,'A1Col2',TEXT_PARAMETER,:TableA.A1Col2);
Add_Parameter(pl_id,'A1Col3',TEXT_PARAMETER,:TableA.A1Col4);
Add_Parameter(pl_id,'A1Col4',TEXT_PARAMETER,:TableA.A1Col3); -- (newly added line for current requirement)
Add_Parameter(pl_id,'A1Col5',TEXT_PARAMETER,:PARAMETER.UID);
NEW_FORM('FormB',TO_SAVEPOINT,NO_QUERY_ONLY,pl_id);
end if;
END;
DECLARE
So now,.
W_WHERE VARCHAR2(100);
BEGIN
if :PARAMETER.Param1 > ' ' then
W_WHERE := 'B1col1=''' || :PARAMETER.param1 || ''' AND B1col2=''' || :PARAMETER.param3 || ''' AND B1col3 =''' || :PARAMETER.param4 || ''' AND B1col4=''' || :PARAMETER.Param4 || '''';
Set_Block_Property('TableB',DEFAULT_WHERE,W_WHERE);
execute_query;
Set_Block_Property('TableB',DEFAULT_WHERE,'');
end if;
:SYSTEM.MESSAGE_LEVEL := 25;
END;
New features:
I need to spend an additional column in TableA (A1Col4) also a parameter to form B so that it will be in the where clause of the form B.
To achieve this requirment,
Step 1:
Step 1: I added B1Col4 to TableB because it did not exist before.
Step 2: I added a text element in FormB, named as "A1Col4" and set its property to iterm Yes to Database and columname to A1Col4.
And then I created a setting called "' A1Col4" to FormB (this iis since I added a new setting FormA pressed button code above)... ".
Now, the real problem I am facing:
I have compiled the forms, and it went well... I ran the FormA... Here are the scenarios:
1. formA is running and when I run the query, it performs gets data, when press the button go form B (to all 4 parameters to formb, I get error. FRM 47023 No. such parameter named A1col4 exists in FormB. even though I have the parameter b form created recently with this name.
2. so I just kept the existing code button pressed (commented on newly added lines, keeping the 3 parameters instead of 4) and removed "' AND B1col4 =" ' | : PARAMETER. Param4 | "' from the whennewform code instance formb, the result is: FormA call FormsB successfully, FormB is to be opened, BUT VERY STRANGE, THAT NEWLY ADDED POINT (COLUMN TABLEB THAT I wanted TO PASS ADDITIONAL PARAMETER FROM FORM 'A') IS MISSING. This text element appears not.
3. If I run FormB alone, then it is querying data, the newly added text element is also displayed but if if I have the same call FormA, error FRM-47023.
I sat for hours and hours to find out what exactly the problem... but no clue...
Sorry for the long post... but in hope and who seek the help of our friends from the OTN network...
Hope that I have explained clearly the problem... By the way that the version is 10G forms.
Thanks for the help in advance for everyone...
Kind regards
Prasanththey are in the same folder
If you're on 10G, being in the same folder does not mean automatically that the forms be made on this issue. In your EPS file, there is a parameter named FORMS_PATH, forms are searched for in directories listed there. To verify your env file. also, you could search the entire disk by issuing a
dir formb.fmx /s
from the root directory of your disks.
-
HP mini 110 c: Hi, please help unlock the password of bios compaq mini 110 c.
Hi, please help unlock the password of bios compaq mini 110 c.
fatal error system stopped
CNU93133K2
Hello
Enter: e9lof3ffs7 (3rd charater is a lowercase L)
Kind regards
DP - K
-
When I opened outlook express Inbox, all messages have been deleted, please help restore the same
Go to view | Current view | Show all messages to make sure that you have just selected 'Hide read messages.
If this does not help, check your Recycle Bin, the bak files which are dbx files, you can restore backups. See www.oehelp.com/OETips.aspx#2
If this does not help, then you will probably need my program DBXpress (www.oehelp.com/DBXpress/), which will extract the messages from individual dbx files, and if messages are no longer in the files, it can extract from the disc itself.
Steve
-
Please help find the driver win 7 for sharp AM-400 MFP
I have Windows XP driver for my Sharp AM - 400 multifunction printer. I tried to install it in different compatibility mode to work on win 7 but without success. Please help find the driver win 7 for sharp AM-400 MFP. Regarding the LEP
Think that its too old. I think its time to get another printer
-
Hello! A few days ago, I, disabled Photoshop subscription (CC of Lightroom and Photoshop CC) Act in accordance with your instructions, I have not be enabled. Please help solve the problem?
Contact support - for the link below, click on the still need help? option in the blue box below and choose the option to chat or by phone...
Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache. If it fails to connect, try to use another browser.
Creative cloud support (all creative cloud customer service problems)
http://helpx.Adobe.com/x-productkb/global/service-CCM.html ( http://adobe.ly/19llvMN )
-
Please help improve the JavaScript script
Please help improve the JavaScript script
Hello
to increase or decrease the height of a subform, you use the following syntax in the click of + and - button
cmdAdd::JavaScript
_Row1.addInstance (1);
var b is parseFloat (Subform3.h) - 6.5;.
If (b<>
b = 0;
}
Subform3.h = b + "mm";
cmdRemove::JavaScript
If (_Row1.count > 1) {}
var b is parseFloat (Subform3.h) + 6.5.;
Subform3.h = b + "mm";
_Row1.removeInstance (this.parent.index);
}
This should do the trick, I hope this will help you
-
Error 213:10 on windows 10. Please help solve the problem
Error 213:10 on windows 10. Please help solve the problem
Different code, but can help - error 213:19 license https://forums.adobe.com/thread/1907953 because of write permissions
Run all programs as Administrator http://forums.adobe.com/thread/969395 to assign FULL... Permissions said yet, but it is sometimes necessary for Adobe
-
Please help me, the round sign of gum disappear (yesterday I upgraded to 2015 worm)
Please help me, the round sign of gum disappear (yesterday I upgraded to 2015 worm)
Wassakorni55174346
Reset the Eraser tool. Click on the gum and choose Reset tool.
-
Setting in the WHERE clause of the query
Hi all
I have 2 tables.
TABLE_A contains 10 million documents.
TABLE_B contains 100 records.
I associate myself with these 2 tables
Here's a.ID left
Here's b.ID leftSELECT A.*, B.* FROM TABLE_A a, TABLE_B b WHERE a.ID = b.ID;
My question is what query will give better performance? I thought that, if we put the column in the table with a lower number of lines on the left, then it will be faster than the other.SELECT A.*, B.* FROM TABLE_A a, TABLE_B b WHERE b.ID = a.ID;
In current versions of Oracle, it does not matter in what order you sum-up your predicates in the WHERE clause of a query: they will be optimized/executed in a way even.
Maybe you are looking for
-
Remove the Google search bar of about: newtab page
It's maddening, and why users don't upgrade their software. The 3 latest updates of Firefox have caused many to not open in Firefox https sites, but they work fine in Internet Explorer. Lowering the TLS settings in topic: config from 3 to 2 fixed pri
-
Windows 7 - Disable CPU Core Parking, it works.
I recently heard of a technical guy on Windows 7, it is features that call parking core, which would be activated / deactivated your processor from time to time. And that's the main cause you're system is the momentary lock and lock upward for some t
-
Hello I am trying to send a digital signal using a PCI-6259 and concurrently read an analog waveform using a PCI-6132. I tried to look at examples of synchronization but seem to have trouble trigger c using DAQmx Start Trigger (PowerPlay). Is the 625
-
Problems in Flight Simulator 98
I have Flight Simulator 98 that I have loaded on my new Dell computer with vista. My logitech joystick will not work with her, it this year but will not do anything else. How to operate? It worked fine with my old computer which had xp on it. It is s
-
Photosmart B209a printer causes internet to file when connecting to a netgear WNDR4000 router
I had problems with the internet connection being lost on our wireless network. I traced the problem until when the Photosmart printer connects to the wireless router, internet connection seems to fall. If I turn off the printer and I do not find the