SELECT in the where clause clause
Hello[Oracle 11g]
I've created a workflow in which the user can choose some variables for a report. Say (EMP-TABLE) as a first step the user must choose the Department. His selection is stored in another table called selection.
If the user selects all departments the Department of the column to the table of selection must contain "ALL". It is dynamic, because maybe some departments are added.
In my last step, the user must run a query against the emp table with the selction-table variables.
SELECT *
FROM emp
WHERE deptno IN
(Select
CASE WHEN deptno like 'ALL' then
Select ......... from selection where ID like :P13_ID)
This one works if there is only a single deptnumber stored in the table:SELECT *
FROM emp
WHERE depto IN
(Select deptno from selection where ID like :P13_ID)
ID is a sequence to define unique lines.So I need to know how to make the statement box:
If deptno table as 'ALL' selection and select deptno all of the emp table.
Decode them could be the solution too?
Hope you can help.
Thorsten wrote:
Try:SQL> insert into selection values(1,'10,20');
Now, we got the problem mentioned.
Published by: Thorsten on 29.04.2013 06:55
I edited my previous post... You can change the code as
SQL> SELECT empno,deptno
2 FROM emp e
3 where exists
4 (
5 select null
6 from selection s
7 where ( ','||s.deptno||',' like '%,'||e.deptno||',%' or s.deptno = 'ALL' )
8 and s.id like 1
9 );
EMPNO DEPTNO
---------- ----------
7369 20
7566 20
7782 10
7788 20
7839 10
7876 20
7902 20
7934 10
8 rows selected.
Tags: Database
Similar Questions
-
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.
-
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
-
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,
^_^
-
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? -
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 )
-
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; -
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.
-
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.
-
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;
-
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
-
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. -
Implementation of subqueries in the WHERE clause
Hi all
First of all, here are the technical info:
Oracle JDeveloper 12 c 12.1.3.0.0
Studio Edition Version 12.1.3.0.0
Build JDEVADF_12.1.3.0.0_GENERIC_140521.1008.S
Version of the component
========= =======
Oracle IDE 12.1.3.0.41.140521.1008
Java (TM) Platform 1.7.0_51
Support versioning 12.1.3.0.41.140521.1008
Secondly, the issue I'm facing is I'm trying to implement a query with three sous-sélections them in the (see image below) WHERE clause. I don't know what is the best way to implement something like this.
I have implemented this by creating a display object and add a view criteria. I put the whole SQL fragment in the view as a literal value criteria. Is there a better (or best?) approach to implement something like this?
This implementation is a problem is because as well as query tests out fine when I click on explain Plan even recognized that there is no bind variables in subqueries and allows me to.
When I run this test by the tester of AM, that it fails to recognize and define the binding (projCategory) variable that appears only in subqueries. All your comments and/or help is very appreciated.
Thank you
Vladimir
Vladimir, there is something wrong in the view Definition of criteria dialog box. The button "explain plan...". "running the whole statement generated (as a string) and returns the result. The entire statement is valid and returns the correct result. However, the view criteria, when it is running in the application work differently. Here the literal that you entered is not passed as a string, but the framework does something internally with her (it is necessary to do things as in the research of memory and other things). If you run the criteria to view in the app Tester I get
SQL error in the preparation of the statement. Instruction: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID from employees WHERE (((Employees.SALARY< :vc_temp_1="" )="" )="" )="" ):="" ora-01722:="" invalid="">
Accordingly, for the display criteria
employes.salaire< (select="" max(e2.salary)="" from="" employees="" e2="" where="" e2.department_id="">
As you can see the literal is passed as: vc_temp_1 and my binding variable is not visible at all. You can open an SR and ask for the support of working on it. I guess that they do not see a bug here as help for the dialog box says:
Literal
Select when you want to provide a value for the attribute, or when you want to set a default value for a lookup field specified by the user for a search query-by-example form.
When the criteria of view defines a search query for the user interface form, you can leave the field blank. In this case, the user will provide the value. Alternatively, you can provide a value that will act as a default value to the field search that the user will be able to substitute. This entry can include wildcards * or %.
When the attribute is of type Date, specify the value of the date in the format YYYY-MM-DD; for example, to December 16, 2010, enter 2010-12-16.
Here, it tells you that a value is expected. Your sub query is not interpreted, but is simply converted to the appropriate data type. In my example, I get an invalid number as expected.
So I guess my suggestion to use a custom sql statement stands.
Timo
Maybe you are looking for
-
When I want to connect to a site as soon as I put the cursor in the box, I get a list every every name I ever typed in this box. I'm not a specific typist, appears every spelling error I've ever done. It's boring. How can I get rid of them?
-
Don't know what you want in this space. Content of what?
-
Base station changes from green to orange
I have an airport Time Capsule and added a base station. Where plug the led is green and the pass immediately to amber. I thought it would be out of reach, but it does even in the room where the airport Time capsule.
-
Satellite S1700-500 - need drivers for Windows 2000
Hello, I need the drivers for Windows 2000 from the Satellite 1700-500 model. Where can I find it? Thank you
-
No response error and timeout device
Hi guys,. I'm quite desperate I'm trying to control a pump scaler, but this does not and gets the time-out expired before the operation is complete. (1) I checked that rate baud, bit, parity... are as indicated in the manual of the device. (2) the si