Retrieve only a group of records
Hi,
Is it possible to retrieve only a particular number of records from the db ? suppose, if there are 100 records, Can I retrieve only the 10 records which I need, thereby I can improve the performance by not reading the other 90 records from the db ?
Hello,
yes, it is possible. You can use an index (secondary database) with DUPSORT for instance. But take care that an index consumes storage on disk. So, it is better if you use it quite often. Of course, you can have many index for one primary database.
You can use cursors as well like a cursor on an index.
You can look into the documentation "Getting started with Berkeley DB for C"
http://www.oracle.com/technology/documentation/berkeley-db/db/index.html
You have both the HTML version and the PDF version.
Similar Messages
-
Efficiently retrieving only a set of records ... ?
Hi,
Ours is web centric small-scale ERP. We have lot of reports which display data by pages.
While retrieving records we are using the following type of SQLs:
select col1,col2,.... from (
select rownum srno, col1, col2, ... from tables where ...)
where srno between 1 and 100;
(100 records per page)
But we know that the sub-query is going to do a full table scan and then the main query will filter the records based on the 'srno' column.
Does anybody know any better way of retrieving records without a having the sub-query do a full table scan?
I would really appreciate your response.
TIA.If you are on Oracle9i, you could use the PL/SQL package DBMS_XMLQUERY to get XML output (optionally you could also
apply an XSLT stylesheet right inside the database to convert it into an HTML). This package has two procedures
setMaxRows => Maximum number of rows to return for your query
setSkipRows => Rows to skip before query results are returned
using this combination, you could call a PL/SQL package with different starting point this package will get you the
rows starting from that row (in XML format or optionally in HTML after applying XSLT).
Once you have the output, you could pass it to the front end and if needed, apply the stylesheet binding there to display
to the client.
You can also take advantage of using bind variables to query for different data values. -
OBIEE only getting limited number of group membership records
Hey everyone,
I'm seeing some strange behavior with the group membership functionality of OBIEE. Right now we're on version 10.1.3.2 and we've implemented SSO and we setup a query against LDAP (AD) to get user group information similar to the way Venkat's blog demonstrates:
http://oraclebizint.wordpress.com/2007/10/12/oracle-bi-ee-101332-and-oid-user-and-group-phase-2/
At first glance, everything was working smoothly, however, on second glance, I noticed that on users who were part of lots of groups (i.e. 80 groups), not all of their membership information was getting into OBIEE. On my test user, who was part of only 10 groups, I ran a test in which I only gave access to the Answers module to a person from the 10th group. When I logged into OBIEE as my test user, I was able to access answers.
On my second test user, who had 80 groups, I set access to answers for the 75th and 80th groups (both different tests). Neither test allowed this user to access answers. However, when I choose the 5th group returned, the user was quickly able to see and access answers.
When I test out the call to the Oracle function in the Admin tool, I see all the groups returned there.
These strange results lead me to believe that there is only so many group membership records that OBIEE can receive. Is that true? Has anyone seen this before? Did I forget to set something appropriately?
Thanks everyone for your help!
-JoeHey,
Sorry about the delay in getting back to you, I was slammed with some work right before the Holiday. Anyway, below is the sample code and an example of it's usage. be sure to replace the <BASE DN>, <LDAP HOST>. <LDAP USER>, and <LDAP PASSWORD> with the appropriate values for your situation.
Also, you'll need to create the "ARRAY" datatype like in Venkat's blog.
Best of luck!
-Joe
select * from table(getusergroup(‘Jbertram’));
create or replace FUNCTION GETUSERGROUP(Username in Varchar2) RETURN ARRAY PIPELINED AS
-- Adjust as necessary.
l_retval pls_integer;
l_session dbms_ldap.session;
l_attrs dbms_ldap.string_collection;
l_message dbms_ldap.message;
l_entry dbms_ldap.message;
l_attr_name varchar2(256);
l_ber_element dbms_ldap.ber_element;
l_vals dbms_ldap.string_collection;
l_raw dbms_ldap.binval_collection;
l_ldap_base varchar2(256) := '<BASE DN>';
l_filter varchar2(100) := '(&(cn='||Username||'))';
l_ldap_host varchar2(100) := '<LDAP HOST>';
l_ldap_port number := 389;
l_ldap_user varchar2(100) := '<LDAP USER>';
l_ldap_passwd varchar2(100):= '<LDAP PASSWORD>';
l_result varchar2(100);
begin
-- Choose to raise exceptions.
dbms_ldap.use_exception := true;
dbms_ldap.utf8_conversion := false;
-- Connect to the LDAP server.
l_session := dbms_ldap.init(hostname => l_ldap_host, portnum => l_ldap_port);
l_retval := dbms_ldap.simple_bind_s(ld => l_session, dn => l_ldap_user, passwd => l_ldap_passwd);
-- Get all attributes
l_attrs(1) := 'memberOf'; -- retrieve all attributes
--l_attrs(2) := 'cn';
l_retval := dbms_ldap.search_s(ld => l_session
,base => l_ldap_base
,scope => dbms_ldap.scope_subtree
,filter => l_filter
,attrs => l_attrs
,attronly => 0
,res => l_message);
if dbms_ldap.count_entries(ld => l_session, msg => l_message) > 0
then
-- Get all the entries returned by our search.
l_entry := dbms_ldap.first_entry(ld => l_session, msg => l_message);
<<entry_loop>>
while l_entry is not null
loop
-- Get all the attributes for this entry.
dbms_output.put_line('---------------------------------------');
l_attr_name := dbms_ldap.first_attribute(ld => l_session
,ldapentry => l_entry
,ber_elem => l_ber_element);
<<attributes_loop>>
while l_attr_name is not null
loop
-- Get all the values for this attribute.
l_vals := dbms_ldap.get_values(ld => l_session, ldapentry => l_entry, attr => l_attr_name);
<<values_loop>>
for i in l_vals.first .. l_vals.last
loop
dbms_output.put_line(substr(l_vals(i),4,instr(l_vals(i),',')-4));
PIPE ROW(substr(l_vals(i),4,instr(l_vals(i),',')-4));
end loop values_loop;
l_attr_name := dbms_ldap.next_attribute(ld => l_session
,ldapentry => l_entry
,ber_elem => l_ber_element);
end loop attibutes_loop;
l_entry := dbms_ldap.next_entry(ld => l_session, msg => l_entry);
end loop entry_loop;
end if;
-- Disconnect from the LDAP server.
l_retval := dbms_ldap.unbind_s(ld => l_session);
--dbms_output.put_line('L_RETVAL: ' || l_retval);
end; -
Read-only radio group losing value on validation error
It took quite a while to track this down, but I think I've got it narrowed down properly. I have an APEX form for updating a record in a databse table with a radio group which is conditionally read-only. If that radio group has a value AND is read-only, when the form is submitted and hits a validation error, the value of the radio group is lost.
For example, the radio group SUBMITTED_FOR_APPROVAL is set to Y and is read-only for a given user. That user then changes something else on the form and submits it. However, the form now hits a validation error for some field. When the form reloads with the validation error displayed, all the fields are restored except the read-only radio group which is now blank. If a select list is used with the identical read-only condition, it works fine. Likewise, if a radio group is used, but the read-only condition is removed, it works fine. It is only when it is a radio group and it is read-only, that the value does not appear to be submitted to the session with all the form values whent he form is submitted.
Is this a bug or am I simply missing something?
Apex 3.1.2
Rgds/Mark M.It's using a shared component LOV cleverly called LOV_YN which consists of a static LOV with
1 Display=Yes, Return=Y
2 Display=No, Return=N
The settings in the LOV section on the item iteself:
Named LOV: LOV_YN
Display Extra values: No Dynamic translation: Not translated
Number of columns: 2 Display null: No
Null display value is blank as is null return value
Item was setup as a radio group and was only converted over to a select list to work around this issue. Let me know what else you need and thanks again.
Rgds/Mark M. -
Assigning sequential value that resets to a group of records
Hello all, and happy FRIDAY!!!
I'm doing some data conversion for a new system and I'm having trouble coming up with a query.
Running Oracle 10.2
Sample Data:
create table test (GRP number, PART varchar2(20), SEQ number);
insert into test values(9000, 'lskdjf', null);
insert into test values(9000, 'alsdk', null);
insert into test values(9000, '492kjsfjsldk', null);
insert into test values(9000, 'lkjasdf0982j', null);
insert into test values(9001, 'likfjajsd', null);
insert into test values(9001, '234-092838', null);
insert into test values(8934, '000-192893aj', null);
insert into test values(8934, 'anotherpart', null);
insert into test values(8934, 'jjjj0-aa-2001', null);
insert into test values(8934, 'encifudy', null);
insert into test values(8934, 'asfdjslkjdfklsj', null);
insert into test values(8934, 'lksjdflj', null);
insert into test values(4736, 'l;ask---jdflasj', null);
commit;
Select * from test;Doing the select * at this point will give you the null data elements for the third column.
Problem:
I'm trying to run a query that spits out a sequence for each "group" of records. If there were 5 records in a group, I would want the sequence to start at 1 and go to 5... maybe ordered by part. (not quite sure the ordering, but need to do babysteps here) :P
Here is an example of the data output I'd want from the above example:
GRP PART SEQ
9000 lskdjf 1
9000 alsdk 2
9000 492kjsfjsldk 3
9000 lkjasdf0982j 4
9001 likfjajsd 1
9001 234-092838 2
8934 000-192893aj 1
8934 anotherpart 2
8934 jjjj0-aa-2001 3
8934 encifudy 4
8934 asfdjslkjdfklsj 5
8934 lksjdflj 6
4736 l;ask---jdflasj 1In that result, SEQ is not applied to the record in part order, but ultimately that might be something that I'd like to do. So far just working toward wanting to get those numbers in there. I have read using rankover(), but that is still a bit confusing to me on how that works. I'll go research it more as I suspect that is probably what I'm going to have to use.
Ultimately this is part of a cursor that is being fed through a bulk collect. I might be able to populate that SEQ in the PL/SQL, but I figured it'd be easier to just get them in place at the query level so they're already part of the collection, instead of having to build the logic to create that numbering system prior to insertion to a staging table.
Anyhoo... any help would be greatly appreciated! If I left anything out or am un-clear in anyway, please let me know! Thank you!
Edited by: dvsoukup on Jul 27, 2012 4:25 PMHi,
dvsoukup wrote:
Running Oracle 10.2
Sample Data:
create table test (GRP number, PART varchar2(20), SEQ number);
insert into test values(9000, 'lskdjf', null); ...
Thanks for posting your version, and the CREATE TABLE and INSERT statemen ts; that's very helpful!
>
Doing the select * at this point will give you the null data elements for the third column.
Problem:
I'm trying to run a query that spits out a sequence for each "group" of records. If there were 5 records in a group, I would want the sequence to start at 1 and go to 5... maybe ordered by part. (not quite sure the ordering, but need to do babysteps here) :P
I have read using rankover(), but that is still a bit confusing to me on how that works. You've got that right! Analytic functions are very strange looking and confusing at first. After a while, they don't seem so strange, and then they even get less confusing.
One thing to remember: "PARTITION BY x" (this clause is always optional) means that each value of x is a world unto itself. It's as if a separate query is being done for each value of x, and when they're all finished, the results are UNIONed together. In this case, you want to PARTITION BY grp.
I'll go research it more as I suspect that is probably what I'm going to have to use.You're very close; only, as the first reply said, it's not RANK that you want, but its close relative ROW_NUMBER. The difference between the two is how they handle ties. If you have duplicate data, RANK assigns duplicate numbers. I assume you want unique numbers, even if you have identical parts in the same grp.
Ultimately this is part of a cursor that is being fed through a bulk collect. I might be able to populate that SEQ in the PL/SQL, but I figured it'd be easier to just get them in place at the query level so they're already part of the collection, instead of having to build the logic to create that numbering system prior to insertion to a staging table.It's easy enough to assign the numbers when you build the table.
If the situation is what you posted, that is, your table already exists, but the seq number isn't populated yet, then you can do this:
MERGE INTO test dst
USING (
SELECT grp
, part
, ROW_NUMBER () OVER ( PARTITION BY grp
ORDER BY part
) AS seq
FROM test
) src
ON ( src.grp = dst.grp
AND src.part = dst.part
WHEN MATCHED THEN UPDATE
SET dst.seq = src.seq
;The MERGE statement above assumes that the combination (grp, part) is unique.
After you run it, this query:
SELECT *
FROM test
ORDER BY grp
, part
;will produce these results:
` GRP PART SEQ
4736 l;ask---jdflasj 1
8934 000-192893aj 1
8934 anotherpart 2
8934 asfdjslkjdfklsj 3
8934 encifudy 4
8934 jjjj0-aa-2001 5
8934 lksjdflj 6
9000 492kjsfjsldk 1
9000 alsdk 2
9000 lkjasdf0982j 3
9000 lskdjf 4
9001 234-092838 1
9001 likfjajsd 2The USING clause above is almost the same as the query posted in the last message, but, in the analytic clause, instead of "ORDER BY grp, part" it only says "ORDER BY part". It never makes any sense to PARTITION BY and ORDER BY the same column in the same function. Why? Discuss. -
Retrieve only one type of phone number
Hi
In the following sample query I need to retrieve only one phone number. The preference is if Mobile available - mobile number if not Home number (Type - H1), else Work number (W1).
I have included the script and sample output what I am getting from the SQL
Thanks in advance
Regards
Sriram
select pp.ph_id
,papf.person_id
,pp.ph_type
,pp.ph_no
,pp.date_from
,pp.date_to
from per_phones pp
,per_all_people_f papf
,per_contact_relationships pcr
where papf.person_id = pp.parent_id
and pcr.person_id = papf.person_id
and trunc(sysdate) between trunc(nvl(pcr.date_start, sysdate-1))
and trunc(nvl(pcr.date_end, sysdate+1))
and papf.person_id in (146564, 514)
and pcr.primary_contact_flag = 'Y'
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and trunc(sysdate) between nvl(pp.date_from, sysdate-1) and nvl(pp.date_to, sysdate+1);output
PH_ID PERSON_ID PH_TYPE PH_NO DATE_FROM DATE_TO
3261 514 H1 987524879 13-Jun-04
117287 514 M 0403672797 11-May-05
141997 146564 H1 54789620 15-Feb-06 05-Mar-10
311028 146564 H2 235469 5-Dec-09
311029 146564 W1 8300054 15-Dec-09
311108 146564 M 04126872 12-Feb-10Not tested, but something like this might do the trick. What you need to do is assign a hierarchy to the phone type codes, then choose the top one for each parent id.
WITH phone_list
AS ( SELECT parent_id,
MIN( CASE ph_type
WHEN 'M' THEN 1
WHEN 'H1' THEN 2
WHEN 'W' THEN 3
ELSE 99
END ) AS phone_pref
FROM per_phones
GROUP
BY parent_id )
SELECT pp.ph_id,
papf.person_id,
pp.ph_type,
pp.ph_no,
pp.date_from,
pp.date_to
FROM per_phones pp,
per_all_people_f papf,
per_contact_relationships pcr,
phone_list lst
WHERE papf.person_id = pp.parent_id
AND pcr.person_id = papf.person_id
AND trunc(sysdate) between trunc(nvl(pcr.date_start, sysdate-1))
AND trunc(nvl(pcr.date_end, sysdate+1))
AND papf.person_id in (146564, 514)
AND CASE pp.ph_type
WHEN 'M' THEN 1
WHEN 'H1' THEN 2
WHEN 'W' THEN 3
ELSE 99
END = lst.phone_pref
AND pp.parent_id = lst.parent_id; -
Event 917 Console Crash when attempting to modify Disk Only Protection Group
Primary DPM 2012 R2 4.2.1254.0 running on Server 2012 -
In the process of decommissioning a number of old servers - I found that I am no longer able to modify a disk only protection group on one of my primary DPM servers. Console crash - noting error 917. I've seen a number of work around in relation to protection
groups with long term storage, but none noting disk only. Notably, kb 2905631 - long term only protection may cause this issue.
Another thread mentioned that re-syncing / consistency checks on the entire server resolved the issue for them, but I find that rather unnecessary. I've over 13Tb of data on this server, and am trying to remove the last 30GB of an old protection group.
Recap-
Error 917 when removing member from protection group
MMC crash with a 999 marked when modifying the protection group
The event log is not noting any service crashes, or the 917 error in the event log. 999 is getting recorded in the event log.
The description for Event ID 999 from source MSDPM cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
An unexpected error caused a failure for process 'mmc'. Restart the DPM process 'mmc'.
Problem Details:
<FatalServiceError><__System><ID>19</ID><Seq>0</Seq><TimeCreated>12/2/2014 5:40:14 PM</TimeCreated><Source>DpmThreadPool.cs</Source><Line>163</Line><HasError>True</HasError></__System><ExceptionType>SqlNullValueException</ExceptionType><ExceptionMessage>Data
is Null. This method or property cannot be called on Null values.</ExceptionMessage><ExceptionDetails>System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
at System.Data.SqlClient.SqlBuffer.get_String()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.OMCommon.ProtectionGroup.ReadBackupAndCCWindow()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.OMCommon.ProtectionGroup.get_BackupWindow()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.OMCommon.ProtectionGroup.GetPerformanceString()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ProtectedGroupUIElement.AddPerformanceData()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ProtectedGroupUIElement.ConstructDetailsPaneContent()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.CommonControls.UISearchableElement.get_DetailNameValuePairs()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ProtectedGroupUIElement.DisplayDetails()
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ProtectionViewInternal.FillGroupDetails(GroupingListHeaderItem group)
at Microsoft.Internal.EnterpriseStorage.Dls.UI.ProtectionViewInternal.UpdateDetailsPane()
at System.EventHandler.Invoke(Object sender, EventArgs e)
at Microsoft.Internal.EnterpriseStorage.UI.CommonControls.GroupingListView.EndUpdate()
at Microsoft.Internal.EnterpriseStorage.UI.CommonControls.GroupingListViewBody.ProcessClick()
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at Microsoft.Internal.EnterpriseStorage.UI.CommonControls.GroupingListViewBody.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</ExceptionDetails></FatalServiceError>
the message resource is present but the message is not found in the string/message tableHi Mike,
That appears to be the case. A row shows NULL for IMCatalogXML. I'm looking at your script to update the value now based on the following thread - thread .
So far, no rows have been modified.
Since I really don't care about this protected member, is this a row I could just delete from the DB, or how to properly update the data so I can remove it from within the confines of the GUI?
Marketing 2011-05-19 18:59:41.917
B7073B10-DDE6-4EA3-BD8C-1E1497C218D5 NULL
NULL 0
0 0 NULL
2 0
NULL
This PG was definitely around back when this server was DPM 2010.
Regards -
Suggestions required for Read-only cache group in timesten IMDB cache
Hi
In IMDB Cache , If the underlying oracle RAC is having two schemas ( "KAEP" & "AAEP" , having same sturcture and same name of objects ) and want to create a Read-only cache group with AS pair in timesten.
Schema
KAEP
Table
Abc1
Abc2
Abc3
Schema
AAEP
Table
Abc1
Abc2
Abc3
Can a read-only cache group be created using union all query ?
The result set of the cache group should contain both schema records in timesten read-only cache group will it be possible ?
Will there be any performance issue?You cannot create a cache group that uses UNION ALL. The only 'query' capability in a cache group definition is to use predicates in the WHERE clause and these must be simple filter predicates on the tables in the cache group.
Your best approach is to create separate cache groups for these tables in TimesTen and then define one or more VIEWS using UNION ALL in TimesTen in order to present the tables in the way that you want.
Chris -
Retrieving latest updated or inserted records without using a trigger
I have to retrieve the latest updated/inserted records from a set of database tables. Say, if 'n' sets of different records have been updated or inserted into one or more different database tables then all the 'n' records of data should be retrieved using a java code without using a trigger.
helpmeplz wrote:
Thanks for your reply.
But I don't know when or from where or what kind of data gets inserted/updated into the tables. I need a listener or a component which can handle events occured on the particular set of database tables, and get the event data. the java code should get the updated/inserted rows that have been inserted into a set of database tables by a third party.
Please lemme know how I can do this.Realistically you can't.
If and only if the tables have a modification timestamp then you could use that. Every table would need it.
Other than that the only othe possibility would require that you keep an entire copy of each table in the memory, poll at a set interval and then do an entire comparison for each table. For very small data volumes (on the target tables) that is practical. For larger volumes it isn't. -
SQL Query to retrieve one line from duplicate records
Hi
I have one table which contains duplicate records in multiple column but the difference is in one column which contains the value 0 or positive. The query i want is to retrieve only the line with the positive value for only the duplicated records.
here below a sample data for your reference:
CREATE TABLE TRANS
CALLTRANSTYPE NVARCHAR2(6),
ORIGANI NVARCHAR2(40),
TERMANI NVARCHAR2(40),
STARTTIME DATE,
STOPTIME DATE,
CELLID NVARCHAR2(10),
CONNECTSECONDS NUMBER,
SWITCHCALLCHARGE NUMBER
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,0)
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,18000)
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:18:03','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:18:20','mm/dd/yyyy hh24:mi:ss'),null,17,0)
The output i want to have is:
CALLTRANSTYPE ORIGANI TERMANI STARTTIME STOPTIME CELLID CONNECTSECONDS SWITCHCALLCHARGE
REC 555988801 222242850 05/15/2012 09:15:00 05/15/2012 09:15:25 25 18000
REC 555988801 222242850 05/15/2012 09:18:03 05/15/2012 09:18:20 17 0 Thank you.Hi ekh
this is the query i want to have, thank you for the help:
SQL> Select *from
select CALLTRANSTYPE,ORIGANI,TERMANI,STARTTIME,STOPTIME,CELLID,CONNECTSECONDS,SWITCHCALLCHARGE
,row_number() over( partition by STARTTIME ,STOPTIME order by SWITCHCALLCHARGE DESC ) rn from TRANS
where rn=1;
CALLTR ORIGANI TERMANI STARTTIME STOPTIME CELLID CONNECTSECONDS SWITCHCALLCHARGE RN
REC 555988801 222242850 15-MAY-12 15-MAY-12 25 18000 1
REC 555988801 222242850 15-MAY-12 15-MAY-12 17 0 1Regrads
Lucienot. -
SQL to group the records and apply logic to pick one record from each group
Hi Friends,
I am looking for a query to group the records on certain columns in a table and then from each group I want to pick only one record based on certain rules.
May be having data laid out will make my point more clear to you. Here you go :
CREATE TABLE AD_LIST
FILE_NAME VARCHAR2(50 BYTE),
ACTIVITY_START DATE,
ACTIVITY_END DATE,
DIVISION VARCHAR2(50 BYTE),
ITEM_CODE VARCHAR2(50 BYTE),
MULT NUMBER,
RETAIL NUMBER,
AD_PAGE VARCHAR2(1 BYTE),
FORECAST NUMBER,
MEMO VARCHAR2(50 BYTE)
INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,5,10,'A',10,'This must be in my result');
INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,1,1,'B',15,'Must not be in my result');
INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,6,15,'C',11,'Must not be in my result');
INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,4,20,'D',40,'Must not be in my result');
INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,5,15,'E',30,'Must not be in my result');
INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,1,2,'F',20,'This must be in my result');
CREATE TABLE PAGE_RANK
AD_PAGE VARCHAR2(1 BYTE),
RANK NUMBER
INSERT INTO PAGE_RANK VALUES ('A',1);
INSERT INTO PAGE_RANK VALUES ('B',2);
INSERT INTO PAGE_RANK VALUES ('C',3);
INSERT INTO PAGE_RANK VALUES ('D',4);
INSERT INTO PAGE_RANK VALUES ('E',5);
INSERT INTO PAGE_RANK VALUES ('F',6);
COMMIT;
SELECT * FROM AD_LIST
FILE ACTIVITY ACTIVITY ITEM AD
NAME START END DIV CODE MULT RETAIL PAGE FORECAST MEMO
FILE_1 4/1/2010 4/15/2010 B 1111 5 10 A 10 This must be in my result
FILE_1 4/1/2010 4/15/2010 B 1111 1 1 B 15 Must not be in my result
FILE_1 4/1/2010 4/15/2010 B 1111 6 15 C 11 Must not be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 4 20 D 40 Must not be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 5 15 E 30 Must not be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 1 2 F 20 This must be in my resultNow, from the table AD_LIST I want to group the records based on FILE_NAME, ACTIVITY_START, ACTIVITY_END, DIVISION, ITEM_CODE.
So in my example here we have 2 set of records grouped based on the columns specified.
Also we have one more table, PAGE_RANK, which has a rank corresponding to each ad_page number. Here 1 is higher rank than 2. Hence ad page 'A' takes priority over 'B'. Similarly for all other ad pages.
Now, we need to pick one ad from each group of ads by determining the highest ranked ad page within the group and the value for mult and retail must be replaced with the value that has min(retail/mult). So, using the above data we will have the one having ad page = 'A' and ad page = 'D' as the final results since they have highest ad page rank in their group.
The value for mult and retail values for ad_page 'A' = min (10/5 , 1/1, 15/6) = 1,1(mult,retail).
The value for mult and retail values for ad_page 'D' = min (20/4 , 15/5, 2/1) = 1,2(mult,retail).
Finally I have this query below
SELECT a.file_name,
a.activity_start,
a.activity_end,
a.division,
a.item_code,
FIRST_VALUE (a.mult) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
a.mult))
mult,
FIRST_VALUE (a.retail) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
a.mult))
retail,
FIRST_VALUE (a.ad_page) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (b.RANK))
ad_page,
a.forecast,
a.memo
FROM ad_list a, page_rank b
WHERE a.ad_page = b.ad_pageThis query is giving me all the records but with the values what I wanted in Ad_Page, Mult and Retail columns.
How can I pick only one from each group.
I am getting this FILE ACTIVITY ACTIVITY ITEM AD
NAME START END DIV CODE MULT RETAIL PAGE FORECAST MEMO
FILE_1 4/1/2010 4/15/2010 B 1111 1 1 A 15 Must not be in my result
FILE_1 4/1/2010 4/15/2010 B 1111 1 1 A 10 This must be in my result
FILE_1 4/1/2010 4/15/2010 B 1111 1 1 A 11 Must not be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 1 2 D 20 This must be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 1 2 D 30 Must not be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 1 2 D 40 Must not be in my resultBut I want this FILE ACTIVITY ACTIVITY ITEM AD
NAME START END DIV CODE MULT RETAIL PAGE FORECAST MEMO
FILE_1 4/1/2010 4/15/2010 B 1111 1 1 A 10 This must be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 1 2 D 20 This must be in my resultI have to run this query for thousands of such group combination.
Hope some one can throw some light on this query.
Thanks in advance,
Raj.Frank,
You are marvelous.
That is what I was expecting, but basically I want to display the row with highest page rank which is 'A' and 'D' in this case.
So I have changed my query as below using yours :
WITH mainq AS
(SELECT a.file_name,
a.activity_start,
a.activity_end,
a.division,
a.item_code,
FIRST_VALUE (a.mult) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
a.mult))
mult,
FIRST_VALUE (a.retail) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
a.mult))
retail,
--FIRST_VALUE (a.ad_page) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (b.RANK))
a.ad_page,
a.forecast,
a.memo,
ROW_NUMBER () OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY b.RANK)
AS r_num
FROM ad_list a, page_rank b
WHERE a.ad_page = b.ad_page)
SELECT *
FROM mainq a
WHERE r_num = 1
FILE ACTIVITY ACTIVITY ITEM AD
NAME START END DIV CODE MULT RETAIL PAGE FORECAST MEMO
FILE_1 4/1/2010 4/15/2010 B 1111 1 1 A 10 This must be in my result
FILE_1 4/16/2010 4/30/2010 N 1111 1 2 D 40 Must not be in my resultMy apologies that I gave you wrong forecast and memo values in my earlier post.
But that is what I wanted and your input greatly helped me to save lot of time by using in one single query.
Earlier I was using cursor to do that and it was not doing any good performance wise.
Thanks to every body for your time and your efforts.
I appreciate it.
Have fun.
~Raj -
I need to create a SQL statement that will create a unique identifer for groups of records returned by a join. This number will be used to differentiate individual records in groups where all columns are the same except for one. I can use a function to do this but I am trying to avoid temporary tables. This SQL statement will be used to populate a view.
Here is basically what it should look like:
Col1 Col2 Col3 Col4 OBS
A A A 5 1
A A A 4 2
B A A 3 1
B A B 2 1
B A B 3 2
B A B 7 3
A B A 6 1
(OBS is the number I need to generate, col4 is the one column whose value can vary in the group. Col 1-4 come from a join)
Any ideas or suggestions would be appreciated.
Thanks,
David
nullHi David-
If OBS is used only to differentiate and possibly for sorting, then it doesn't have to start over at 1 for each new group. You can create a sequence named OBS_seq and reference it for the value of OBS. Each row in the entire resultset gets a unique value for OBS and by deduction, each row in a group has a unique value of OBS.
If you implement this technique, you will probably wish to define a time when the sequence can be dropped and re-created to occasionally start over at 1.
David -
How to retrieve only error message through report file
Hi,
When there is extract/replicat abended,we need to check complete report file to see the error message.
I would like to know is there parameter setting available ,so that we can retrieve only required error message.
For ex. Instead of complete error message to check in report file,i need to see below meesage only,starting from "source Context".
Source Context :
SourceModule : [er.main]
SourceID : [scratch/pradshar/view_storage/pradshar_bugdbrh40_12927937/oggcore/OpenSys/src/app/er/rep.c]
SourceFunction : [get_map_entry]
SourceLine : [9126]
ThreadBacktrace : [11] elements
: [ora/gg/install/replicat(CMessageContext::AddThreadContext()+0x26) [0x5f2ac6]]
: [ora/gg/install/replicat(CMessageFactory::CreateMessage(CSourceContext*, unsigned int, ...)+0x7b2) [0x5e9562]]
: [ora/gg/install/replicat(_MSG_ERR_DB_CLAUSE_ERROR(CSourceContext*, char const*, CMessageFactory::MessageDisposition)+0x92) [0x5b1352]
: [ora/gg/install/replicat(get_map_entry(char*, int, __wc*, int)+0x1dd6) [0x4fcec6]]
: [ora/gg/install/replicat [0x5497e5]]
: [/ora/gg/install/replicat(WILDCARD_check_table(char const*, char const*, int, unsigned int*, int, unsigned int, DBString<777>*, int)+0
x16b) [0x54b08b]]
: [ora/gg/install/replicat(REP_find_source_file_wc(char const*, unsigned int, DBString<777>*, int)+0x350) [0x903d50]]
: [ora/gg/install/replicat [0x90bb0d]]
: [ora/gg/install/replicat(main+0x84b) [0x5081ab]]
: [lib64/libc.so.6(__libc_start_main+0xf4) [0x2b87d13469b4]]
: [ora/gg/install/replicat(__gxx_personality_v0+0x1da) [0x4e479a]]
2012-07-09 02:20:48 ERROR OGG-00919 Error in COLMAP clause.
--------------------------------------------------------------------------------------------------------------------------------------------------------Nice..i think awk is better option.
Just one thing.awk command only displays part of the information instead of complete below information.
Ex: egrep -q ERROR dirrpt/PODS00C1.rpt && awk '/^Source Context/,/ERROR/ { print $0 }' dirrpt/PODS00C1.rpt
[22:00]goldengate]$ egrep -q ERROR dirrpt/PODS00C1.rpt && awk '/^Source Context/,/ERROR/ { print $0 }' dirrpt/PODS00C1.rpt
Source Context :
SourceModule : [ggdb.ora.sess]
SourceID : [scratch/pradshar/view_storage/pradshar_bugdbrh40_12927937/oggcore/OpenSys/src/gglib/ggdbora/ocisess.c]
SourceFunction : [OCISESS_try]
SourceLine : [500]
ThreadBacktrace : [12] elements
: [orashare/gg/navc1/extract(CMessageContext::AddThreadContext()+0x26) [0x6705e6]]
: [orashare/gg/navc1/extract(CMessageFactory::CreateMessage(CSourceContext*, unsigned int, ...)+0x7b2) [0x667082]]
: [orashare/gg/navc1/extract(_MSG_ERR_ORACLE_OCI_ERROR_WITH_DESC(CSourceContext*, int, char const*, char const*, CMessageFactory::MessageDisposition)+0xa6) [0x61f2c6]]
Where as i would like to see complete information including ERROR details as mentioned below.Do you have any awk command for this?
Required below output:
Source Context :
SourceModule : [ggdb.ora.sess]
SourceID : [scratch/pradshar/view_storage/pradshar_bugdbrh40_12927937/oggcore/OpenSys/src/gglib/ggdbora/ocisess.c]
SourceFunction : [OCISESS_try]
SourceLine : [500]
ThreadBacktrace : [12] elements
: [orashare/gg/navc1/extract(CMessageContext::AddThreadContext()+0x26) [0x6705e6]]
: [orashare/gg/navc1/extract(CMessageFactory::CreateMessage(CSourceContext*, unsigned int, ...)+0x7b2) [0x667082]]
: [/orashare/gg/navc1/extract(_MSG_ERR_ORACLE_OCI_ERROR_WITH_DESC(CSourceContext*, int, char const*, char const*, CMessageFactory::MessageDisp
osition)+0xa6) [0x61f2c6]]
: [orashare/gg/navc1/extract(OCISESS_try(int, OCISESS_context_def*, char const*, ...)+0x353) [0x5a3d53]]
: [orashare/gg/navc1/extract(OCISESS_logon(OCISESS_context_def*, char const*, char const*, char const*, int, int, int)+0x89c) [0x5a596c]]
: [orashare/gg/navc1/extract(DBOCI_init_connection_logon(char const*, char const*, char const*, int, int, int, char*)+0x74) [0x5931a4]]
: [orashare/gg/navc1/extract [0x597918]]
: [orashare/gg/navc1/extract(gl_odbc_param(char const*, char const*, char*)+0x3b) [0x597f1b]]
: [orashare/gg/navc1/extract [0x520b96]]
: [orashare/gg/navc1/extract(main+0x1ce) [0x52726e]]
: [lib64/libc.so.6(__libc_start_main+0xf4) [0x2af768923994]]
: [orashare/gg/navc1/extract(__gxx_personality_v0+0x1ea) [0x4f3aba]]
2012-09-06 16:48:50 ERROR OGG-00664 OCI Error beginning session (status = 1017-ORA-01017: invalid username/password; logon denied).
2012-09-06 16:48:50 ERROR OGG-01668 PROCESS ABENDING. -
I can only create group messages but every time someone starts a group chat it says its send to my number but I never got any text. I wen't to settings>Messages and I can't find any on/off switch.
Hello there, Idaniabb.
The following Knowledge Base article offers up some great information in regards to group messaging and also links to another excellent resource for troubleshooting messages as well:
iOS: Understanding group messaging
http://support.apple.com/kb/HT5760
Thanks for reaching out to Apple Support Communities.
Cheers,
Pedro. -
How to Select each check box values in a group of records
Hi,
I have a requirement in forms 10g. In that form there are 10 records are displaying each record has one check box is there if i click the check box on record number one and record number three and do some changes in the text field(adjustment field is number data type) then finally I want to see the total on one field called total amount.
In this my question is how to select particular records in a group of records? and finally these selected records are inserted into one table.
Because I am not able to fetch these records at a time.
Is there any Array to define a record group to fetch each of them individually for example Rec[1],Rec[2]...like that if yes please suggest me the steps how to do this.
Thanks in advance
Prasanna
Edited by: user10315107 on Dec 17, 2008 11:44 PMI'm sorry, but i didn't get your requirement in detail.
Do you want to do the summing of the selected records in forms ? Or do you just want to know which records are selected and then process them?
If you want to process the selected records in sql you could use an object-type to store the list of id's (of whatever primary key you use), loop over the block to fill it, and then afterwards process them.
For this approach, first create an object-type in the database:
CREATE OR REPLACE TYPE ID_LIST AS TABLE OF NUMBER;
/Then, in forms you could do something like this to fill a list of id's:
DECLARE
lIds ID_LIST:=ID_LIST();
BEGIN
GO_BLOCK('MYBLOCK');
FIRST_RECORD;
LOOP
EXIT WHEN :SYSTEM.RECORD_STATUS='NEW';
IF :BLOCK.CHECKBOXITEM="CHECKEDVALUE" THEN
lIds.EXTEND(1);
lIds(lIds.COUNT):=:BLOCK.PRIMARYKEYITEM;
END IF;
EXIT WHEN :SYSTEM.LAST_RECORD='TRUE';
NEXT_RECORD;
END LOOP;
-- Now you can use the object-list in SQL like :
INSERT INTO MYNEWTABLE (cols..)
SELECT (cols..)
FROM MYOLDTABLE
WHERE ID IN (SELECT COLUMN_VALUE FROM TABLE(lIds));
END;Edited by: Andreas Weiden on 18.12.2008 18:17
Maybe you are looking for
-
Profit center in material master is not in MARC table
Hi All, We have maintained profit center in Material master costing 1 screen but when I am checking it in MARC table I am not able to see profit center in MARC Table. Please tell me in which table this profit center data will sit. Thanks in advance.
-
Code is not working check for solution . The code is not working after look up table.
In this code i am multiplying two binary images , one is a rectangle and another is an image. i am getting the rectangle, but not the image. The image part is not working after the look up table. Waiting for the solution Attachments: binary morpholog
-
Account inaccessible .. operation does not support device
iMac, Core Duo 20" 2Gig RAM Since update to 10.4.10 using combo update... trying to log on to a guest account crashes the system to black screen with white system prompt: '...operation not supported by device.' I hold the power button for 5 seconds t
-
BDLS conversion require manual corrections
Hi, I am currently running BDLS in a system that is copied from BI Quality system. After the copy, I have run BDLS conversion for few source system connections. For the source system conversion from URD030 -> DV2CLNT030, I found that few tables requi
-
A system just like stock quota has many client(100 000+). we choose JMS to resolve the project. we have many choice in the field of Client. 1st:Client is a stand-alone application,which directly connect to JMS server and receive those message. 2nd:us