Query to search for students by group ID
HelloI have a table that has 2 columns student_id and Course_id.
Examples of data
Student_id Course_id
-------------------------------
1 > 1
1 > 2
1 > 3
1 > 4
2 > 1
2 > 3
3 > 1
3 > 2
3 > 4
I want to find students who have completed all course 1,3,4.
Try again with the following query.
WITH T AS (SELECT 1 stu_id , 1 stu_curs FROM DUAL
UNION ALL
SELECT 1 , 2 FROM DUAL
UNION ALL
SELECT 1 , 3 FROM DUAL
UNION ALL
SELECT 1 , 4 FROM DUAL
UNION ALL
SELECT 2 , 1 FROM DUAL
UNION ALL
SELECT 2 , 3 FROM DUAL
UNION ALL
SELECT 3 , 1 FROM DUAL
UNION ALL
SELECT 3 , 2 FROM DUAL
UNION ALL
SELECT 3 , 4 FROM DUAL
)
select stu_id from t where stu_curs in (1,3,4) group by stu_id having count(0) = 3;
Tags: Database
Similar Questions
-
query to search for the user of the application
Hello
What is the query to search for the user of the application in the sql command?
I tried the query belowselect app_user from dual;
Thank you.app_user invalid identifier
Hello skud,
The following SQL statement will give you the APP_USER which is an environmental variable in the APEX:SELECT v('APP_USER') FROM DUAL;
See if it works. As I used the syntax given in the triggers to record audit trail above and it works fine.
KiranPublished by: chubby Kiran June 11, 2011 04:08
Published by: chubby Kiran June 11, 2011 04:09
-
SQL query to search for the line that contains the identifier for each consecutive group
Hello
I'm on 11.2.0.3 Enterprise Edition.
I have a strange request here - do not know if this is possible without going to procedure...
Given these data of the sample:
create table test_status ( status varchar2(10), revision_id number, revision_timestamp timestamp); insert into test_status values ('PROPOSED', 1, systimestamp); insert into test_status values ('PROPOSED', 2, systimestamp); insert into test_status values ('PROPOSED', 3, systimestamp); insert into test_status values ('ACTIVE', 4, systimestamp); insert into test_status values ('ACTIVE', 5, systimestamp); insert into test_status values ('PROPOSED', 6, systimestamp); insert into test_status values ('PROPOSED', 7, systimestamp); insert into test_status values ('ACTIVE', 8, systimestamp); insert into test_status values ('ACTIVE', 9, systimestamp); insert into test_status values ('FINISHED', 10, systimestamp); insert into test_status values ('FINISHED', 11, systimestamp); insert into test_status values ('FINISHED', 12, systimestamp);
Gives me:
SQL> select * 2 from test_status 3 order by revision_id; STATUS REVISION_ID REVISION_TIMESTAMP ---------- ----------- ----------------------------- PROPOSED 1 25-SEP-14 04.49.47.954000 PM PROPOSED 2 25-SEP-14 04.49.47.962000 PM PROPOSED 3 25-SEP-14 04.49.47.966000 PM ACTIVE 4 25-SEP-14 04.49.47.969000 PM ACTIVE 5 25-SEP-14 04.49.47.972000 PM PROPOSED 6 25-SEP-14 04.49.47.976000 PM PROPOSED 7 25-SEP-14 04.49.47.979000 PM ACTIVE 8 25-SEP-14 04.49.47.982000 PM ACTIVE 9 25-SEP-14 04.49.47.987000 PM FINISHED 10 25-SEP-14 04.49.47.991000 PM FINISHED 11 25-SEP-14 04.49.47.996000 PM FINISHED 12 25-SEP-14 04.49.48.000000 PM 12 rows selected. ws selected.
I want to get this result:
STATUS REVISION_ID REVISION_TIMESTAMP ---------- ----------- ---------------------------- PROPOSED 3 25-SEP-14 04.49.47.966000 PM ACTIVE 5 25-SEP-14 04.49.47.972000 PM PROPOSED 7 25-SEP-14 04.49.47.979000 PM ACTIVE 9 25-SEP-14 04.49.47.987000 PM FINISHED 12 25-SEP-14 04.49.48.000000 PM
Then query the table ordered by Revision_Id, I would get the line containing the highest revision for each consecutive group of status values. I am able to get the line containing the highest revision for each separate status, value, but I can't deal with the scenario where a state value reappears later. In the case of the real world, it is a workflow and I need to take into account the fact that an element through the workflow may be redirected to the back front she proceeds forward again.
Hope it makes sense.
Thank you
John
Hi, John,.
John OToole (Dublin) wrote:
Hello
I'm on 11.2.0.3 Enterprise Edition.
I have a strange request here - do not know if this is possible without going to procedure...
...
Do not no stinkin' procedure:
WITH got_grp_id AS
(
SELECT the status, revision_id, revision_timestamp
ROW_NUMBER () OVER (ORDER BY revision_id)
-ROW_NUMBER () (PARTITION STATUS
ORDER BY revision_id
) AS grp_id
OF test_status
)
SELECT status
MAX (revision_id) AS revision_id
MAX (revision_timestamp) DUNGEON (DENSE_RANK LAST ORDER BY revision_id)
AS revision_timestamp
OF got_grp_id
GROUP BY status, grp_id
ORDER BY revision_id
;
For an explanation of the technique of Difference sets used here, see
-
Stuck on a sql query to search for records that have the same parent child records
Oracle 10 g 2 Enterprise Edition.
Hello
I'm writing a logic to find records in a parent table, who have the same values in a child table.
This is part of a larger application, but I am stuck on that part for now, so I have mocked some of the below simplified tables to capture the heart of the
the problem is that I'm stuck.
Let's say I have a responsible parent, child employee table table and there are a number of many relationships between them.
The aptly named Join_Table manages the relationship between them. If a manager can manage several employees, an employee can be managed by
many managers.
I have a feeling it's stupidly easy, but it seems to me having a bad episode of brain freeze today!
If I ask for Manager John, so I want to find other managers who manage the exact list and even employees.-- parent table CREATE TABLE manager ( id number primary key, name varchar2(100)); -- child table CREATE TABLE employee ( id number primary key, name varchar2(100)); -- link table CREATE TABLE join_table ( manager_id NUMBER, employee_id NUMBER, CONSTRAINT join_table_pk PRIMARY KEY (manager_id, employee_id), CONSTRAINT manager_fk FOREIGN KEY (manager_id) REFERENCES manager(id), CONSTRAINT employee_fk FOREIGN KEY (employee_id) REFERENCES employee(id) ); -- Insert some managers INSERT INTO manager (id, name) VALUES (1, 'John'); INSERT INTO manager (id, name) VALUES (2, 'Bob'); INSERT INTO manager (id, name) VALUES (3, 'Mary'); INSERT INTO manager (id, name) VALUES (4, 'Sue'); INSERT INTO manager (id, name) VALUES (5, 'Alan'); INSERT INTO manager (id, name) VALUES (6, 'Mike'); -- Insert some employees INSERT INTO employee (id, name) VALUES (101, 'Paul'); INSERT INTO employee (id, name) VALUES (102, 'Simon'); INSERT INTO employee (id, name) VALUES (103, 'Ken'); INSERT INTO employee (id, name) VALUES (104, 'Kevin'); INSERT INTO employee (id, name) VALUES (105, 'Jack'); INSERT INTO employee (id, name) VALUES (106, 'Jennifer'); INSERT INTO employee (id, name) VALUES (107, 'Tim'); -- Insert the links -- John manages Paul, Simon, Ken INSERT INTO join_table (manager_id, employee_id) VALUES (1, 101); INSERT INTO join_table (manager_id, employee_id) VALUES (1, 102); INSERT INTO join_table (manager_id, employee_id) VALUES (1, 103); -- Bob manages Paul, Simon, Kevin, Jack INSERT INTO join_table (manager_id, employee_id) VALUES (2, 101); INSERT INTO join_table (manager_id, employee_id) VALUES (2, 102); INSERT INTO join_table (manager_id, employee_id) VALUES (2, 104); INSERT INTO join_table (manager_id, employee_id) VALUES (2, 105); -- Mary manages Jennifer, Tim INSERT INTO join_table (manager_id, employee_id) VALUES (3, 106); INSERT INTO join_table (manager_id, employee_id) VALUES (3, 107); -- Sue manages Jennifer, Tim INSERT INTO join_table (manager_id, employee_id) VALUES (4, 106); INSERT INTO join_table (manager_id, employee_id) VALUES (4, 107); -- Alan manages Paul, Simon, Ken, Jennifer, Tim INSERT INTO join_table (manager_id, employee_id) VALUES (5, 101); INSERT INTO join_table (manager_id, employee_id) VALUES (5, 102); INSERT INTO join_table (manager_id, employee_id) VALUES (5, 103); INSERT INTO join_table (manager_id, employee_id) VALUES (5, 106); INSERT INTO join_table (manager_id, employee_id) VALUES (5, 107); -- Mike manages Paul, Simon, Ken INSERT INTO join_table (manager_id, employee_id) VALUES (6, 101); INSERT INTO join_table (manager_id, employee_id) VALUES (6, 102); INSERT INTO join_table (manager_id, employee_id) VALUES (6, 103); -- For sanity CREATE UNIQUE INDEX employee_name_uidx ON employee(name);
Answer should be Mike.
If I ask for Manager of Mary, the answer should be Sue.
This query will give me the list of managers who manage some of the same employees as John, but not the same employees accurate...
I thought about using set operations to find managers with a list of employees less than my employees is null and where my employees under their list of employees is null. But there must be an easier way more elegant.SELECT DISTINCT m.name AS manager FROM manager m, join_table jt, employee e WHERE m.id = jt.manager_id AND jt.employee_id = e.id AND e.id IN ( SELECT e.id FROM manager m, join_table jt, employee e WHERE m.id = jt.manager_id AND jt.employee_id = e.id AND m.name = 'John') ORDER BY 1;
Any ideas?
BTW, I need to run as a batch on tables with > 20 million rows so the efficiency of queries is key.What about...
WITH manager_list AS ( SELECT name, LTRIM(MAX(SYS_CONNECT_BY_PATH(id,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees FROM (SELECT m.name, e.id, ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr, ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev FROM manager m, join_table jt, employee e WHERE m.id = jt.manager_id AND jt.employee_id = e.id AND m.name = :P_MANAGER) GROUP BY name CONNECT BY prev = PRIOR curr AND name = PRIOR name START WITH curr = 1 ), all_list AS ( SELECT name, LTRIM(MAX(SYS_CONNECT_BY_PATH(id,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees FROM (SELECT m.name, e.id, ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr, ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev FROM manager m, join_table jt, employee e WHERE m.id = jt.manager_id AND jt.employee_id = e.id) GROUP BY name CONNECT BY prev = PRIOR curr AND name = PRIOR name START WITH curr = 1 ) SELECT a.* FROM manager_list m, all_list a WHERE m.employees = a.employees
Would be easier in 11g, but I do not have a facility here so this is based on 10g.
See you soon
Ben
-
Query to search for users based on the State of the resource
Hi all
I'm working on version 9 x IOM. I need to find all the users of a resource that is in "Ready" status in the profile of their resources
Let say resource Genetiquea is here and for some users of the status of this resource in their resources profile is in "ready". I want to get these users.
Melyssa, help me with this SQL query.
Thank you
MadhuTry this query:
Select usr.usr_login, obj.obj_name, ost.ost_status, usr, obj, obi, Ouedraogo, ost where usr.usr_key = oiu.usr_key and obi.obi_key = oiu.obi_key and obi.obj_key = obj.obj_key and ost.ost_key = oiu.ost_key and obj.obj_name ='' You can add: and ost.ost_status =
to find the status as well. Kind regards
GP -
Query to search for recursive data
Hello
I have a table called orders that has two columns, orderid and originalorderid. the data from this column as below:
OrderId Active OriginalOrderId
6 0
11 6 0
14-11-1
I want to write a query such that when I pass the orderid = 14 it returns me OrderID 6 and 11 6 being the first orderid that changed 11 orderid, then 14 orderid.
How can I write such a request.
Please notify.
Thank you
ReenaHello
@ Centinel: thanks for you Centinel SAMPLES.
WITH orders AS ( SELECT 6 AS ORDERID, 0 AS ORIGINALORDERID, NULL AS ACTIVE FROM DUAL UNION ALL SELECT 11 AS ORDERID, 6 AS ORIGINALORDERID, 0 AS ACTIVE FROM DUAL UNION ALL SELECT 14 AS ORDERID, 11 AS ORIGINALORDERID, 1 AS ACTIVE FROM DUAL ) SELECT max(ltrim(SYS_CONNECT_BY_PATH(ORDERS.ORDERID, ','),','))keep(dense_rank last order by level )res FROM ORDERS START WITH ORDERID != 14 CONNECT BY ORDERID = PRIOR ORIGINALORDERID / RES -------------------------------------------------------------------------------- 11,6 SQL>
-
SQL query to search for a single line
Hi All-
I have a requirement where I have to get the id who subscribe only to a single course based on data below.
ID courses
103812 CFH
102968 REP
103812 DFH
DFH 102968
103071 DFH
CFH 102968CREATE TABLE classes
(IDENTIFICATION NUMBER,
course VARCHAR2 (3));insert into class values (103812, "CFH");
insert into class values (102968, "REP");
insert into class values (103812, "DFH");
insert into class values (102968, "DFH");
insert into class values (103071, "DFH");
insert into class values (102968, "CFH");SELECT THE ID
IN THE COURSE OF
GROUP BY ID
AFTER HAVING COUNT (RACE) = 1; -
Python script to search for users who belong to a group of weblogic
Hello
We know
Python script to search for users who belong to a particular group in weblogic
That's what I showed you already. You just need to add the function connect() and disconnect() around it and evaluate the slider that went back.
If you don't want to learn how to write your own script and that you just want to use an existing one, try this one Weblogic Scripting Tool 101: WLST list users, groups, and users in groups
-
Can I create a Web site using Muse where classmates can submit their projects photo and other students can search for these photos using keywords?
You need a dynamic Server backend. You can't do it just with Muse. You can connect to one of the catalyst for business advanced accounts to implement these features or use widgets from third party services. Otherwise look you in systems such as Joomla, Typo3, Wordpress etc. and not even set up with muse.
Mylenium
-
vCAC 6.1 Catalogue right - cannot search for or select users or group?
I want to install vCAC 6.1 from scratch and try to entitle a group of users for my first article in catalog. When I'm on the Administration > catalog management > rights tab and type "domain admins" ordomain\domain admins"to search for a user I just get"no data to display.
I thought that my source of identity was the issue then I double checked that...
And the strange thing is that I can seek this identity store when I'm under Administration > groups
I don't know why I can't find users and groups above, but I can look for them in the admin > groups option. I have been stuck on this for about a day and can't get anywhere. I restarted the identity goes, the vcac goes and the iaas server. The logs will show that nothing is wrong either.
I was walking around videos from youtube by Yves Sandfort. I watched all the videos of the series and followed, but at 10:08 in the video, I get to a stopping point.
VCAC VMware 6.0 - based hypervisor Blueprint by Yves Sandfort - YouTube
I am new to vCAC so I could have done something wrong. I hope that its simple. Let me know. Thank you!
JoeJust make sure, but domain administrators have user rights in the Group of companies to ensure that this right is? If they have not so you will not be able to grant them rights to this right.
-
Internationalization of the search for the af:query component fields
HelloI dropped a component af:query on my page. I have a requirement that when the browser is English, label of query components search fields must be in English, and if the browser is in Arabic that they must appear in the Arabic language. Please help me to know how this can be achieved.
Thanks and greetings
Rati
Hello
It's a simple matter to create local resource bundles.
I guess you have indicators on the elements of the model installation check that the attributes of the View object. If so, you will see a ModelBundle.properties (if your model project called model). Create a copy based on the locale of this property file and customize the labels.
Read more here: http://docs.oracle.com/cd/E41362_01/web.1111/b31974/bcquerying.htm#CEGBFHJC
-
Search for files based on the flow
Hi, I would like to be able to search for specific files mp3 and m4a files based on their bitrate, IE search for files with a bitrate to 128KBit.
I don't know, but is it possible under Windows Vista, or do I need another tool to do?
Thank you
Hello trotskyicepick,
Windows Search does not include a searchable property for the bitrate, but Windows Explorer can indicate the rate on view Mp3 files. For example, you can sort and filter the search results by bit rate and group your files in this way.
For example, if the files in question are in your folder of music and its subfolders, click music in the left pane of Windows Explorer. Now paste this query into the search engine:
ext:MP3
Now, right-click on a column heading in the right pane and add the property of spleen in the view. Click the bitrate column header to sort the display rate. Now click the drop down menu on the same header and choose "near CD quality' in the list. This filter the search results so that only files recorded to 128 or more appear.
Unfortunately, the Vista does not support the M4a format, so speeds of transmission of these files are not visible in Windows Explorer.
Mr. Doug in New Jersey
-
Need help with the search for special characters in oracle text
Hi all
Oracle 11g sql developer 4.0 help
I am facing this challenge where Oracle text when it comes to searching for text that contains a special character.
What I've done so far with the help of http://www.orafaq.com/forum/t/162229/
"CREATE TABLE"SOS" COMPANY ".
(SELECT "COMPANY_ID" NUMBER (10,0) NOT NULL,)
VARCHAR2 (50 BYTE) "COMPANY."
VARCHAR2 (50 BYTE) "ADDRESS1"
VARCHAR2 (10 BYTE) "ADDRESS2"
VARCHAR2 (40 BYTE) 'CITY ',.
VARCHAR2 (20 BYTE) 'STATE ', HE SAID.
NUMBER (5.0) "ZIP".
) CREATION OF IMMEDIATE SEGMENT
PCTFREE, PCTUSED, INITRANS 40 10 1 MAXTRANS 255 NOCOMPRESS SLAUGHTER
STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS USER_TABLES DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT 1)
TABLESPACE 'USERS ';
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (1, 'LSG SOLUTIONS LLC', null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (2,' LOVE "S TRAVEL', null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (3, 'DEVON ENERGY', null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (4, 'SONIC INC', null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (5, "MSCI", null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (6, 'ERNEST AND YOUNG', null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (7, "JOHN DEER", null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (8,'Properties@Oklahoma, LLC', null, null, null, null, null);
Insert into COMPANY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (9, 'D.D.T L.L.C.', null, null, null, null, null);
BEGIN
CTX_DDL. CREATE_PREFERENCE ("your_lexer", "BASIC_LEXER");
CTX_DDL. SET_ATTRIBUTE ("your_lexer", "' SKIPJOINS,"., @-"'); -to jump. , @ - ' symbols
END;
/
CREATE INDEX my_index2 ON COMPANY (COMPANY_NAME)
INDEXTYPE IS CTXSYS. CONTEXT IN PARALLEL
PARAMETERS ("LEXER your_lexer");
SELECT company_name FROM company WHERE CATSEARCH(company.COMPANY_NAME, 'LLC','') > 0 ORDER BY company.COMPANY_ID;
output
company_name
1 LSG SOLUTIONS LLC
2 Properties@Oklahoma, LLC
only 2 rows back but must return 3
It helps if you post a copy and paste of effective enforcement of the full code, including the results. You posted an index of context with the query with catsearch, which requires a ctxcat index. You must be a context clue that you did not post and did not add your lexer to. The following table shows it returns all the lines of 3 as planned using either a with catsearch ctxcat index or a context index with contains, as long that you include the lexer in your create index. You must also be sure that the index is created, or synchronized after inserting or updating data.
Scott@ORCL >-version:
Scott@ORCL > SELECT banner version of v$.
BANNER
--------------------------------------------------------------------------------
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
AMT for 64-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
5 selected lines.
Scott@ORCL >-table and the test data:
Scott@ORCL > CREATE TABLE 'SOCIETY '.
2 ("COMPANY_ID" NUMBER (10,0) NULL NOT ACTIVATE,)
3 'COMPANY_NAME' VARCHAR2 (50 BYTE),
VARCHAR2 (50 BYTE) 4 "ADDRESS1"
5 "ADDRESS2" VARCHAR2 (10 BYTE),
VARCHAR2 (40 BYTE) 6 'CITY',
7 VARCHAR2 (20 BYTE) 'STATE ', HE SAID.
NUMBER (5.0) 8 'ZIP '.
(9) THE CREATION OF IMMEDIATE SEGMENT
PCTFREE 10 10 PCTUSED 40 INITRANS, MAXTRANS NOCOMPRESS SLAUGHTER 1 255
11 STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
12 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS USER_TABLES DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT 1)
TABLESPACE 13 "USERS."
Table created.
Scott@ORCL > START
2 insert in SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (1, 'LSG SOLUTIONS LLC', null, null, null, null, null);
3 insert in SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (2,' LOVE "S TRAVEL', null, null, null, null, null);
4 insert into SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (3, 'DEVON ENERGY', null, null, null, null, null);
5 insert into SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (4, 'SONIC INC', null, null, null, null, null);
6 insert in SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (5, "MSCI", null, null, null, null, null);
7 insert into SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (6, 'ERNEST AND YOUNG', null, null, null, null, null);
8 insert in SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (7, "JOHN DEER", null, null, null, null, null);
9 insert in SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (8,'Properties@Oklahoma, LLC', null, null, null, null, null);
10 insert into SOCIETY (COMPANY_ID, COMPANY_NAME, Address1, Address2, CITY, STATE, ZIP) values (9, 'D.D.T L.L.C.', null, null, null, null, null);
11 END;
12.
PL/SQL procedure successfully completed.
Scott@ORCL >-lexer:
Scott@ORCL > START
CTX_DDL 2. CREATE_PREFERENCE ("your_lexer", "BASIC_LEXER");
CTX_DDL 3. SET_ATTRIBUTE ("your_lexer", "' SKIPJOINS,"., @-"'); -to jump. , @ - ' symbols
4 END;
5.
PL/SQL procedure successfully completed.
Scott@ORCL >-ctxcat index and using catsearch queries:
Scott@ORCL > CREATE INDEX my_index2 ON COMPANY (COMPANY_NAME)
2 INDEXTYPE IS CTXSYS. CTXCAT PARALLEL
3 PARAMETERS ("LEXER your_lexer");
The index is created.
Scott@ORCL > SELECT
2 company_name
3 the COMPANY
4. WHERE the CATSEARCH (company.COMPANY_NAME, 'LLC', ") > 0
5 ORDER BY company.COMPANY_ID;
COMPANY_NAME
--------------------------------------------------
LSG SOLUTIONS LLC
Properties@Oklahoma, LLC
D.D.T L.L.C.
3 selected lines.
Scott@ORCL >-context and using the query index contains:
Scott@ORCL > CREATE INDEX my_index3 ON COMPANY (COMPANY_NAME)
2 INDEXTYPE IS CTXSYS. CONTEXT IN PARALLEL
3 PARAMETERS ("LEXER your_lexer");
The index is created.
Scott@ORCL > SELECT
2 company_name
3 the COMPANY
4 WHERE CONTAINS (company.COMPANY_NAME, 'LLC') > 0
5 ORDER BY company.COMPANY_ID;
COMPANY_NAME
--------------------------------------------------
LSG SOLUTIONS LLC
Properties@Oklahoma, LLC
D.D.T L.L.C.
3 selected lines.
-
Using synonyms in the search for name
Hello
I try to use synonyms in an oracle namesearch. Set up a seqarch name as in the second example described in the developer's guide to the oracle text to http://download.oracle.com/docs/cd/E18283_01/text.112/e16594/search.htm application
Now the name, for I am looking can hold one '&', for example 'B & V '.
I would like to find this text when I enter "B & V", B & V' or 'B and V.
I found a thread on how to set up a thesaurus with synonyms for '&' and 'and' to 'and' and ampersand or special characters
Now I'm wondering how to combine this.
Thanks for the help in advance,
DirkYour change was correct and it works. For reserved words in the braces enclosing aims to tell Oracle Text as text rather than apply the special meaning they have as reserved words. Since "und" is not a reserved word, it didn't need to be escaped by placing braces. When you set "&", then "und" synonymously as you did the search for 'B und V' correctly found "B and V, as in the modified below demo. In this particular case, the search might work without applying the format_string, but you need to keep it in the query so that it is applied to these values in need, for example, if you searched for "B & V' or 'B & V".
SCOTT@orcl_11gR2> create table emp ( 2 first_name varchar2(30), 3 middle_name varchar2(30), 4 last_name varchar2(30), 5 email varchar2(30), 6 phone varchar2(30)); Table created. SCOTT@orcl_11gR2> -- added row of data: SCOTT@orcl_11gR2> set define off SCOTT@orcl_11gR2> insert into emp values 2 ('Jane', 'Doe', 'B & V', '[email protected]', '321-654-0987'); 1 row created. SCOTT@orcl_11gR2> SCOTT@orcl_11gR2> create or replace procedure empuds_proc 2 (rid in rowid, tlob in out nocopy clob) is 3 tag varchar2(30); 4 phone varchar2(30); 5 begin 6 for c1 in (select FIRST_NAME, MIDDLE_NAME, LAST_NAME, EMAIL, PHONE 7 from emp 8 where rowid = rid) 9 loop 10 tag :='
'; 11 dbms_lob.writeappend(tlob, length(tag), tag); 12 if (c1.EMAIL is not null) then 13 dbms_lob.writeappend(tlob, length(c1.EMAIL), c1.EMAIL); 14 end if; 15 tag :=' '; 16 dbms_lob.writeappend(tlob, length(tag), tag); 17 tag :=''; 18 dbms_lob.writeappend(tlob, length(tag), tag); 19 if (c1.PHONE is not null) then 20 phone := nvl(REGEXP_SUBSTR(c1.PHONE, '\d\d\d\d($|\s)'), ' '); 21 dbms_lob.writeappend(tlob, length(phone), phone); 22 end if; 23 tag :=' '; 24 dbms_lob.writeappend(tlob, length(tag), tag); 25 tag :=''; 26 dbms_lob.writeappend(tlob, length(tag), tag); 27 if (c1.FIRST_NAME is not null) then 28 dbms_lob.writeappend(tlob, length(c1.FIRST_NAME), c1.FIRST_NAME); 29 dbms_lob.writeappend(tlob, length(' '), ' '); 30 end if; 31 if (c1.MIDDLE_NAME is not null) then 32 dbms_lob.writeappend(tlob, length(c1.MIDDLE_NAME), c1.MIDDLE_NAME); 33 dbms_lob.writeappend(tlob, length(' '), ' '); 34 end if; 35 if (c1.LAST_NAME is not null) then 36 dbms_lob.writeappend(tlob, length(c1.LAST_NAME), c1.LAST_NAME); 37 end if; 38 tag :=' '; 39 dbms_lob.writeappend(tlob, length(tag), tag); 40 end loop; 41 end; 42 / Procedure created. SCOTT@orcl_11gR2> show errors No errors. SCOTT@orcl_11gR2> begin 2 ctx_ddl.create_preference('empuds', 'user_datastore'); 3 ctx_ddl.set_attribute('empuds', 'procedure', 'empuds_proc'); 4 ctx_ddl.set_attribute('empuds', 'output_type', 'CLOB'); 5 end; 6 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> begin 2 ctx_ddl.create_section_group('namegroup', 'BASIC_SECTION_GROUP'); 3 ctx_ddl.add_ndata_section('namegroup', 'fullname', 'fullname'); 4 ctx_ddl.add_ndata_section('namegroup', 'phone', 'phone'); 5 ctx_ddl.add_ndata_section('namegroup', 'email', 'email'); 6 end; 7 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> begin 2 ctx_thes.create_thesaurus ('nicknames'); 3 ctx_thes.create_relation ('nicknames', 'John', 'syn', 'Jon'); 4 end; 5 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> SCOTT@orcl_11gR2> -- added synonyms to thesaurus: SCOTT@orcl_11gR2> begin 2 ctx_thes.create_relation ('nicknames', '&', 'syn', 'and'); 3 ctx_thes.create_relation ('nicknames', '&', 'syn', 'und'); 4 end; 5 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> SCOTT@orcl_11gR2> begin 2 ctx_ddl.create_preference('NDATA_WL', 'BASIC_WORDLIST'); 3 ctx_ddl.set_attribute('NDATA_WL', 'NDATA_ALTERNATE_SPELLING', 'FALSE'); 4 ctx_ddl.set_attribute('NDATA_WL', 'NDATA_BASE_LETTER', 'TRUE'); 5 ctx_ddl.set_attribute('NDATA_WL', 'NDATA_THESAURUS', 'NICKNAMES'); 6 ctx_ddl.set_attribute('NDATA_WL', 'NDATA_JOIN_PARTICLES', 7 'de:di:la:da:el:del:qi:abd:los:la:dos:do:an:li:yi:yu:van:jon:un:sai:ben:al'); 8 end; 9 / PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> create index name_idx on emp (first_name) 2 indextype is ctxsys.context 3 parameters 4 ('datastore empuds 5 section group namegroup 6 wordlist ndata_wl'); Index created. SCOTT@orcl_11gR2> SCOTT@orcl_11gR2> -- added function to format search string: SCOTT@orcl_11gR2> create or replace function format_string 2 (p_string in varchar2) 3 return varchar2 4 as 5 v_string varchar2 (32767) := ' ' || p_string || ' '; 6 begin 7 -- add extra spaces around ampersand: 8 v_string := replace (v_string, '&', ' & '); 9 -- remove duplciate spaces: 10 while instr (v_string, ' ') > 0 11 loop 12 v_string := replace (v_string, ' ', ' '); 13 end loop; 14 -- add { and } around each reserved word: 15 for r in 16 (select keyword, 17 ' ' || keyword || ' ' keyword2 18 from v$reserved_words) 19 loop 20 v_string := replace (upper (v_string), r.keyword2, ' {' || r.keyword || '} '); 21 end loop; 22 return ltrim (rtrim (v_string)); 23 end format_string; 24 / Function created. SCOTT@orcl_11gR2> show errors No errors. SCOTT@orcl_11gR2> -- example of usage of function: SCOTT@orcl_11gR2> select format_string ('B und V') from dual; FORMAT_STRING('BUNDV') -------------------------------------------------------------------------------- B UND V 1 row selected. SCOTT@orcl_11gR2> SCOTT@orcl_11gR2> -- query modified to apply foramt_string function to :name variable: SCOTT@orcl_11gR2> var name varchar2(80); SCOTT@orcl_11gR2> exec :name := 'B und V' PL/SQL procedure successfully completed. SCOTT@orcl_11gR2> column first_name format a10 SCOTT@orcl_11gR2> column middle_name format a11 SCOTT@orcl_11gR2> column last_name format a9 SCOTT@orcl_11gR2> column phone format a12 SCOTT@orcl_11gR2> column email format a22 SCOTT@orcl_11gR2> select first_name, middle_name, last_name, phone, email, scr 2 from (select /*+ FIRST_ROWS */ 3 first_name, middle_name, last_name, phone, email, score(1) scr 4 from emp 5 where contains 6 (first_name, 7 'ndata (phone,' || format_string (:name) || ') OR 8 ndata (email,' || format_string (:name) || ') OR 9 ndata (fullname,' || format_string (:name) || ')', 10 1) > 0 11 order by score (1) desc) 12 where rownum <= 10; FIRST_NAME MIDDLE_NAME LAST_NAME PHONE EMAIL SCR ---------- ----------- --------- ------------ ---------------------- ---------- Jane Doe B & V 321-654-0987 [email protected] 97 1 row selected. SCOTT@orcl_11gR2> -
Search for an exact match without additional words
Hello world
is it possible to know if a tag contains a certain word or phrase and nothing else? For example the search for all documents with the title "foo" should match all documents containing < title > foo < /title > but not documents containing something like < title > foo bar < / title >. I tried something like "(foo ~ (% ~ foo)) IN the title ' but I get an error"extension of generic query results in terms too", so using a wildcard character is no option here. Any ideas?Another method would be to use extractvalue to limit lines. He would still use the text index to get the rows with foo inside, then extractvalue would limit only the rows where the word foo is in. Which would eliminate the need for a procedure or user_datastore or increasing the size of the index. Please see the demo below.
SCOTT@orcl_11gR2> create table documents 2 (text varchar2 (45)) 3 / Table created. SCOTT@orcl_11gR2> insert all 2 into documents values ('
foo ') 3 into documents values ('foo bar ') 4 into documents values ('bar foo ') 5 select * from dual 6 / 3 rows created. SCOTT@orcl_11gR2> insert into documents 2 select '' || object_name || ' ' 3 from all_objects 4 / 76012 rows created. SCOTT@orcl_11gR2> create index test_idx 2 on documents (text) 3 indextype is ctxsys.context 4 parameters 5 ('section group ctxsys.auto_section_group') 6 / Index created. SCOTT@orcl_11gR2> set autotrace on explain SCOTT@orcl_11gR2> select * from documents d 2 where contains (text, 'foo within title') > 0 3 and extractvalue (xmltype (d.text), '//title') = 'foo' 4 / TEXT ---------------------------------------------foo 1 row selected. Execution Plan ---------------------------------------------------------- Plan hash value: 3102160860 ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 36 | 10 (0)| 00:00:01 | |* 1 | TABLE ACCESS BY INDEX ROWID| DOCUMENTS | 1 | 36 | 10 (0)| 00:00:01 | |* 2 | DOMAIN INDEX | TEST_IDX | | | 4 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(EXTRACTVALUE("XMLTYPE"."XMLTYPE"("D"."TEXT"),'//title')='foo') 2 - access("CTXSYS"."CONTAINS"("TEXT",'foo within title')>0) Note ----- - dynamic sampling used for this statement (level=2) SCOTT@orcl_11gR2>
Maybe you are looking for
-
I get an error message saying "Windows cannot find config.sys.
Original title: startup problem I am running XP I try to access my Start menu. My problem is that I get an error message saying "Windows cannot find config.sys. In search no config.sys happens. I'm tring to remove some startup problems Thank you Bo
-
HP 045tx: extended warranty
How can I extend my accidental warranty of the laptop? My laptop is hp Pavilion. I left 3 months before the warranty expires. Won't charge hp less to extend a guarantee rather than wait until this guarantee can compplete and apply to others?
-
Is Amigos. I have already installed Service Pack 2. Should I also have Service Pack 1 for add? Also, if anyone knows how to re - install... ISATAP (1971 F6F0..., which shows as not work and I think that's the reason why the DVD does not work properly
-
My screen just turned laptop black if it was on. I had to turn it off by clicking the close button and turn it on before I could use my pc again. When turned on, he showed "Recovery Windows". Can I solve this problem before happen again... ?
-
the files must contain pictures. All I get is a sunflower repettative
Images, content in libraries so see no not my photos. ALL I see is a repetitive sunflower. All the answers? Thank you