Query --Insert no of records in target based on count
The source table has a count column. Now, depending on the value in the count field of that record, that particular record has to be loaded that number of times with consecutive dates. For e.g. the source table structure looks like:
Resource ID Project ID Count Value Start Date*
001 Abc 2 0 01/01/2007
001 Abc 5 8 01/01/2007
001 Abc 2 0 01/01/2007
002 Xyz 2 0 05/01/2007
002 Xyz 4 10 05/01/2007
*The Start Date remains same for a particular set of resource id and project id.
Count Field represents the number of days starting from the start date, where a set of resource id and project id has a value specified in the value column. We need to track this source on a day basis. Hence, the number of times a record will be entered into the target will depend on the count value. So, in this example, for resource id - 001 and project id - Abc, starting from date 01/01/2007, for first 2 days, value is 0, next 5 days, value is 8 and next 2 days, value is 0. The target for this source table would look like:
Resource ID Project ID Value Date Explanation**
001 Abc 0 01/01/2007 Count = 2. Hence 2 records inserted.
001 Abc 0 02/01/2007
001 Abc 8 03/01/2007Count = 5. Hence 5 records inserted.
001 Abc 8 04/01/2007
001 Abc 8 05/01/2007
001 Abc 8 06/01/2007
001 Abc 8 07/01/2007
001 Abc 0 08/01/2007Count = 2. Hence 2 records inserted.
001 Abc 0 09/01/2007
002 Xyz 0 05/01/2007Count = 2. Hence 2 records inserted.
002 Xyz 0 06/01/2007
002 Xyz 10 07/01/2007Count = 4. Hence 4 records inserted.
002 Xyz 10 08/01/2007
002 Xyz 10 09/01/2007
002 Xyz 10 10/01/2007
** This column is not there in the target
Kindly let me know how we can devise this logic.
Thanks a lot in advance.
Cheers
I would suggest you use PL/SQL for this . Here is a Code Stub ( not tested ) , this is just for your reference , customize it for your need .
declare
Cursor Cur_Resource IS
Resource_ID , Project_ID , Count_Value , Start_Date From <Table> ;
BEGIN
For orec in Cur_Resource Loop
For i in 1..orec.Count_Value Loop
Insert into Table2 values (orec.Resource_ID, orec.Project_ID, orec.Count_Value , orec.Start_Date+i)
End Loop;
End Loop;
END;
Similar Messages
-
Deleting records in target based on condition
Hi,
I have a field in source 'original_clm_id'
I need to match it with the 'claim_id' of target table and if i find any, i need to delete them from the target.
The source tables 'original_clm_id' is not being loaded to target -- just using it for matching
Can i do this using operators in OWB. i dont want to use procedure here.
Thanks
RameshHi,
1) create new mapping
2) drop mapping table where to delete from onto mapping (2 times, 1 source, 1 target)
3) map all fields from source to their corresponding fields in target, except the ones that determine the "where" clause (Refered to as filter fields)
4) Either create a select, or a mapping input parameter which should result in generating the filter-values for your delete.
5) map above step to the filter fields.
6)define a delete mapping by altering target table properties as follows:
6a) Loading Type => Delete
6b) Match by constraint => No constraints
7) set properties each field as folows:
7a) filter fields match column when deleting => Yes
7b) other fields match column when deleting => No
Hope this helps .
Sutirtha -
Insert order by records into a view with a instead of trigger
Hi all,
I have this DML query:
INSERT INTO table_view t (a,
b,
c,
d,
e)
SELECT a,
b,
c,
d,
e
FROM table_name
ORDER BY dtable_view is a view with an INSTEAD OF trigger and table_name is a table with my records to be inserted.
I need the ORDER BY clause because in my trigger i call a procedure who treat each record and insert into a table, used in the view. I need to garantee these order.
If i put an other SELECT statement outside, like this:
INSERT INTO table_view t (a,
b,
c,
d,
e)
SELECT a,
b,
c,
d,
e
FROM table_name
ORDER BY dIt works. But I can put these new SELECT because these query is created automatic by Oracle Data Integrator.
What I'm asking you is if there any solution to this problem without changing anything in the Oracle Data Integrator. Or, in other words, if there is any simple solution other than to add a new SELECT statement.
Thanks in advance,
Regards.Sorry... copy+paste error :)
INSERT INTO table_view t (a,
b,
c,
d,
e)
SELECT *
FROM ( SELECT a,
b,
c,
d,
e
FROM table_name
ORDER BY d)I need to insert him by a D column order, because my trigger needs to validate each record and insert him. I have some restrictions. For example, my records are:
2 1 2006 M
1 2 2007 M
1 3 2007 S 2007
1 2 2007 S 2007
2 1 2009 S
2 1 2009 S
I want to insert the 'M' records first and then the 'S' records because the 'S' records only makes sense in target table is exists 'M' records
Regards,
Filipe Almeida -
ORA-00001:Unique Constraint while inserting 2 similar records from source
Hi,
in TEST1 there are records:
10 20 ABC
10 20 DEF
I amt trying to insert into TEST which has CODE as Primary Key.
declare
type cur is ref cursor;
cur_t cur;
type v_t is table of TEST%rowtype;
tab v_t;
v_act_cnt_str VARCHAR2(4000);
v_act_cnt NUMBER:=0;
BEGIN
v_act_cnt_str:=' SELECT COUNT(*) '||' FROM TEST '||' WHERE '||'('||CODE||')'||' IN '||'('||'SELECT '||CODE||' FROM TEST1'||')';
DBMS_OUTPUT.PUT_LINE('The Actual Count String is'||v_act_cnt_str);
EXECUTE IMMEDIATE v_act_cnt_str INTO v_act_cnt;
open cur_t for select * from TEST1 ORDER BY ROWNUM;
loop
fetch cur_t bulk collect into tab limit 10000;
if v_act_cnt=0 THEN
forall i in 1..tab.count
insert into TEST values tab(i);
commit;
ELSE
v_merge_act_str :=
'MERGE INTO TEST '||
' DEST' || ' USING TEST1 '||
' SRC' || ' ON (' || DEST.CODE=SRC.CODE || ')' ||
' WHEN MATCHED THEN ';
first_str := 'UPDATE ' || ' SET ' ||
'DEST.NAME=SRC.NAME,DEST.DEPT_NAME=SRC.DEPT_NAME;
execute immediate v_merge_act_str || first_str;
v_merge_act_str := '';
first_str := '';
commit;
END IF;
end loop;
END;
ITS GIVING ERROR as:
ORA-00001: unique constraint (PK_TEST1) violated
Any help will be needful for me
Edited by: user598986 on Sep 22, 2009 4:20 AM
Edited by: user598986 on Sep 22, 2009 4:22 AMYour code makes absolutely no sense whatsover. The whole point of MERGE is that it allows us to conditionally apply records from a source table as inserts or updates to a target table. So why have you coded two separate statements? And why are you using such horrible dynamic SQL?
Sorry to unload on you, but you seem to have your code unnecessarily complicated, and that it turn makes it unnecessarily harder to debug. As an added "bonus" this approach will also perform considerably slower than a single MERGE statement. SQL is all about set operations. Don't do anything procedurally which can be done in a set.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
How to find out query for the deleted record.
Hi Guys,
We are using Oracle9i release 1. We are about 5 employees who are working on the same application. All Employee are connected to the same Schema (User)
User: Employee/web
Now one of the user have deleted like 200,000 records from a table. We just want to trace out the query by which these records were deleted.
From which file i can get the log of executed queries so that i can recover the data.
Just want to know the query executed for this deletion of records?
we are using windows server.
Regards,
Imran BaigIf you do not need an exact query, but only the way you can reconstruct the data, LogMiner can be solution for you. Below I have put a simple example you can review it if you want.
[email protected]> create table t201 as select object_id , object_name from all_objects where rownum < 10;
Table created.
[email protected]> select * from t201;
OBJECT_ID OBJECT_NAME
17918 /1005bd30_LnkdConstant
7540 /10076b23_OraCustomDatumClosur
23355 /10297c91_SAXAttrList
14204 /103a2e73_DefaultEditorKitEndP
22920 /1048734f_DefaultFolder
10154 /10501902_BasicFileChooserUINe
23566 /105072e7_HttpSessionBindingEv
23621 /106ba0a5_ArrayEnumeration
9830 /106faabc_BasicTreeUIKeyHandle
9 rows selected.
[email protected]> delete t201 where object_id < 10000;
2 rows deleted.
[email protected]> commit;
Commit complete.
[email protected]> alter system switch logfile;
System altered.
[email protected]> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
1 1 41 10485760 2 YES ACTIVE 58320830 25-MAR-06
2 1 42 10485760 1 NO CURRENT 58348006 25-MAR-06
3 1 40 10485760 1 YES INACTIVE 58293190 25-MAR-06
[email protected]> select * from v$archived_log where sequence# = 41;
RECID STAMP
NAME
DEST_ID THREAD# SEQUENCE# RESETLOGS_CHANGE# RESETLOGS FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME BLOCKS
ARC APP
DEL S COMPLETIO DIC DIC END BACKUP_COUNT ARCHIVAL_THREAD# ACTIVATION#
86 585998848
C:\ORACLE\ORADATA\MOB92\ARCH\ARC00041.001
1 1 41 57407039 20-MAR-06 58320830 25-MAR-06 58348006 25-MAR-06 20282
YES NO
NO A 25-MAR-06 NO NO NO 0 1 2555135919
[email protected]> exec dbms_logmnr.add_logfile('C:\ORACLE\ORADATA\MOB92\ARCH\ARC00041.001',dbms_logmnr.new)
PL/SQL procedure successfully completed.
[email protected]> exec dbms_logmnr.start_logmnr(options => dbms_logmnr.dict_from_online_catalog)
PL/SQL procedure successfully completed.
[email protected]> l
1 select sql_undo, sql_redo
2 from v$logmnr_contents
3 where username = 'MOB' and timestamp > sysdate - 1
4* order by timestamp
insert into "MOB"."T201"("OBJECT_ID","OBJECT_NAME") values ('7540','/10076b23_OraCustomDatumClosur');
delete from "MOB"."T201" where "OBJECT_ID" = '7540' and "OBJECT_NAME" = '/10076b23_OraCustomDatumClosur' and ROWID = 'AAAIE2AAXAAAFVaAAB';
insert into "MOB"."T201"("OBJECT_ID","OBJECT_NAME") values ('9830','/106faabc_BasicTreeUIKeyHandle');
delete from "MOB"."T201" where "OBJECT_ID" = '9830' and "OBJECT_NAME" = '/106faabc_BasicTreeUIKeyHandle' and ROWID = 'AAAIE2AAXAAAFVaAAI';
Best Regards
Krystian Zieja / mob -
Informatica failed to update records in target table
Hi,
Recently I converted hourly full load into incremental laod. everything is working good except updating records in target. Informatica not updating any records and I'm trying to understand and troubleshoot the issue. details given below
I ran mapping debugger and came to know Filter transformation is filtering the data instead of passing to next transformation because update flag is X.
ETL_PROC_WID AND LKP_ETL_PROC_WID are same and update flag = X.
I dont understand why ETL_PROC_WID AND LKP_ETL_PROC_WID are same. As per my knowledge Informatica generates new ETL_PROC_WID for every ETL run. If you know anything about it please let me know.
I executed code in SYS_COL_DIFF and UPDATE_FLG manually(on paper for few records) by assuming ETL_PROC_WID AND LKP_ETL_PROC_WID are different and got UPDATE_FLG=U
If you know how MPLT_GET_ETL_PROC_WID mapplet in OOTB works please let me know.
appreciate you for your help
Thanks
Jay.
Edited by: JV123 on Dec 12, 2012 9:29 AMWelcome to the forum.
You can try your hands on MERGE while performing the INSERT operation
Something like this
MERGE INTO Emp_Org eo
USING (
select Empno,deptno,empname,currenttimestamp from Emp
) x
ON (
eo.Empno = x.Empno
WHEN NOT MATCHED THEN
INSERT
Empno,
country,
Emporg,
currenttimestamp,
Targettimestamp
VALUES
x.Empno,
'USA', /* Used Constant here */
'Emporg', /* Used Constant here */
x.currenttimestamp,
sysdate /* Used Constant here */
);If you are not ok with the solution, then provide some sample data with expected output -
Execute query. Not all records retrieved.
Hi everyone.
I have made a screen with the data block and layout wizzards.
When I click on the default toolbar "Execute query" it brings only 68 records and there are about 25,000!.
I have a botton which displays a LOV of the same table and the LOV is working well, it brings all the records in the table.
Any idea ???
Thanks!If you go to the bottom of the query, does
it get the next set of records??
Oracle forms buffers the records it gets
based upon the number of records buffered
in the "block properties".
Go to block properties. Look at Number of
records buffered. If you want it to get
ALL records. Set the Query ALL records switch
to "Yes". Try it again.
Hopefully this helps. -
How do I insert/update certain records that I've identified in cursors..?
Morning gurus..
As the title asks, I have this script that loads records into a temp table then compares these with whats in the ORACLE table. When each temp table record has been identified as being either needing to be inserted or not, how do I then insert these identified records? As in, how can I do..
INSERT INTO xxxxxxxxxxx_SUPPLIERS (vendor_id, vendor_name,segment1, end_date_active) VALUES (2, 'SUPPLIER NAME 2', 100002, sysdate); ..but I'll need to put in some variable names where the values have been written in above - is this allowed..?
thanks,
Ehi,
here is a small sample for your query.... given Procedure InsertExcep is reading data from table code_master and inserting all fetched records into another table test_code_master..... before insert you can do any comparison within loop..... or even can give any Update statement....
CREATE TABLE code_master
CODE VARCHAR2(10),
CODE_DESC VARCHAR2(70)
INSERT INTO CODE_MASTER ( CODE, CODE_DESC ) VALUES (
'ORG0007', 'PARTNERSHIP FIRM');
INSERT INTO CODE_MASTER ( CODE, CODE_DESC ) VALUES (
'ORG0008', 'CONSULTANCY FIRM OR PROFESSIONAL BODY');
INSERT INTO CODE_MASTER ( CODE, CODE_DESC ) VALUES (
'ORG0009', 'SOCIAL ORGANIZATION');
INSERT INTO CODE_MASTER ( CODE, CODE_DESC ) VALUES (
'ORG0010', 'EMBASSY');
CREATE TABLE test_code_master
CODE VARCHAR2(10),
CODE_DESC VARCHAR2(70)
CREATE OR REPLACE PROCEDURE InsertExcep
AS
CURSOR insertdata
IS
SELECT code,code_desc
FROM code_master ;
BEGIN
FOR i IN insertdata
LOOP
BEGIN
INSERT INTO test_code_master (code,code_desc)
VALUES(i.code,i.code_desc);
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ( 'Error during Insert code - '||i.code );
END;
END LOOP;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE ( 'Error in InsertExcep' );
END;
hope this will work...
Thanx
MB -
NUmber of records in query mismatch number of records in file
Hi Experts,
I am running an APD having as source a query and target file.
The issue is that in my query i have 78 records and in my file 138 any possible solutions??
Points will be awarded for useful answers.
Kevinhello Kevin,
The reason for getting more records in file can be due to:
May be you will having a characteristic due to which the Key Figure values are getting split up into many rows.
For eg:
If you have condition type in Rows, and have other characteristics like, Material, Customer etc.. you will get out put as:
Sales Org Sales Dist AGI Code UC AGi code Bill Qty CondVal(Cond type1) CondVal(Condition type2) CondVal(Cond type3)
A B C D 122 10.00 0 0
A B C D 122 0.00 12.00 0
A B C D 122 0.00 0.00 15.00
When you will remove the char due to which you are getting the above output, you will get proper result as follows:
Sales Org Sales Dist AGI Code UC AGi code Bill Qty CondVal(Cond type1) CondVal(Condition type2) CondVal(Cond type3)
A B C D 122 10.00 12.00 15.00
Hope it helps
Regards
Lavanya -
Dear All,
I have a requirement, to write a SQL query to populate the records which are inserted less than 10 no of records.
The tables has the cretaed_date column and along with other key column which will have unique values.
Ex1: The user might have inserted records from application, per week basis, between the date range '01-jun-2013' - 08-jun-2013 , the no of records created by the user during this week may be less than 10 records or more.
But I want to populate the records by giving date range that too, it should pick the records the count which fall with in 10 records.
I dont want the query to populate the records if the user has inserted more than 10 records in a week.
Ex2:
User 1 has created 15 records during the week 1 ( the query should not populate this ).
User 2: has cretaed less than 10 records from the UI during the week 2. ( This details should get populated ).
ThanksUse COUNT to find how many rows where inserted in a week.
If this does not answer your question then please read Re: 2. How do I ask a question on the forums? And provide necessary details. -
Unable to INSERT PL/SQL record with EXECUTE IMMEDIATE
Hi All,
I am selecting data from a source table and after some modification inserting into a target table. Source and target table name are available at run time. You can say only source table structure is fixed.
I have crated a pl/sql table of type source record and inserting record by record in target table using execute immediate. But I am not able to write
EXECUTE IMMEDIATE string USING pl_sql_table(index); and getting error as
PLS-00457: expressions have to be of SQL types
Please see the part of code below. Is it possible to use FORALL with dynamic sql like
FORALL pl_sql_table.FIRST .. pl_sql_table.COUNT
EXECUTE IMMEDIATE .... pl_sql_table(j); -- Like this.
Please suggest why I am not able to write record here. I also want to replace 'INSERT in a loop' with a single INSERT statement out of the loop, to upload whole pl_sql table into target table in one go.
Thanks,
Ravi
DECLARE
TYPE rec_tab_CMP IS RECORD
model_id NUMBER(38),
absolute_rank NUMBER(5)
v_rec_tab_CMP rec_tab_CMP;
TYPE t_rec_tab_CMP IS TABLE OF v_rec_tab_CMP%TYPE INDEX BY BINARY_INTEGER;
v_records_CMP t_rec_tab_CMP;
rc SYS_REFCURSOR;
v_old_table_name VARCHAR2(30); -- passed from parameter
v_new_table_name VARCHAR2(30); -- passed from parameter
dyn_str VARCHAR2(500);
v_columns_str VARCHAR2(200) := ' model_id, absolute_rank ';
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE '|| v_new_table_name || ' AS SELECT * FROM ' || v_old_table_name ||' WHERE 1 = 2 ' ;
OPEN rc FOR 'SELECT '|| v_columns_str ||' FROM '|| v_old_table_name;
FETCH rc BULK COLLECT INTO v_records_CMP;
FOR j IN 1..v_records_CMP.COUNT
LOOP
v_records_CMP(j).model_id := 1; -- Do someting here, This thing can be performed in SQL stmt directly.
dyn_str := 'INSERT INTO '|| v_new_table_name ||' ( '|| v_columns_str || ' ) VALUES (:1, :2) ';
EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j).model_id ,
v_records_CMP(j).absolute_rank ;
-- Here in place of two columns I want to use one record like
-- EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j);
-- But it is giving me error like
-- EXECUTE IMMEDIATE dyn_str USING v_records_st(j);
-- PLS-00457: expressions have to be of SQL types
END LOOP;
CLOSE rc;
END;
/You cannot bind PL/SQL record types to dynamic SQL.
Possibly you could work around this by declaring the INDEX-BY table of records at package specification level, e.g.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE PACKAGE package_name
2 AS
3 TYPE tt_emp IS TABLE OF emp%ROWTYPE;
4 t_emp tt_emp;
5 END package_name;
6 /
Package created.
SQL> CREATE TABLE new_emp
2 AS
3 SELECT *
4 FROM emp
5 WHERE 1 = 0;
Table created.
SQL> DECLARE
2 v_table_name user_tables.table_name%TYPE := 'NEW_EMP';
3 BEGIN
4 SELECT *
5 BULK COLLECT INTO package_name.t_emp
6 FROM emp;
7
8 EXECUTE IMMEDIATE
9 'BEGIN ' ||
10 ' FORALL i IN 1 ..package_name.t_emp.COUNT ' ||
11 ' INSERT INTO ' || v_table_name ||
12 ' VALUES package_name.t_emp (i); ' ||
13 'END;';
14 END;
15 /
PL/SQL procedure successfully completed.
SQL> SELECT empno, ename
2 FROM new_emp;
EMPNO ENAME
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SQL> -
How I can change this query to retun both records (max scores)
This query does not retrieve records when I have two records for the same pidm (unique key) with the same score and different test date
SORTEST_PIDM IS 'This field identifies the internal identification number of the student.'
SELECT sortest_pidm,
CASE sortest_tesc_code WHEN 'S02' THEN 'S06' END CASE,
sortest_tsrc_code,
test_date,
sortest_test_score
FROM (SELECT a.*,
ROW_NUMBER ()
OVER (
PARTITION BY a.sortest_tesc_code, a.sortest_pidm
ORDER BY
a.sortest_test_score DESC,
a.sortest_test_date DESC)
rn
FROM sortest a
WHERE --- a.sortest_pidm = 228709
-- sortest_pidm = 107168
---- sortest_pidm = 30021 --
and a.sortest_tesc_code = 'S02'
AND a.sortest_tsrc_code NOT IN ('SUPR'))
WHERE rn = 1;like this one
SORTEST_PIDM SORTEST_TESC_CODE SORTEST_TEST_DATE SORTEST_TEST_SCORE
30037 S02 03/01/2010 00:00:00 630
30037 S02 05/01/2010 00:00:00 630 It retrieves data when the scores are different
like this one
SORTEST_PIDM SORTEST_TESC_CODE SORTEST_TEST_DATE SORTEST_TEST_SCORE
107168 S02 06/01/2010 00:00:00 690
107168 S02 10/01/2010 00:00:00 800I need to be able to return the maximun test scrore in both cases...
here is some code to create a test table and insert the codes, I took out the sortest the table is already in the DB, I called the test table test...
CREATE TABLE TEST
TEST_PIDM NUMBER(8) NOT NULL,
TESC_CODE VARCHAR2(4 CHAR) NOT NULL,
TEST_DATE DATE NOT NULL,
TEST_SCORE VARCHAR2(5 CHAR) NOT NULL
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 30037,'S02',to_date('03/01/2010','mm/dd/yyyy'),'630' from dual ;
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 30037,'S02',to_date('05/01/2010','mm/dd/yyyy'),'630' from dual ;
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 107168 ,'S02',to_date('06/01/2010','mm/dd/yyyy'),'690' from dual ;
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 107168 ,'S02',to_date('10/01/2010','mm/dd/yyyy'),'800' from dual;
Hi,
893973 wrote:
This query does not retrieve records when I have two records for the same pidm (unique key) with the same score and different test date
SORTEST_PIDM IS 'This field identifies the internal identification number of the student.'
SELECT sortest_pidm,
CASE sortest_tesc_code WHEN 'S02' THEN 'S06' END CASE,
sortest_tsrc_code,
test_date,
sortest_test_score
FROM (SELECT a.*,
ROW_NUMBER ()
OVER (
PARTITION BY a.sortest_tesc_code, a.sortest_pidm
ORDER BY
a.sortest_test_score DESC,
a.sortest_test_date DESC)
rn
FROM sortest a
WHERE --- a.sortest_pidm = 228709
-- sortest_pidm = 107168
---- sortest_pidm = 30021 --
and a.sortest_tesc_code = 'S02'
AND a.sortest_tsrc_code NOT IN ('SUPR'))
WHERE rn = 1;like this one
SORTEST_PIDM SORTEST_TESC_CODE SORTEST_TEST_DATE SORTEST_TEST_SCORE
30037 S02 03/01/2010 00:00:00 630
30037 S02 05/01/2010 00:00:00 630 It retrieves data when the scores are different
like this one
SORTEST_PIDM SORTEST_TESC_CODE SORTEST_TEST_DATE SORTEST_TEST_SCORE
107168 S02 06/01/2010 00:00:00 690
107168 S02 10/01/2010 00:00:00 800I need to be able to return the maximun test scrore in both cases...
here is some code to create a test table and insert the codes, I took out the sortest the table is already in the DB, I called the test table test... It looks like you renamed all the columns, too, making the query above useless. There's no danger in using the same column names in two or more tables, even in the same schema.
CREATE TABLE TEST
TEST_PIDM NUMBER(8) NOT NULL,
TESC_CODE VARCHAR2(4 CHAR) NOT NULL,
TEST_DATE DATE NOT NULL,
TEST_SCORE VARCHAR2(5 CHAR) NOT NULL
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 30037,'S02',to_date('03/01/2010','mm/dd/yyyy'),'630' from dual ;
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 30037,'S02',to_date('05/01/2010','mm/dd/yyyy'),'630' from dual ;
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 107168 ,'S02',to_date('06/01/2010','mm/dd/yyyy'),'690' from dual ;
insert into test (TEST_PIDM,TESC_CODE,TEST_DATE,TEST_SCORE) select 107168 ,'S02',to_date('10/01/2010','mm/dd/yyyy'),'800' from dual; If you want to pick the highest scores, regardless of test date, then don't include test_date in the analytic ORDER BY clause.
If you want to pick all the rows with the highest score in case of a tie, then use RANK instead of ROW_NUMBER. -
Hi
Am trying to insert 5 crore records into table A by selecting two diffrent tables(B&C).
I DONT KNOW WHETHER IT GETS INSRTED OR NOT.
when i give select count its giving 0 after very long time,
SELECT COUNT(ROWNUM) FROM A;
*0*
but when i select segment size,
SELECT SUM(BYTES)/1024/1024 MB FROM DBA_SEGMENTS WHERE SEGMENT_NAME='A';
*4700*
when i issue the following query,
truncate table a;
ORA-00054:RESOURCE BUSY ERROR
what i have to do now to get all rows inserted?
and i want to increase the performance of selection for that wat i should do?
Thanks
SivaHi,
>
I DONT KNOW WHETHER IT GETS INSRTED OR NOT.
>
The rows have been inserted but have been removed too (rolled back) because the session have finished and did not perform a commit.
>
truncate table a;
ORA-00054:RESOURCE BUSY ERROR
>
It seems you try to do this in a second session when the table A was locked because a commit was missing in first session.
>
what i have to do now to get all rows inserted?
>
You have to perform the insert again and perform a commit when the insert finishes.
>
that session is closed..
>
The insert is rolled back, that is PMON job. All transacctions without commit when the session have been finished are rolled back. Because of that you can't see the rows, because the are not any rows.
HTH -- johnxjean -- -
ADF: any good examples on inserting a new record
Hi, I'm currently developing a
web based application (using jsp + struts on top of ADF)
and I've seen many many demos and viewlets on
how to create a page that reads a list of employees
or master-detail relationship of records.
However, when I try to make a page which can insert
a new record (ex. new employee, new department, etc),
I am baffled, because I couldn't find a good example
that showed me how to do it.
Has anyone have a good example?
thank you.Did you check the tutorials page?
For example:
http://otn.oracle.com/products/jdev/collateral/tutorials/9050/bizcomp_jsp_tut.html -
How to stop a query on a last record?
I have a basic question. I have put a button on my form, which goes to the next_record (it goes on id-es). (on when button pressed action)
But I have a problem, when it comes to the last_record, it goes to the nex record which is not there ( it does not exist). I would like to stop the query on my last record. How to do it?
I had sometihng like it
if :atletika.idRezultata is null
last_record;
else
next_record;
end if;
but its not working.Hai,
If the block's INSERT ALLOWED property is set to YES, then it will go to new record.
Try setting this property to NO
Regards,
Manu.
If this answer is helpful or correct, please mark it. Thanks.
Maybe you are looking for
-
Program not executing in jar file. Help please.
I went through the tutorial about jars on the sun website and i created a jar file with a hello world program like this: "cd E:\Batch jar cfm test.jar m.txt test.class PAUSE" My m.txt contains this text: "Main-Class: test.class" The jar file is creat
-
Can i access a external Hard-drive attached to a time-capsule remotely?
Hello there, im sure i have seen this question floating around before but i there are many options to do this. i have a 2TB Time capsule and i have a 500gb external hardrive attched through the USB port? i am wanting to know if i can access that Hard
-
FCP Problem with Firewire output to external monitor and speaker ???Help
i have a g5 powermac. the problem is when using Final cut pro 4hd. when i output my work through firewire to my external monitor and speaker i have a problem with the audio signal. Theres feedback/noise/hiss from the speakers. The firewire connects t
-
Can Anyone help save my Nokia Lumia 1520?
Hello I am in need of help to save my Lumia 1520. I made the mistake of flashing my lumia 1520 (RM-937) with a lumia 1520 (RM-938) rom. Ever-since, my phone started acting out. The phone is stuck in aiplane mode and does not connect to GSM network an
-
Mac Pro 2009 - the base is uneven and "wobbles"
I just picked up a new 8-Core Mac Pro. I have a glass desktop table. Upon setting the Mac Pro on top of it, the unit "wobbles" I know the glass desktop is even and flat. From what I can tell the front right side and rear left (if looking from the fro