Help... CASE in the WHERE clause...!
Hi allI need help in the following condition. I am passing the parameter say INDI. the value of INDI can be 01 or 02
I am retriving count in a table. say,
DECLARE
CNTL varchar2 (5);
BEGIN
Select count (*) from cntl
XYZ
where FLG = CASE WHEN INDI = '01', then 'Y' END;
dbms_output.put_line (cntl);
END;
the FLG column can contain the value "Y" or "n" or NULL. If I run the above code, it gives me a count for these lines where FLG = 'Y' for INDI 01. But if I spend INDI = 02, it should give me account for these lines that has FLG = ' not and NULL.
If I say where FLG = CASE WHEN INDI = '01' and then 'Y' ELSE ' no END; then he'll give me an account for these lines that has FLG = ' don't, but here I want County to FLG = 'n' and FLG = NULL, if I spend INDI = 02
I am not able to determine how I can achieve this...
select count(*) into cntl
from xyz
where NVL(FLG,'N') = CASE WHEN INDI = '01' THEN 'Y'
WHEN INDI = '02' THEN 'N'
END;
Tags: Database
Similar Questions
-
Hi all
I posted the question about CASES where the condition. It is one of the changes.
The first condition was, if the Individual is 01 extraction then all the values of the table where the column of FLG = 'Y '. If the Individual is 02 and then extract all the values of the table where the column of FLG = ' no or NULL. Here, INDI is the setting.
Select count (*) from cntl
XYZ
where NVL(FLG,'N') = decode(INDI,'01','Y','02','N');
Now the chnages is, if the Individual is 01 and then extract all the values in the table where FLG colum = 'Y '. If the Individual is 02 and then extract all the values in the table, including ('Y', ' n, NULL). no need to put the filter of the FLG columns in which contion.It's not just...
select count(*) into cntl from xyz where NVL(FLG,'N') = decode(INDI,'01','Y','02',NVL(FLG,'N'));
Or shorter:
select count(*) into cntl from xyz where NVL(FLG,'N') = decode(INDI,'01','Y',NVL(FLG,'N'));
If you are happy for 01 retreat flg of Y and any other value fold everything.
Published by: BluShadow on June 3, 2009 12:31
-
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? -
Outer joins and null in the 'where' clause condition
Hi people,
Please help me on this.
Here's my query.
with x
(select 'a' as a dual union all col1)
Select 'b' as col1 of union double all the
Select 'c' as double col1
),
y as
(
Select 'b' as col2 from dual Union all the
Select 'c' as col2 from dual Union all the
Select would be "as col2 from dual Union all the"
Select 'e' as col2 from dual
)
Select * x y right outer join
on x.col1 = y.col2 and y.col2 is null
Get all the lines of 'COL1' as null. Why like this?
Just add the condition to the WHERE clause for example
WITH x AS (SELECT 'a' AS col1 FROM dual UNION ALL SELECT 'b' AS col1 FROM dual UNION ALL SELECT 'c' AS col1 FROM dual ), y AS ( SELECT 'b' AS col2 FROM dual UNION ALL SELECT 'c' AS col2 FROM dual UNION ALL SELECT 'd' AS col2 FROM dual UNION ALL SELECT 'e' AS col2 FROM dual ) SELECT * FROM x LEFT OUTER JOIN y ON x.col1=y.col2 ----want to add "and y.col2 is null " condition to get value "a" where y.col2 is null
-
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;
-
DECODE inside the WHERE clause
Hi all:
I can't get the DECODE statement to work inside my WHERE clause. I have read the information on
Tahiti.Oracle.com
http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions049.htm#i1017437
But still can not get it to work. Initially, I had he works as dynamic SQL and then run that string, but I am not allowed to use dynamic SQL statements and to do 'Real' PL/SQL.
I have the following WHERE clause (more info after the WHERE clause)
As you can see, initially I was adding values of "whereClauseStatus, whereClauseFromDate, whereClauseToDate" and it has been defined with the following PL/SQL code:WHERE a.ebiz_asn_no(+) = te.ebiz_cntrl_no AND w.ebiz_work_no(+) = te.ebiz_cntrl_no AND o.ebiz_ord_no(+) = ebiz_cntrl_no AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no AND ms.ebiz_sku_no(+) = te.ebiz_sku_no AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1)) AND tl.ebiz_lp_no(+) = te.ebiz_lp_no AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1)) AND eu.ebiz_user_no(+) = te.act_ebiz_user_no AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1)) AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~')) AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~')) AND te.comp_id = p_CompID AND te.site_id = p_SiteID AND INSTR('' || p_TaskType || '', te.task_type) > 0 AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1)) AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL (te.ebiz_cntrl_no,-1))) AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~')) AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1)) || whereClauseStatus || whereClauseFromDate || whereClauseToDate;
I have serious problems getting the DECODE statement to replace the three variables in the annex.IF(p_TaskStatus = 'C') THEN ------------------------------------------------------------------------------------------- -- Set From Date Clause ------------------------------------------------------------------------------------------- IF(p_FromShipDate IS NOT NULL) THEN whereClauseFromDate := ' AND TRUNC(te.act_end_date) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') '; END IF; ------------------------------------------------------------------------------------------- -- Set To Date Clause ------------------------------------------------------------------------------------------- IF (p_ToShipDate IS NOT NULL) THEN whereClauseToDate := ' AND TRUNC(te.act_end_date) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') '; END IF; ELSE ------------------------------------------------------------------------------------------- -- Incomplete and All statuses are filtered on the currdate ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- -- Set From Date Clause ------------------------------------------------------------------------------------------- IF(p_FromShipDate IS NOT NULL) THEN whereClauseFromDate := ' AND TRUNC(te.currdate) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') '; END IF; ------------------------------------------------------------------------------------------- -- Set To Date Clause ------------------------------------------------------------------------------------------- IF (p_ToShipDate IS NOT NULL) THEN whereClauseToDate := ' AND TRUNC(te.currdate) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') '; END IF; END IF; IF (p_TaskStatus = 'I') THEN whereClauseStatus := ' AND act_end_date IS NULL '; ELSIF (p_TaskStatus = 'C') THEN whereClauseStatus := ' AND act_end_date IS NOT NULL '; ELSE whereClauseStatus := ''; END IF;
Any help would be greatly appreciated.
Thank you
Andy
Published by: BluShadow on August 2, 2011 15:11
addition of {noformat}{noformat} tags for clarity. Please read {message:id=9360002} and learn to do this yourself.
I'll take a wild shot in the dark, and suggests that it is perhaps what you are looking for...
WHERE a.ebiz_asn_no(+) = te.ebiz_cntrl_no AND w.ebiz_work_no(+) = te.ebiz_cntrl_no AND o.ebiz_ord_no(+) = ebiz_cntrl_no AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no AND ms.ebiz_sku_no(+) = te.ebiz_sku_no AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1)) AND tl.ebiz_lp_no(+) = te.ebiz_lp_no AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1)) AND eu.ebiz_user_no(+) = te.act_ebiz_user_no AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1)) AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~')) AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~')) AND te.comp_id = p_CompID AND te.site_id = p_SiteID AND INSTR('' || p_TaskType || '', te.task_type) > 0 AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1)) AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL (te.ebiz_cntrl_no,-1))) AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~')) AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1)) AND TRUNC(te.act_end_date) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.act_end_date)) AND TRUNC(te.act_end_date) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(tw.act_end_date)) AND TRUNC(te.currdate) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.currdate)) AND TRUNC(te.currdate) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(te.currdate)) AND ( (act_end_date IS NULL AND p_TaskStatus = 'I') OR (act_end_date IS NOT NULL AND p_TaskStatus = 'C') OR p_TaskStatus NOT IN ('I','C') )
Published by: BluShadow on August 2, 2011 16:27
spleen the last clause. Oops. -
Session variable in the WHERE clause of the SQL statement
Hey all,.
I was wonering just if there is a way to set the WHERE clause of the query that the session variable? I have the following so far and have tried to go through a ton of tutorials, but it doesn't seem to work. Is it still possible? I don't know what follows is wrong, but can someone help me with changing the following code, or pointing me to a good tutorial? (I write it with PHP)
$query = "SELECT * from members where user_id = ' $_SESSION ['members']";
Thanks for your help.
$member = "-1";
If (isset($_SESSION['members'])) {}
$member = $_SESSION ['members'];}
$query = "SELECT * from members where user_id = $member; -
Try adding conditions to clause "and" stored in the table for the where clause, unknown syntax
I am trying to add additional segments to the 'where' clause, and I don't know exactly how to proceed. I am currently using another table to search for keywords and sometimes there aren't everything. I use this table containing the key words to search the description and associate a symbol with a path.
The code loops through the keywords with the keywords most associated and try to find links to a symbol then excludes those and search for symbols that correspond to those with less keywords and all. I am able to do this with 6 queries and manually changing the arguments, but I want to loop together so that if the changes need to be made in the future, I won't need to go digging in the code.
Thanks, but that's ok. I already have a solution for this.
-
T/t with the WHERE clause using a list breaks
Hello, all,.
I have a project where I need to use a list as part of the WHERE clause for a t/t, and it is breaking. I don't know what I'm doing wrong.
For some pseudo-code, do I have a complete query of a database called 'people '. A list of values for the t/t with the first query; the second query is my t/t:
<cfquery name="getDIR" datasource="#request.THISDSN#"> SELECT thisName dir FROM orgs WHERE thisID in (<cfqueryparam value="#form.org#" cfsqltype="cf_sql_varchar" list="yes" />) </cfquery> <cfquery name="people" database="people"> SELECT colA, colB, colC, colD FROM people WHERE 1=1 AND ( div IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />) OR dir IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />) ) </cfquery>
I get the error message is "t/t syntax error: encountered" div IN \'thisValue\' ".» Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition. »
Can support _not_ QoQ lists of WHERE clauses?
V/r,
^_^
SMH - so much... I just found.
I forgot to give the lists in the second query bracket.
(The pseudocode was manually typed, since my dev system is isolated from the internet, and I added the in my pseudo code when they were not in my original code.)
* headdesk * headdesk * headdesk * headdesk *.
V/r,
^_^
-
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
-
Beginner: Get on the WHERE clause syntax error in SELECT
I am very new to php and mySQL. Use DW master/detail to generate Basic code I need. One thing I have to do is to modify a select statement in the master to include a WHERE clause to limit the selection to a particular value in a field.
I get a syntax error with the select statement in the WHERE clause, I add to the map.
It's the part of the error message showing the location of the error:
"WHERE group = 'Community' LIMIT 0, 10'"
Php that generated the select is:
$query_maps = "SELECT * FROM tblmaps ORDER BY tblmaps.» DispSeq ';
$query_limit_maps = sprintf ("%s WHERE group =' LIMIT %s %d, %d", $query_maps, $selectGroup, $startRow_maps, $maxRows_maps);
This approach to create the select statement is on the generated code for the master page. He added the LIMIT clause. I didn't add the ' WHERE group = '%s' and the variable $selectGroup, which comes from the old code.» You can see that the $selectGroup variable is equal to the "community: group.»
I scanned the web to see what syntax error, I could do, but haven't found anything that explains it.
The resolved full select statement is:
SELECT * FROM tblmaps ORDER BY tblmaps. WHERE DispSeq = 'Community' LIMIT 0,10 group
What I don't see?
Tom
The group is a reserved word in MySQL. You could probably put single quotes around it, but I suggest to rename this column. Do not use reserved words for column names.
-
DECODE does not work in the WHERE clause when subquery returns more than one line
Hi gurus,
I want to write a query against the table CCENTERS (Script given below) and wait for the following result:
1. in the transition from a value of 0 for the ID, it returns all the rows in the table.
2. in the passage of one value other than 0, it returns the row corresponding to the given value and all its records of the child.
CCENTER has parent-child relationship in the column ID and the BASE. I use a query with the DECODE function. but the function in the WHERE clause is not capable of managing the subquery with multiple lines of DECODE.
*************************************************
VARIABLE ParaCCenter NUMBER
BEGIN
: paraccenter: = 0;
END;
/
CREATE TABLE ccenters
(id NUMBER,
name VARCHAR2 (20).
number base);
INSERT INTO ccenters VALUES(1,'NUST',null);
INSERT INTO ccenters VALUES(2,'SEECS',1);
INSERT INTO ccenters VALUES(3,'NBS',1);
commit;
SELECT * from ccenters
WHERE id IN DECODE(:ParaCCenter, 0, id,)
(SELECT id FROM ccenters
START WITH basic =: ParaCCenter
ID of CONNECTION BY PRIOR = base
UNION
SELECT: ParaCCenter OF double
)
)
/
BEGIN
: paraCCenter: = 1;
END;
/
SELECT * from ccenters
WHERE id IN DECODE(:ParaCCenter, 0, id,)
(SELECT id FROM ccenters
START WITH basic =: ParaCCenter
ID of CONNECTION BY PRIOR = base
UNION
SELECT: ParaCCenter double))
/
The result is
(SELECT id FROM ccenters
*
ERROR at line 3:
ORA-01427: einreihig subquery returns multiple rows
How this query can be rewritten for the given feature. Any response will be appreciated.
Thank youTry something like this:
SELECT * FROM ccenters WHERE :ParaCCenter = 0 OR id in (SELECT id FROM ccenters START WITH base=:ParaCCenter CONNECT BY PRIOR id = base UNION SELECT :ParaCCenter FROM dual )
-
Trouble using a function in the where clause
Hello
I use a function that is located at ask.tom.oracle.com, which converts a long data type in a character. The function returns an error when it is placed in the where clause. The sql statement, the error message and the function of asking tom are listed below. Does anyone know how to fix this?
< pre >
SELECT A.FLDPHYSICAL,
A.FLDEXPOSURE,
A.FLDDATEDUE,
A.FLDDATELAST,
A.FLDEMPLOYEE,
B.FLDBDATE,
B.FLDMAILSTOP,
B.FLDREC_NUM,
B.FLDLNAME,
B.FLDMI,
B.FLDFNAME,
B.FLDBDATE,
B.FLDDEPT,
B.FLDSTATUS,
B.FLDSSN,
B.FLDHOMEPHON,
B.FLDWORKPHON,
B.FLDID,
B.FLDDIVISION
OF REQEXAM,.
B OF THE EMPLOYEE,
C EMPLOYEE_MEMO
WHERE A.FLDEMPLOYEE = B.FLDREC_NUM
AND b.flduserstr = c.fldrec_num
AND OHM_PKG. GET_LONG ('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) AS ' % CDL YES % '.
"AND A.FLDDATEDUE > 1 January 1900"
AND A.FLDPHYSICAL = 'COP '.
ORDER OF B.FLDDIVISION,
B.FLDLNAME,
B.FLDFNAME,
B.FLDMI,
A.FLDDATEDUE
-------------------------------------------------------------------------
The error message
Error in the command line: 26 column: 4
Error report:
SQL error: ORA-00904: "OHM_PKG." "" GET_LONG ": invalid identifier
00904, 00000 - '% s: invalid identifier '.
-------------------------------------------------------
create or replace
PACKAGE OHM_PKG AS
/ * TODO type (types, exceptions, methods etc.) package declarations here * /.
getlong function (p_tname in varchar2, p_cname in varchar2, p_rowid in rowid) return varchar2;
END OHM_PKG;
create or replace
PACKAGE BODY OHM_PKG AS
getlong function (p_tname in varchar2, p_cname in varchar2, p_rowid in rowid) return varchar2 as
whole l_cursor default dbms_sql.open_cursor;
number of l_n;
l_long_val varchar2 (4000);
number of l_long_len;
number of l_buflen: = 4000;
l_curpos number: = 0;
Start
DBMS_SQL. Parse (l_cursor,
"select" | p_cname | 'from ' | p_tname |
' where rowid =: x',.
DBMS_SQL.native);
DBMS_SQL.bind_variable (l_cursor, ': x', p_rowid);
DBMS_SQL.define_column_long (l_cursor, 1);
l_n: = dbms_sql.execute (l_cursor);
If (dbms_sql.fetch_rows (l_cursor) > 0)
then
DBMS_SQL.column_value_long (l_cursor, 1, l_buflen, l_curpos,)
(l_long_val, l_long_len);
end if;
DBMS_SQL.close_cursor (l_cursor);
Return l_long_val;
getLong end;
END OHM_PKG;
< / prev >Remove the '_' in the name of the function as below:
AND OHM_PKG. GETLONG('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) AS "CDL % YES % '.
-
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.
-
Execution of statement of UPDATE for the whole table even when the WHERE Clause is presentation
Hi friends,
I have a problem in a stored procedure where I wrote an update with a where clause clause statement. At some point only one line should be updated according to the unique identifier in where clause.
But what is happening is that the Update statement is getting executed for all rows in the table to neglect the WHERE clause. I don't get any idea of why this is happening. Here is the stored procedure and the update statement is BOLD:-
CREATE OR REPLACE PROCEDURE MDMADM.proc_MDM_InsertCntryDetails
(
CntryMasterCode IN VARCHAR2,
CntryName IN VARCHAR2,
MDMUser IN VARCHAR2,
Exists IN ITS ENTIRETY,
status in VARCHAR2,
Inserted_By IN VARCHAR2 default NULL,
Modified_By IN VARCHAR2 default NULL,
Mdm_Code IN the DEFAULT NUMBER 0.
Action in VARCHAR2 DEFAULT 'Add ',.
XGenAttNames IN VARCHAR2 default NULL,
XGenAttValues IN VARCHAR2 default NULL,
MirusAttNames IN VARCHAR2 default NULL,
MirusAttValues IN VARCHAR2 default NULL,
GenisysAttNames IN VARCHAR2 default NULL,
GenisysAttValues IN VARCHAR2 default NULL,
XGenModify IN VARCHAR2 default NULL,
MirusModify IN VARCHAR2 default NULL,
GenisysModify IN VARCHAR2 default NULL
)
IS
strSQLXGen VARCHAR (1000);
strSQLMirus VARCHAR (1000);
strSQLGenisys VARCHAR (1000);
nMaxMDMCode INTEGER.
ifExist INTEGER;
/******************************************************************************
NAME: proc_MDM_InsertCntryDetails
PURPOSE:
REVISIONS:
Worm Date Description of the author
--------- ---------- --------------- ------------------------------------
1.0 03/07/2009 1. Created this procedure.
NOTES:
Keywords to replace automatically available Auto:
Object name: proc_MDM_InsertCntryDetails
SYSDATE: 03/07/2009
Date and time: 03/07/2009, 19:11:20 and 03/07/2009-19:11:20
User name: (put in TOAD Options, editor of the procedure)
Name of the table: (defined in the dialog box "New PL/SQL object")
******************************************************************************/
BEGIN
COUNT (*) of SELECT INTO ifExist OF MDM_COUNTRY_MASTER;
IfExist IF = 0 THEN
SELECT 1 INTO nMaxMDMCode FROM DUAL;
ON THE OTHER
SELECT MAX (MDM_CODE) + 1 IN MDM_COUNTRY_MASTER nMaxMDMCode;
END IF;
IF Action = "add" THEN
INSERT INTO MDM_COUNTRY_MASTER(MDM_CODE,MDM_MASTER_CODE,MDM_DESCRIPTION,MDM_USER,MDM_EXIST,MDM_STATUS,MDM_ACTION,DAT_INSERT_DATE,DAT_INSERTED_BY)
VALUES(nMaxMDMCode,CntryMasterCode,CntryName,MDMUser,exist,Status,action,sysdate,Inserted_By);
strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
"VALUES (' |)" nMaxMDMCode | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen;
strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
"VALUES (' |)" nMaxMDMCode | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus;
strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
"VALUES (' |)" nMaxMDMCode | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Inserted_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys;
ON THE OTHER
UPDATE MDM_COUNTRY_MASTER
SET MDM_DESCRIPTION = CntryName, DAT_MODIFIED_BY = Modified_By, DAT_MODIFY_DATE = SYSDATE.
MDM_USER = MDMUser, MDM_ACTION = Action, MDM_STATUS = status MDM_EXIST = exist WHERE MDM_CODE = Mdm_Code;
COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 1 AND MDM_CODE = Mdm_Code;
IfExist IF = 0 THEN
strSQLXGen: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) XGenAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
' VALUES(' ||) Mdm_Code | ',' || '''' || "XGen | '''' || ',1,' || XGenAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLXGen;
ON THE OTHER
strSQLXGen: = "UPDATE MDM_COUNTRY_MAPPING SET | XGenModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 1';
EXECUTE IMMEDIATE strSQLXGen;
END IF;
COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 2 AND MDM_CODE = Mdm_Code;
IfExist IF = 0 THEN
strSQLMirus: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) MirusAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
' VALUES(' ||) Mdm_Code | ',' || '''' || "Mirus | '''' || ',2,' || MirusAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLMirus;
ON THE OTHER
strSQLMirus: = "UPDATE MDM_COUNTRY_MAPPING SET | MirusModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 2';
EXECUTE IMMEDIATE strSQLMirus;
END IF;
COUNT (*) of SELECT INTO ifExist FROM MDM_COUNTRY_MAPPING WHERE SYSTEM_CODE = 3 AND MDM_CODE = Mdm_Code;
IfExist IF = 0 THEN
strSQLGenisys: = ' INSERT IN MDM_COUNTRY_MAPPING (MDM_CODE, SYSTEM_NAME, SYSTEM_CODE,' |) GenisysAttNames | DAT_INSERTED_BY, DAT_INSERT_DATE) ' |
' VALUES(' ||) Mdm_Code | ',' || '''' || "Genisys | '''' || ',3,' || GenisysAttValues | ',' || '''' || Modified_By | '''' || SYSDATE)';
EXECUTE IMMEDIATE strSQLGenisys;
ON THE OTHER
strSQLGenisys: = "UPDATE MDM_COUNTRY_MAPPING SET | GenisysModify | ', DAT_MODIFY_DATE = SYSDATE, DAT_MODIFIED_BY =' | '''' || Modified_By | '''' || "WHERE MDM_CODE =' | ' Mdm_Code | "and SYSTEM_CODE = 3';
EXECUTE IMMEDIATE strSQLGenisys;
END IF;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHILE OTHERS THEN
-Consider recording the error and then re-raise
LIFT;
END proc_MDM_InsertCntryDetails;
/
Thank you>
WHERE mdm_code = mdm_code
>This will always be value true - similar to WHERE 1 = 1.
You typed it wrong or is the same as the variable column name? If they are the same test rename one of them.
Maybe you are looking for
-
gives the error the URL requested ' / ', is not valid, but I gave a valid format
I gave firefox 3.6.6 what seems to be a URL correctly formatted, namely http://www.3dfx.com. Firefox changes for http://www.3dfx.com/ I think that the added value / indicates he received a response from the URL I gave, but it indicates the requested
-
HP Pavilion 500-164 recovery disks came with instructions in Spanish, don't read not Spanish
Good afternoon everyone. I have a HP pavilion 500-164, barely a month and a hlaf old, which came in a kind of loop to the HP after a few minutes loading screen, a pink screen came up with a frown face alomng with a message that I have never read co
-
Missing unknown device after the upgrade of windows 8 to 8.1 pro
My laptop is HP Pavllion notebook. Product number is E0J99UA #ABA. It is a new laptop. I've updated to windows 8 to 8.1 pro and the driver stood as unknow device - location is PCI Express Root Comples That's what shows the 'events' tab in the prope
-
planning the installation of 240 GB SSD
I install windows 7 64 bit on SSD. where can I find drivers for network and etc for my in 3847 Inspiron? second question: what software do I need, so I can clone it or transfer my windows 8.1 in my new 250 GB of SSD drive size. ?
-
Windows cannot communicate with the device he resourse (primary DNS server).
Original title: primary dns. Help, please Windows cannot communicate with the device he resourse (primary DNS server) Please help me solve this problem