Select * from tbl where product like ('abc', 'def', 'russo');
Hi guys,.My requirement is I need to filter by providing a few details porduct date value and prod_id may vary with product as
prod_id product date
01 abc 01/2012
ABC 02 02/2012
Def 03 03/2012
How can we put several conditions in text using LIKE operator in the where clause of the sql query.
The union allows us to combine all sql queries, how can we filter by entering the date value.
SQL > select * from tbl where product like ('abc', 'def', 'russo');
Please provide any ideas on the same.
Thanks in advance!
-LK
Select * from tab1 where regexp_like(product,'^abc|def|rgh');
Tags: Database
Similar Questions
-
How to create a report based on the item selected from the list of selection?
Hello
I created a tables_LOV based on:
Select table_name table_name user_tab_cols r, d
where column_name like '% _type % '.
Then I created a ListOfTables page element, display in a selection list and pointing to tables_LOV.
I run the page, and I can choose the table I want in the drop-down list.
How to create a report based on the selected element? (ex: select * from selected_table)
Thanks in advance
Salah
Hi Salah,
Allright, take a look at this page: http://apex.oracle.com/pls/apex/f?p=vincentdeelen:collection_report
I think that simulates what you are trying to accomplish. I've implemented the simplest method I could think of.
The report is based on a collection of apex. If you are not familiar with this, you should study the documentation: APEX_COLLECTION
To recreate my example, you should:
(1) create a report (interactive) on your collection
SELECT * FROM APEX_collections WHERE collection_name = 'MY_COLLECTION'
(2) create a selection list page_item for the tables that you want to display (in my case, this is called "P38_TABLES")
(3) create a dynamic action that triggers on the evolution of your selection list page_item. Dynamic action must be a parade of PL/SQL procedure the following code:
declare l_query varchar2(4000); begin l_query := 'select * from '||:P38_TABLES; if apex_collection.collection_exists ( p_collection_name => 'MY_COLLECTION' ) then apex_collection.delete_collection ( p_collection_name => 'MY_COLLECTION' ); end if; apex_collection.create_collection_from_query ( p_collection_name => 'MY_COLLECTION' , p_query => l_query ); end;
Make sure that you add your page_item 'Page to send items' section.
(4) add a real extra action that makes an update of the report area.
Here are two photos describing the da:
http://www.vincentdeelen.com/images/OTN/OTN_COLLECTION_REPORT_DA1.PNG
http://www.vincentdeelen.com/images/OTN/OTN_COLLECTION_REPORT_DA2.PNG
Good luck and greetings,
Vincent
-
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.
This one works if there is only a single deptnumber stored in the table:SELECT * FROM emp WHERE deptno IN (Select CASE WHEN deptno like 'ALL' then Select ......... from selection where ID like :P13_ID)
ID is a sequence to define unique lines.SELECT * FROM emp WHERE depto IN (Select deptno from selection where ID like :P13_ID)
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.
-
Select only records where the column values are not all equal to zero
Hi everyone, it seems so easy, but it has left me speechless on the research in a way that is clean, easy to achieve. I know when someone replies, I'm going to kick me. So, let's assume this is what I have:
I need an external application around it or something which will select only 'Type 1'... that is, if all months are each equal to zero, do not include the record in the result set.with mytable as ( select 'Type 1' as itemtype, 'JAN' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'FEB' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'MAR' as monthname, 5 as theval from dual union all select 'Type 1' as itemtype, 'APR' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'MAY' as monthname, 4 as theval from dual union all select 'Type 1' as itemtype, 'JUL' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'AUG' as monthname, 0 as theval from dual union all select 'Type 1' as itemtype, 'SEP' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'OCT' as monthname, 7 as theval from dual union all select 'Type 1' as itemtype, 'NOV' as monthname, 1 as theval from dual union all select 'Type 1' as itemtype, 'DEC' as monthname, 2 as theval from dual union all select 'Type 2' as itemtype, 'JAN' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'FEB' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'MAR' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'APR' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'MAY' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'OCT' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'NOV' as monthname, 0 as theval from dual union all select 'Type 2' as itemtype, 'DEC' as monthname, 0 as theval from dual ) select itemtype, sum (case monthname when 'JAN' then theval else 0 end) as JAN, sum (case monthname when 'FEB' then theval else 0 end) as FEB, sum (case monthname when 'MAR' then theval else 0 end) as MAR, sum (case monthname when 'APR' then theval else 0 end) as APR, sum (case monthname when 'MAY' then theval else 0 end) as MAY, sum (case monthname when 'JUN' then theval else 0 end) as JUN, sum (case monthname when 'JUL' then theval else 0 end) as JUL, sum (case monthname when 'AUG' then theval else 0 end) as AUG, sum (case monthname when 'SEP' then theval else 0 end) as SEP, sum (case monthname when 'OCT' then theval else 0 end) as OCT, sum (case monthname when 'NOV' then theval else 0 end) as NOV, sum (case monthname when 'DEC' then theval else 0 end) as DEC from mytable group by itemtype order by itemtype
In summary to get a total of zero is not an option, because I could have-15 and + 15 in different columns, in which case, the recording should be displayed.
Something as simple as... 'not the case (oct = 0 and 0 nov and dec = 0...) at the end is all it seems to me necessary. I thought to add a case for each column clause, but that seems not very effective. Ideas?
Thanks in advance!
Mark
Edit... I know not what follows will work using the MINUS operator, but my actual query is really huge, and I don't want to have to write it twice...
{code}
Select
ItemType,
sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
sum (case monthname when "APR" then Val else 0 end) as APR.
sum (case when monthname 'MAY', then Val else 0 end) either.
sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
sum (case monthname when "JUL" then Val else 0 end) as JUL,.
sum (case monthname when "AUG" then Val else 0 end) as AUG.
sum (case monthname when "MS" then Val else 0 end) as MS.
sum (case monthname when "OCTS" then Val else 0 end) OCT.
sum (case monthname when "NOV" then Val else 0 end) as NOV.
sum (case monthname when 'DEC' then Val else 0 end) as DEC
FROM MyTable
Group of itemtype
less
Select
ItemType,
Jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
de)
Select
ItemType,
sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
sum (case monthname when "APR" then Val else 0 end) as APR.
sum (case when monthname 'MAY', then Val else 0 end) either.
sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
sum (case monthname when "JUL" then Val else 0 end) as JUL,.
sum (case monthname when "AUG" then Val else 0 end) as AUG.
sum (case monthname when "MS" then Val else 0 end) as MS.
sum (case monthname when "OCTS" then Val else 0 end) OCT.
sum (case monthname when "NOV" then Val else 0 end) as NOV.
sum (case monthname when 'DEC' then Val else 0 end) as DEC
FROM MyTable
Group of itemtype
)
where (oct = 0 & nov = 0 and dec = 0 and jan = 0 and 0 = Feb and mar = 0
apr = 0 and may = 0 and = 0 jun and Jul = 0 and aug = 0 and Ms = 0
)
order of itemtype
{code}
Change again... OK, I guess that I am answering my own question here, but I think that by using a WITH to write the main request once clause and then selecting * twice using the MINUS operator between where the second query is where (oct = 0, etc.) is what I need. If anyone has better suggestions, please let me know! Here's the logic of nickname for what I come up with to date...
{code}
WITH mainquery as (select all)
Select * from mainquery
less
Select * from mainquery where (oct = 0, nov = 0, etc...)
{code}
Thanks again!
Mark
Published by: user455268 on March 1, 2012 19:13
Published by: user455268 on March 1, 2012 19:16Hello
You can do it with a HAVING clause:
select itemtype, sum (case monthname when 'JAN' then theval else 0 end) as JAN, sum (case monthname when 'FEB' then theval else 0 end) as FEB, sum (case monthname when 'MAR' then theval else 0 end) as MAR, sum (case monthname when 'APR' then theval else 0 end) as APR, sum (case monthname when 'MAY' then theval else 0 end) as MAY, sum (case monthname when 'JUN' then theval else 0 end) as JUN, sum (case monthname when 'JUL' then theval else 0 end) as JUL, sum (case monthname when 'AUG' then theval else 0 end) as AUG, sum (case monthname when 'SEP' then theval else 0 end) as SEP, sum (case monthname when 'OCT' then theval else 0 end) as OCT, sum (case monthname when 'NOV' then theval else 0 end) as NOV, sum (case monthname when 'DEC' then theval else 0 end) as DEC from mytable group by itemtype HAVING MIN (theval) != 0 OR MAX (theval) != 0 order by itemtype ;
If the values are all 0, then the MIN and MAX will be 0.
If the MIN or MAX is not 0, the values are all 0.This assumes that the combination (itemtype, monthname) is unique, because it is in your sample data.
If this is not the case, start with a subquery that GROUPs BY itemtype, monthname, so that when you get to the main request, this combination will be unique. -
How to get data in the procedure after CREATE TABLE table1 AS SELECT * from table2
Hello
can any body tell me how to get the data in the new table created in the procedure. because it gives following error.
- Error (47,21): PL/SQL: ORA-00942: table or view does not exist
tableName: = "BCKUP_" | TO_CHAR (sysdate, 'ddmmrrrr');
tableDDL: = 'CREATE TABLE' | tableName. "AS SELECT * FROM Table1 where to_char(MSG_IN_TIME,''dd-mon-rrrr'') < sysdate - ' | daysNumber;
EXECUTE IMMEDIATE backUpDDL;
COMMIT;
DELETE FROM Table1;
How to select the data in the newly created table. as...
Select * from ". tableName;
Do not choose anything to get the number...
Just after backupDDL EXECUTE IMMEDIATE, simply refers to SQL % ROWCOUNT - who will be the number of lines.
Oh and DDL engages automatically, your commitment is redundant.
-
SELECT * FROM normal behavior of the parameter $ v
Make sure that your NLS settings a Sql * longer or Oracle Developer session:
SELECT * v PARAMETER $ WHERE name LIKE '% nls '.
returns no row is this normal behavior ?
Kind regards
Abdetu...Yes Chris :)
It is, as u suggested and here I gave the link to the solution with the steps to the person who has the same problem, I got hope it helps one day someone else
How can enter you right to LEFT (i.e. the Arab style) forms?
Best regards
Abdetu...
-
Insert into select * from table 3. -is on the agenda by the needless?
I've got an example of script, it will work for any table, so I don't bother with the full ddl.
----------------------------------------------------------------------------
create table test in select * from hotels where 1 = 2;
Insert into test select * from Hotels by city;
Select the city from the trial;
-drop table test is serving;
-----------------------------------------------------------------------------
The amazing thing is, that the city is ordered alphabetically,
but you would say it is that an operation order is irrelevant.
Any ideas on that?
This will still work?
Edited by: FourEyes on December 8, 2008 22:55
Edited by: FourEyes on 8 December 2008 22:56
Edited by: FourEyes on 8 December 2008 22:56Hello
The [SQL Oracle 10 language reference | http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#sthref9371] manual says:
«In regards to the ORDER BY clause from the subquery in the DML_table_expression_clause, you place your order is guaranteed only for the inserted rows and only within each extension table.» Orders new lines with regard to existing lines is not guaranteed. »
-
Original title: windows Vista SP2 is not start properly. Very, very slow and do not have access to open anything.
I was able to boot into safe mode and view the event viewer, and that's what he said:
./root/CIMV2
SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_Processor' AND TargetInstance.LoadPercentage > 99 0 x 80041003 Hi Noomcy,
1. don't you make changes before the show?
This problem occurs if the WMI filter is accessible without the necessary permissions. To resolve this problem, we recommend that you run the script inthis article and check the result.
See also Optimize Windows Vista for better performance
Visit our Microsoft answers feedback Forum and let us know what you think.
-
Query to select higher values, where LIKE clause is used
Oracle 10g
Ask for your help in the drafting of the request correctly.
I have 2 tables. The tables AddProjectPhase and AddProject. That's a lot to-several. Each project can have a predefined set of 4 different phases under him. Each phase has a start date and an end date. I am writing a report for the phases that have lasting more than in, for example, 3 months.
The following query works well for just a list of all the phases and the length of each phase. I am not able to change to select the phases that have a duration, for example, 3 months or more.
This is the query for a list of all the phases and the length of each phase which works very well.CREATE TABLE "ADDPROJECT" ( "VERSIONNO" NUMBER(*,0), "PROJID" VARCHAR2(20), "PROJNAME" VARCHAR2(60), "PROJSTARTDATE" DATE, "PROJSTATUS" VARCHAR2(20), "PROJENDDATE" DATE, "PROJENDTYPE" VARCHAR2(20), "PROJENDREASON" VARCHAR2(1000), "UCPROJECTMANAGER" VARCHAR2(20), "FROMDATE" DATE, "TODATE" DATE, "SRCHFIELD" VARCHAR2(20), "OPERATOR" VARCHAR2(20), "PARENTPROJID" VARCHAR2(20), "PROJHIDDENDATE" VARCHAR2(20), CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE ) CREATE TABLE "ADDPROJECTPHASE" ( "VERSIONNO" NUMBER(*,0), "PROJPHASEID" NUMBER(9,0), "PHASESTARTDATE" DATE, "PHASEENDDATE" DATE, "RRDATE" DATE, "PHASENAME" VARCHAR2(30), "PROJPHASESTATUS" VARCHAR2(20), "PROJID" VARCHAR2(20), "OPERATOR" VARCHAR2(20), "FROMDATE" DATE, "TODATE" DATE, "SRCHFIELD" VARCHAR2(20), "REVIEWCOMMENTS" VARCHAR2(1000), "PROJHIDDENDATE" VARCHAR2(20), "ISUEVALUATION" NUMBER(1,0), "SOLUTIONINGTEAMINVOLVEMENT" NUMBER(1,0), "ISUNAME" VARCHAR2(20), CONSTRAINT "PK_A63" PRIMARY KEY ("PROJPHASEID") ENABLE )
However, the query below changed to select all superior, for example, 3 months, translatesSELECT pp.phaseName "phasename", pp.phaseStartDate "phaseStartDate", pp.phaseEndDate "phaseEndDate", pp.projPhaseStatus "projPhaseStatus", ap.projID "projID", ap.projName "projName", ap.projHiddenDate "projHiddenDate", ap.projStartDate "projStartDate", CASE WHEN pp.phaseEndDate IS NOT NULL THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate) WHEN pp.phaseEndDate IS NULL THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate) ELSE null END "phaseMonths" FROM AddProjectPhase pp, AddProject ap WHERE ap.projID = pp.projID AND ap.projHiddenDate = pp.projHiddenDate ORDER BY ap.projID
ORA-00904: "PHASEMONTHS": invalid identifier
SELECT pp.phaseName, pp.phaseStartDate, pp.phaseEndDate FROM AddProjectPhase pp, AddProject ap WHERE ap.projID = pp.projID AND ap.projHiddenDate = pp.projHiddenDate AND PhaseMonths IN (SELECT (CASE WHEN pp.phaseEndDate IS NOT NULL THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate) WHEN pp.phaseEndDate IS NULL THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate) ELSE null END) AS PhaseMonths FROM AddProjectPhase pp, AddProject ap WHERE ap.projID = pp.projID AND ap.projHiddenDate = pp.projHiddenDate) ORDER BY ap.projID
The research of this?
select * from ( SELECT pp.phaseName "phasename" , pp.phaseStartDate "phaseStartDate" , pp.phaseEndDate "phaseEndDate" , pp.projPhaseStatus "projPhaseStatus" , ap.projID "projID" , ap.projName "projName" , ap.projHiddenDate "projHiddenDate" , ap.projStartDate "projStartDate" , CASE WHEN pp.phaseEndDate IS NOT NULL THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate) WHEN pp.phaseEndDate IS NULL THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate) ELSE null END "phaseMonths" FROM AddProjectPhase pp, AddProject ap WHERE ap.projID = pp.projID AND ap.projHiddenDate = pp.projHiddenDate ORDER BY ap.projID ) where "phaseMonths" >= 3
-
MySQL query - only select a field WHERE it is SEPARATE
Is there a way of msql to select ALL where somehing is SEPARATE
At the moment I have:
$sql = "SELECT * FROM Products WHERE product_month = '$product_month' ORDER BY product_depart_date";
What I need is:
$sql = "SELECT * FROM Products WHERE product_month = '$product_month' AND 'product_depart_date' IS SEPARATE ORDER BY product_depart_date";
I can't have her down as I need to get the product_id BUT only where product_departure date is SEPARATE
$sql = "SELECT DISTINCT product_departure_date FROM Products WHERE product_month = '$product_month' ORDER BY product_depart_date";
See you soon
Operating system
GROUP BY is similar to separate:
SELECT * from products WHERE product_month = '$product_month' GROUP BY product_depart_date ORDER BY product_depart_date
-
Select a view where CLOB is converted into VARCHAR2s of evil
So I create a view of a CLOB table such as:
CREATE OR REPLACE FORCE VIEW "ACTIVITY_TXT" ("NUMBER", "DESCRIPTION_TXT") AS
SELECT "NUMBER", dbms_lob.substr(description,4000,1) 'description_txt' from activitym1 where type = 'Assignment' or type = 'Resassignment ';
When I do a select right I see data no problem, but when I try to query against it more selectively:
Select count ("NUMBER") in the ACTIVITY_TXT where description_txt like 'of NONE. "
I constantly receive:
ORA-06502: PL/SQL: digital or value error: character string buffer too small
ORA-06512: at line 1
06502 00000 - "PL/SQL: digital error or the value of %s.
* Cause:
* Action:
I don't know what means this error and why I receive.
You use multibyte characters? Maximum string length in SQL is 4000 BYTES but your DBMS_LOB. SUBSTR asked 4000 CHARACTERS - a single two-byte character would be the malfunction of the query.
I suggest first to try with dbms_lob.substr(description,2000,1) and then looking for lines where the
LENGTHB (dbms_lob.substr(description, 2000, 1)) > 2000 or LENGTHB (dbms_lob.substr(description, 2000, 2001)) > 2000
I hope this helps.
-
What is to "select * from a subquery?
Hello
I'm a DBA and so I must first humble myself to all developers in this forum because my SQL skills aren't up to par with the rest of you.
That said, let me explain that we have a demand (remedy) where the seller has almost exclusively used inline views as follows.
I do not understand the purpose or reasoning behind it and I was wondering if someone could help me understand it better.
Unforutnately, overlooking the line, Oracle sql Profiler will not work on them and I can't create profiles for them, nor can I use OEM SQL Advisor to give me advice thereon.
(not that it matter anyway because we cannot change their code - but if the Profiler might work, at least I could create profiles for them).
SELECT * FROM ( SELECT T2179.C1,C536871040,C536871728,C536871793,C536871399,C536870944 ,C536871117,C536870918,C536870913,C536870926,C536871418,C3,C536871093 ,C536870928,C7,C536881176,C536870924,C536870925,C536871057,C536871139, C536870916,C4,C536881110,C536871247,C536871048,C536871049,C536871050, C536881056,C536870947,C536870945,C536871015,C536870919,C536871404,C536871394,C536881118 FROM T2179 WHERE ((T2179.C536871037 = 'Trouble') AND ((T2179.C536870944 = 'New') OR (T2179.C536870944 = 'Assigned') OR (T2179.C536870944 = 'On Hold') OR (T2179.C536870944 = 'Resolved')) AND (1 = 1)) ORDER BY C536871418 DESC,C3 DESC, 1 ASC ) WHERE ROWNUM <= 101
There are a variety of reasons why you might want to select * form a subquery. In the particular case, you've published, they do to enable then to do a top request N.
The subquery sorts the output by C536871418 DESC, DESC C3, 1 CAD. The outer query then selects the 101 all first lines in the sorted output. If he did not like that (in other words, the place where rownum)<= 101="" predicate="" was="" applied="" against="" the="" main="" query)="" then="" oracle="" would="" have="" selected="" the="" first="" 101="" rows="" it="" came="" across="" and="" then="" sorted="" them="" (rownum="" is="" always="" applied="" before="">=>
Although there are other ways to do this particular request for top N queries in general you should always a sorted subquery to determine which are the lines of 'top '.
John
-
Not the rows returned by the spatial query wrapped in SELECT * FROM...
Hello
When you run a query with SDO_EQUAL sub, I get a very strange behavior. The SDO_EQUAL query on its own works very well, but if I wrap in SELECT * from there, I get no results. If I wrap SDO_ANYINTERACT in SELECT * from there, I get the expected result.
It seems like the spatial index is used during the execution of the ordinary, but not when SDO_EQUAL request wrapped in SELECT * FROM. Weird. The spatial index is also not used when SDO_ANYINTERACT is wrapped in SELECT * FROM... so I don't know why that returns the correct answer.
I get this problem on 11.2.0.2 on Red Hat Linux 64-bit and 11.2.0.1 on Windows XP 32-bit (i.e., all versions of 11g I've tried). The query works as expected on 10.2.0.5 on Windows Server 2003 64-bit.
Any ideas?
Confused in Dublin (John)
Test case...
Here is the plan of the explain output for the query that works. Note that the spatial index is used.SQL> SQL> -- Create a table and insert the same geometry twice SQL> DROP TABLE sdo_equal_query_test; Table dropped. SQL> CREATE TABLE sdo_equal_query_test ( 2 id NUMBER, 3 geometry SDO_GEOMETRY); Table created. SQL> SQL> INSERT INTO sdo_equal_query_test VALUES (1, 2 SDO_GEOMETRY(3003, 81989, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), 3 SDO_ORDINATE_ARRAY(1057.39, 1048.23, 4, 1057.53, 1046.04, 4, 1057.67, 1043.94, 4, 1061.17, 1044.60, 5, 1060.95, 1046.49, 5, 1060.81, 1047.78, 5, 1057.39, 1048.23, 4))); 1 row created. SQL> SQL> INSERT INTO sdo_equal_query_test VALUES (2, 2 SDO_GEOMETRY(3003, 81989, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), 3 SDO_ORDINATE_ARRAY(1057.39, 1048.23, 4, 1057.53, 1046.04, 4, 1057.67, 1043.94, 4, 1061.17, 1044.60, 5, 1060.95, 1046.49, 5, 1060.81, 1047.78, 5, 1057.39, 1048.23, 4))); 1 row created. SQL> SQL> -- Setup metadata SQL> DELETE FROM user_sdo_geom_metadata WHERE table_name = 'SDO_EQUAL_QUERY_TEST'; 1 row deleted. SQL> INSERT INTO user_sdo_geom_metadata VALUES ('SDO_EQUAL_QUERY_TEST','GEOMETRY', 2 SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', 0, 100000, .0001), SDO_DIM_ELEMENT('Y', 0, 100000, .0001), SDO_DIM_ELEMENT('Z', -100, 4000, .0001)) 3 ,81989); 1 row created. SQL> SQL> -- Create spatial index SQL> DROP INDEX sdo_equal_query_test_spind; DROP INDEX sdo_equal_query_test_spind * ERROR at line 1: ORA-01418: specified index does not exist SQL> CREATE INDEX sdo_equal_query_test_spind ON sdo_equal_query_test(geometry) INDEXTYPE IS MDSYS.SPATIAL_INDEX; Index created. SQL> SQL> -- Ensure data is valid SQL> SELECT sdo_geom.validate_geometry_with_context(sdo_cs.make_2d(geometry), 0.0001) is_valid 2 FROM sdo_equal_query_test; IS_VALID -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TRUE TRUE 2 rows selected. SQL> SQL> -- Check query results using sdo_equal SQL> SELECT b.id 2 FROM sdo_equal_query_test a, sdo_equal_query_test b 3 WHERE a.id = 1 4 AND b.id != a.id 5 AND sdo_equal(a.geometry, b.geometry) = 'TRUE'; ID ---------- 2 1 row selected. SQL> SQL> -- Check query results using sdo_equal wrapped in SELECT * FROM SQL> -- Results should be the same as above, but... no rows selected SQL> SELECT * FROM ( 2 SELECT b.id 3 FROM sdo_equal_query_test a, sdo_equal_query_test b 4 WHERE a.id = 1 5 AND b.id != a.id 6 AND sdo_equal(a.geometry, b.geometry) = 'TRUE' 7 ); no rows selected SQL> SQL> -- So that didn't work. Now try sdo_anyinteract... this works ok SQL> SELECT * FROM ( 2 SELECT b.id 3 FROM sdo_equal_query_test a, sdo_equal_query_test b 4 WHERE a.id = 1 5 AND b.id != a.id 6 AND sdo_anyinteract(a.geometry, b.geometry) = 'TRUE' 7 ); ID ---------- 2 1 row selected. SQL> SQL> -- Now try a scalar query SQL> SELECT * FROM ( 2 SELECT b.id 3 FROM sdo_equal_query_test a, sdo_equal_query_test b 4 WHERE a.id = 1 5 AND b.id != a.id 6 ); ID ---------- 2 1 row selected. SQL> spool off
Here is the plan of the explain output for the query is not working. Note that the spatial index is not used.SQL> EXPLAIN PLAN FOR 2 SELECT b.id 3 FROM sdo_equal_query_test a, sdo_equal_query_test b 4 WHERE a.id = 1 5 AND b.id != a.id 6 AND sdo_equal(a.geometry, b.geometry) = 'TRUE'; Explained. SQL> @?/rdbms/admin/utlxpls.sql PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------ Plan hash value: 3529470109 ------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 1 | 7684 | 3 (0)| 00:00:01 | | 1 | RESULT CACHE | f5p63r46pbzty4sr45td1uv5g8 | | | | | | 2 | NESTED LOOPS | | 1 | 7684 | 3 (0)| 00:00:01 | |* 3 | TABLE ACCESS FULL | SDO_EQUAL_QUERY_TEST | 1 | 3836 | 3 (0)| 00:00:01 | |* 4 | TABLE ACCESS BY INDEX ROWID| SDO_EQUAL_QUERY_TEST | 1 | 3848 | 3 (0)| 00:00:01 | |* 5 | DOMAIN INDEX | SDO_EQUAL_QUERY_TEST_SPIND | | | 0 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter("B"."ID"!=1) 4 - filter("A"."ID"=1 AND "B"."ID"!="A"."ID") 5 - access("MDSYS"."SDO_EQUAL"("A"."GEOMETRY","B"."GEOMETRY")='TRUE') ..... other stuff .....
SQL> EXPLAIN PLAN FOR 2 SELECT * FROM ( 3 SELECT b.id 4 FROM sdo_equal_query_test a, sdo_equal_query_test b 5 WHERE a.id = 1 6 AND b.id != a.id 7 AND sdo_equal(a.geometry, b.geometry) = 'TRUE' 8 ); Explained. SQL> @?/rdbms/admin/utlxpls.sql PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------- Plan hash value: 1024466006 -------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 7684 | 6 (0)| 00:00:01 | | 1 | RESULT CACHE | 2sd35wrcw3jr411bcg3sz161f6 | | | | | | 2 | NESTED LOOPS | | 1 | 7684 | 6 (0)| 00:00:01 | |* 3 | TABLE ACCESS FULL| SDO_EQUAL_QUERY_TEST | 1 | 3836 | 3 (0)| 00:00:01 | |* 4 | TABLE ACCESS FULL| SDO_EQUAL_QUERY_TEST | 1 | 3848 | 3 (0)| 00:00:01 | -------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - filter("B"."ID"!=1) 4 - filter("A"."ID"=1 AND "B"."ID"!="A"."ID" AND "MDSYS"."SDO_EQUAL"("A"."GEOMETRY","B"."GEOMETRY")='TRUE') ..... other stuff .....
Yes, this is the bug 9740355. You can get a 11.2.0.1 patch, or wait for 11.2.0.3.
-
Problem with "select * from table" for dynamic IN the list
I have a 'for loop' based a query that does not work. The query is supposed to return the name of the table, the data type and the name of the column in the columns poses a number of name filters. The problem I have is when I run the query into a TOAD with:
schema_list value SCOTT, MED and the clause of 'in' as ' to (select * from table (DATAPUMP_UTIL.in_list_varchar2 (:schema_list))))»
The query returns the expected lines.
When I have it in my code as shown below it returns no rows. I don't know what hurts me, but any help would be great! I'm on Oracle 11.1.0.6.0.
Published by: BluShadow on June 29, 2011 16:11PROCEDURE export_schema_ondemand (schema_list VARCHAR2, encrypt_file NUMBER default 0, mask_sensitive_data NUMBER default 0) IS ... schema_list_t := my_package.in_list_varchar2(schema_list); ... for c1 in ( with ok_to_mask as ( select owner, table_name, column_name from all_tab_columns where owner in (select * from table(schema_list_t)) minus (SELECT c.owner, p.table_name, cc.column_name FROM all_cons_columns cc, all_constraints p, all_constraints c WHERE c.owner in (select * from table(schema_list_t)) c.constraint_type = 'R' AND p.owner = c.r_owner AND p.constraint_name = c.r_constraint_name AND cc.owner = c.owner AND cc.constraint_name = c.constraint_name AND cc.table_name = c.table_name UNION ALL SELECT c.owner, cc.table_name, cc.column_name FROM all_cons_columns cc, all_constraints p, all_constraints c WHERE p.owner in (select * from table(schema_list_t)) AND p.constraint_type in ('P','U') AND c.r_owner = p.owner AND c.r_constraint_name = p.constraint_name AND c.constraint_type = 'R' AND cc.owner = c.owner AND cc.constraint_name = c.constraint_name AND cc.table_name = c.table_name)) select atc.table_name as mask_tab, atc.column_name as mask_col, atc.data_type as mask_type from all_tab_columns atc, ok_to_mask otm where atc.owner = otm.owner and atc.table_name = otm.table_name and atc.column_name = otm.column_name and atc.owner in (select * from table(schema_list_t)) and ( atc.column_name like '%LAST%NAME%' or atc.column_name like '%FIRST%NAME%' or atc.column_name like '%NAME_LAST%' or atc.column_name like '%NAME_FIRST%' or atc.column_name like '%ENAME%' or atc.column_name like '%SSN%' or atc.column_name like '%DOB%' or atc.column_name like '%BIRTH%' ) and atc.column_name not like '%PHYSICIAN_%' and atc.column_name not like '%DR_%' and atc.column_name not like '%PROVIDER_%' and atc.column_name not like 'PRESCRIBER_%' ) loop ... FUNCTION in_list_varchar2 (p_in_list IN VARCHAR2) RETURN VARCHAR2_TT is l_tab VARCHAR2_TT := VARCHAR2_TT(); l_text VARCHAR2(32767) := p_in_list || ','; l_idx NUMBER; BEGIN LOOP l_idx := INSTR(l_text, ','); EXIT WHEN NVL(l_idx, 0) = 0; l_tab.extend; l_tab(l_tab.last) := TRIM(SUBSTR(l_text, 1, l_idx - 1)); l_text := SUBSTR(l_text, l_idx + 1); END LOOP; RETURN l_tab; END in_list_varchar2;
addition of {noformat}{noformat} tags. PLEASE READ {message:id=9360002} TO LEARN TO DO THIS YOURSELF.
Hello
If you have a query that works well when you launch it directly, and that breaks down when you start with a procedure, this can be a problem of privileges.
Points of view ALL_ * shows only the objects you have access, but using a procedure, privileges must be granted directly to the user and not with a role.
You should check the SELECT privileges to your user through roles and give them directly to the user.
Hope this will help.
Sylvie
-
SELECT from Bulk INSERT - Performance Clarification
I have 2 tables-emp_new & emp_old. I need to load all the data from emp_old to emp_new. Is there a transaction_id column in emp_new whose value should be extracted from a main_transaction table that includes a column of region Code. Something like -
TRANSACTION_ID REGION_CODE
------------------------- ------------
100. WE
AMER 101
APAC 102
My bulk insert query looks like this-
INSERT INTO emp_new
(col1,
col2,
...,
...,
...,
transaction_id)
SELECT
col1,
col2,
...,
...,
...,
* (Select transaction_id from main_transaction WHERE region_code = 'US') *.
Of emp_old
There are millions of rows that need to be loaded this way. I would like to know if the Subselection to fetch the transaction_id would be re-executed for each line, which would be very expensive and I'm actually looking for a way to avoid this. The main_transcation table is pre-loaded and its values will not change. Is there a way (via some SUSPICION) to indicate that the subselect should not re-run for each line?
On a different note, the implementation plan of the whole above INSERT looks like-
--------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU).
--------------------------------------------------------------------------
| 0 | INSERT STATEMENT. 11 M | 54 M | 6124 (4) |
| 1. FULL RESTRICTED INDEX SCAN FAST | EMPO_IE2_IDX | 11 M | 54 M | 6124 (4) |
--------------------------------------------------------------------------
EMPO_IE2_IDX-> Index on emp_old
I'm surprised to see that the main_transaction of the table is not in the execution plan at all. Does this mean that the subselect is not executed for each line? However, at least for the first reading, I suppose that the table must appear in the plan.
Can someone help me understand this?Why the explain command plan includes no information about the table of main_transaction
Can someone please clarify?As I said originally (and repeated in a later post) - probably because PLAN_TABLE is an older version.
More recent versions of PLAN_TABLE are required to correctly report "most recent" functions implementation plans.
Maybe you are looking for
-
How can I do an automatic response if I get an email
The company where I work is closing for two weeks (Christmas holidays). I want to know how I can create an automatic response to a person who is emailing me.
-
XCP MC ECU Connect code-301096
It is a similar problem to http://forums.NI.com/T5/automotive-and-embedded-networks/XCP-connection-problem/m-p/905869/highlight... but the solution is not the same. I want to connect to an ECU via XCP. XCP communication properties are stored in the
-
HP compaq tc4200 Tablet POWER ON PASSWORD
I have a problem with my HP compaq tc4200, I can't reset the power on password, I took it apart several times to get out the cmos battery and put it back, just bios is not reset. any other ideas on how to reset it?
-
I use Sax and presenter to of Dotty to play my karaoke disks. I have not bought a CD + G for awhile, and discs that I just bought will not play the words of graphic on-screen. Did anyone know what program or how to convert these disks so they will
-
HAVE high sampling frequency of trigger
Dear community I am using a microscope to tunnel effect from here feeding two voltage signals on my map of acquisition of data USB-6212 (Labview 2013 SP1). A voltage signal is the voltage applied to a piezo in the microscope (AI0). This signal drifti