Need sql querry for this logic
Hi,
Edited by: 937506 on Jun 10, 2012 7:35 AM
937506 wrote:
Hi,
I have table like this,based on this table data i need one column for example "Value" based on this condition,
KEY A_VAL ETA_VAL RANGE DATE_ID SITE AREA UNIT Monthnumber Year
1111 35 36 50.45 2778 PLANT1 AREA2 CDU-4 8 2011
1111 40 41 50.45 2783 PLANT1 AREA2 CDU-4 8 2011
9010 114 37 50.45 2779 PLANT1 AREA2 CDU-3 8 2011
9010 41 35 50.45 2784 PLANT1 AREA2 CDU-3 8 2011
9011 1500 38 50.45 2789 PLANT2 AREA3 DHT-1 8 2011
9012 43 37 50.45 2774 PLANT1 AREA1 DHT-2 8 2011
9012 38 39 50.45 2781 PLANT1 AREA1 DHT-2 8 2011
9013 39 40 50.45 2782 PLANT1 AREA2 FCC 8 2011How to ask question
SQL and PL/SQL FAQ
Similar Messages
-
Need SQL code for this logic - - From Serial and To serial no.
In Forms 4.5 Screen I have two text boxes where i will be entering From Serial No
and to serial no.
I want the code which will check whether any number in between these from and to serial exists in a table or not ?
For Example
Select * from t; -- contains
serial number
321-456-789
123-456-654
321-569-986
321-569-987
When I enter from Serial no 321-456-789 and to serial no as 321-456-789.. I should get a message sayinig that 321-456-789 exists.
When I enter from Serial no 321-569-986 and to serial no as 321-569-988.
I should get a message sayinig that 321-456-986 exists.
I should get a message sayinig that 321-456-987 exists.
I should get a message sayinig that 321-456-988 not exists.
is it possible with a SQL query or do we need to go for procedure or temp table ?
If anybody ahving similar code please post it here.
Thanks in Advance
DevenderHi Devender,
Try this :
SQL> select * from t;
SN
321-456-789
123-456-654
321-569-986
321-569-987
SQL> var sn1 varchar2(11)
SQL> exec :sn1 := '321-569-986'
Procédure PL/SQL terminée avec succès.
SQL> var sn2 varchar2(11)
SQL> exec :sn2 := '321-569-988'
Procédure PL/SQL terminée avec succès.
SQL>1 select a.sn, decode(t.sn,null,'does not exists','already exists')
2 from
3 (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
4 ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
5 ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
6 from (select level
7 from dual
8 connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
9 )
10 )a,
11 t
12* where a.sn=t.sn(+)
SQL> /
SN DECODE(T.SN,NUL
321-569-986 already exists
321-569-987 already exists
321-569-988 does not exists
SQL> exec :sn1 := '321-456-789'
Procédure PL/SQL terminée avec succès.
SQL> exec :sn2 := '321-456-789'
Procédure PL/SQL terminée avec succès.
SQL> l
1 select a.sn, decode(t.sn,null,'does not exists','already exists')
2 from
3 (select substr(replace(:sn1,'-','')+rownum-1,1,3)||'-'
4 ||substr(replace(:sn1,'-','')+rownum-1,4,3)||'-'
5 ||substr(replace(:sn1,'-','')+rownum-1,7,3) as sn
6 from (select level
7 from dual
8 connect by level <= (replace(:sn2,'-','')-replace(:sn1,'-',''))+1
9 )
10 )a,
11 t
12* where a.sn=t.sn(+)
SQL> /
SN DECODE(T.SN,NUL
321-456-789 already exists
SQL> Nicolas. -
Need SQL statement for this logic....
Hi,
I want a SQL statement for updating the following changed last number .
Cuurently its:
SELECT * FROM TEST;
LAST NUMBER CHANGED LAST NUMBER
123518
12355265
123674659
9087648970
After updating with the required SQL statement table should look like
LAST NUMBER CHANGED LAST NUMBER
123518 0000123518
12355265 0012355265
123674659 0123674659
9087648970 9087648970
the last number should be appended with ZEROs and the length of changed last number should be 10 always. Hope its clear.
Appreciate your help.
Thanks in advance
Devenderselect last_number, lpad(to_char(last_number), 10 , '0') FROM test
-
Need sql querry for PreviousYear First Day Same Month And Currentday rec
Hi ,
I hAVE TABLE FOR EXAMPLE,
emp sal Arrivaldate
111 200 03-mar-2011
100 200 03-mar-2008
150 200 06-mar-2012
170 200 03-mar-2003
178 200 03-mar-2004
112 200 12-jun-2012-------------------->For Example THIS IS TABLE WE HAVE LOT OF RECORDS
I need querry to get based on this condition:Arrival Date is between Previous Year First Day Same Month And Current day.
Any one help me on this.....Hi,
To get the records between Previous Year First Day Same month to Current day..
SELECT TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM') AS last_yr_first_date, TRUNC(SYSDATE) AS PRESENT_DATE
FROM DUAL;Which Outputs to:
LAST_YR_FIRST_DATE PRESENT_DATE
6/1/2011 6/13/2012When you give TRUNC(sysdate) It will removes the Time part of the SYSDATE.
For Ex :
TRUNC(SYSDATE) means that is 6/13/2012 which doesn't give the time part in the query.
Which takes into account the day start that is from 12:00 A.M to today midnight 11.59 P.M.
And, One thing is that
emp sal Arrivaldate
111 200 03-mar-2011
100 200 03-mar-2008
150 200 06-mar-2012
170 200 03-mar-2003
178 200 03-mar-2004
112 200 12-jun-2012The arrivaldate is in Character format so you need to convert to date type as
SELECT TO_DATE(ARRIVALDATE,'DD-MON-YYYY') from your_table;
and the comparison can be done as
SELECT *
FROM YOUR_TABLE
WHERE TO_DATE (ARRIVALDATE, 'DD-MON-YYYY')
AND TRUNC (ADD_MONTHS (SYSDATE, -12), 'MM')
AND TRUNC (SYSDATE);Good day!!!!!!!!!!!!!!!!!!!!!!!!
Thanks,
Shankar -
Need sql querry for records between Current Year First day and Current Day
Hi,
I have a table like this...
Empid Empname DOJ
TEST1 ERDDF 19-Jun-2011
TEST2 AA 22-Mar-2011
TEST3 SS 22-Oct-2011
TEST4 VV 01-Jan-2012
TEST5 HH 01-Apr-2012
TEST6 AS 18-Jun-2012
TEST7 ER 26-Jun-2012
TEST8 ERDDF 28-Jun-2012
My output like this...
Empid Empname DOJ
TEST4 VV 01-Jan-2012
TEST5 HH 01-Apr-2012
TEST6 AS 18-Jun-2012
TEST7 ER 26-Jun-2012
Logic:
records between Current Year First day and Current Day(sysdate)937506 wrote:
Hi,
I have a table like this...
Empid Empname DOJ
TEST1 ERDDF 19-Jun-2011
TEST2 AA 22-Mar-2011
TEST3 SS 22-Oct-2011
TEST4 VV 01-Jan-2012
TEST5 HH 01-Apr-2012
TEST6 AS 18-Jun-2012
TEST7 ER 26-Jun-2012
TEST8 ERDDF 28-Jun-2012
My output like this...
Empid Empname DOJ
TEST4 VV 01-Jan-2012
TEST5 HH 01-Apr-2012
TEST6 AS 18-Jun-2012
TEST7 ER 26-Jun-2012
Logic:
records between Current Year First day and Current Day(sysdate)Probably you are looking for :
where DOJ between trunc(sysdate,'YYYY') and sysdateRead {message:id=9360002} and always provide details mentioned in this thread. -
Need sql querry for getting previous day records only
Hi ,
i have a table with following records,
emp sal date
111 200 03-mar-2011
100 200 03-mar-2008
15 200 06-mar-2012
17 200 03-mar-2003
178 200 03-mar-2004
11 200 11-jun-2012
i need only previous day records only(11 200 11-jun-2012).can any one help on this query?insa wrote:
Except trun you can use Like operator--
select * from emp where date like sysdate-1;
Is it helpful for you?That is most certainly not a helpful answer. the LIKE operator is a string comparison operator and should not be used with dates. Doing so will cause an implicit date to character conversion based on the sessions NLS settings and would be not different to doing:
select * from emp where to_char(date) = to_char(sysdate-1)... which will cause a lack of index usage, and also not deal with any time component within the date.
Please ensure you test your answers before posting them. Several people had already given correct answers here with explanations as to why they are better than other methods. -
Hi
table1
id cus_id val
boi p gh
hdc s vc
123 p xy
123 s xz
123 m xb
123 ll zx
Note: 123 is default values
o/p
id cus_id val
boi p gh
boi s xz
boi m xb
boi ll zx
hdc s vc
hdc p xy
hdc m xb
hdc ll zx
123 p xy
123 s xz
123 m xb
123 ll zxHi,
Pleaes check this:
WITH t AS
(SELECT 'boi' id, 'p' cus_id, 'gh' val FROM DUAL
UNION ALL
SELECT 'hdc', 's', 'vc' FROM DUAL
UNION ALL
SELECT '123', 'p', 'xy' FROM DUAL
UNION ALL
SELECT '123', 's', 'xz' FROM DUAL
UNION ALL
SELECT '123', 'm', 'xb' FROM DUAL
UNION ALL
SELECT '123', 'll', 'zx' FROM DUAL),
tt AS
(SELECT *
FROM t
WHERE id = '123')
SELECT a.id, b.cus_id, b.val
FROM t a, tt b
WHERE a.id <> '123' AND a.cus_id <> b.cus_id
UNION ALL
SELECT * FROM t
order by 1;
Cheers,
Manik. -
9. DATA SET (ALIAS TBL)
SSN Name Background Check Date Review Date
123456789 Bob Smith 4/15/04 5/10/05
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
REQUIREMENTS
Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
EXPECTED RESULTSET
SSN Name Background Check Date Review Date
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULLDATA SET (ALIAS TBL)
------------------------------------------------------------------------------------------------------------------|
SSN Name Background Check Date Review Date|
-------------------------------------------------------------------------------------------------------------------|
123456789 Bob Smith 4/15/04 5/10/05
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL
REQUIREMENTS
Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
EXPECTED RESULTSET
SSN Name Background CheckDate Review Date
987654321 Sue Jones 12/2/05 3/4/06
123456789 Bob Smith 12/31/05 NULL -
Need pl/sql stmnts. for this simple logic
Hi,
I need PL/SQL program for this simple logic i am doing mistake somewhere unbale to trace
out ..
select * from GSR03_PO_DTL;
PO_NUM
L53177000 -- > no changes reqd (only one entry with new format)
L00041677 --> to be updated to L41677000(only one entry with OLD format)
L43677000 -- > no change reqd (exists one row with new format and old format like below)
L00043677 -- > to be deleted this is old format (and new format like above already exists)
EX:
L00012345 --- old format
L12345000 --- new format
Hope question is clear. I written the following program.
update is working fine but delete is not working.
Please help.
Thanks in Advance
Devender
declare
Cursor c_test is
(select po_num from GSR03_PO_DTL);
BEGIN
FOR r_test in c_Test
LOOP
dbms_output.put_line (r_test.po_num);
IF ('L'||substr(r_test.po_num,5,5)) = ('L'||substr(r_test.po_num,2,5)) then
dbms_output.put_line ('delete stmnt');
END IF;
EXIT WHEN c_test%NOTFOUND;
END LOOP;
FOR r_test in c_Test
LOOP
IF r_test.po_num like 'L000%' then
IF ('L'||substr(r_test.po_num,5,5)) is not NULL then
update GSR03_PO_DTL set PO_NUM = 'L'||substr(po_num,5,5)||'000'
where po_num like 'L000%' ;
dbms_output.put_line ('update stmnt');
END IF;
END IF;
END LOOP;
END;
*********************No need for PL/SQL, man.
SQL> SELECT po_no FROM po1
2 /
PO_NO
L53177000
L00041677
L43677000
L00043677
SQL> UPDATE po1 y
2 SET y.po_no = 'L'||substr(y.po_no,5,5)||'000'
3 WHERE y.po_no LIKE 'L000%'
4 AND NOT EXISTS ( SELECT null FROM po1 x
5 WHERE x.po_no = 'L'||substr(y.po_no,5,5)||'000')
6 /
1 row updated.
SQL> DELETE FROM po1 y
2 WHERE y.po_no LIKE 'L000%'
3 AND EXISTS ( SELECT null FROM po1 x
4 WHERE x.po_no = 'L'||substr(y.po_no,5,5)||'000')
5 /
1 row deleted.
SQL> SELECT po_no FROM po1
2 /
PO_NO
L53177000
L41677000
L43677000
SQL> Cheers, APC -
Hi,
I need a PL/SQL code for this one...
Let me know if something is not clear...
1) The table CLOB_CLOBJECT_CDA has the columns described below...
Explaining only those fields which are important in this context
-- CDA_STEP_ID : Basically a Sequence
-- CLOBJECT_SOURCE1_ID : Every id has got a set of records
-- CLOBJECT_SOURCE2_ID : Every id has got a set of records
-- LVL : There are total 8 levels..
This is the main aim :
1) There are total 16 million rows..(limited to 10 rows here)
2) We need to go through level by level (LVL column) & insert the intersection records (CLOBJECT_SOURCE1_ID intersect CLOBJECT_SOURCE2_ID)
into another table...but this is how it goes..
Level (LVL column) 3's basically have CLOBJECT_SOURCE1_ID as level (LVL column) 2 CDA_STEP_ID's..
(consider the statement --** where CLOBJECT_SOURCE1_ID = 285 which is same as 1st insert statement step id)..
The above process goes for next levels until 8..(so have to use loops)
So for ex :
We go through the first insert statement and insert the insertion records only when both CLOBJECT_SOURCE1_ID & CLOBJECT_SOURCE2_ID has got records ..
If we don't find any records for both of them we should skip the corresponding step id when we go to the next levels...
Let's go through the 1st insert statement...
-- We have CDA_STEP_ID = 285 & two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 74...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 74 ..(In fact we insert counts into this table only if they have records)
-- If so, we insert the intersection records into CDA_MRN_RESULTS ( we do have counts for both of them..) with CDA_STEP_ID 285...
-- Then we insert the step id which is 285 along with the count into CLOBJECT_COUNTS..
Let's go through another insert statement...
-- Consider CDA_STEP_ID = 288 which has two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 92...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 92 ..(we have records for 19 but not for 92)
-- So we should not proceed with this..& also skip all those records (future records with increasing levels..basically level 3's) which have got 288 as CLOBJECT_SOURCE1_ID..
(As said earlier that the present CDA_STEP_ID will always be CLOBJECT_SOURCE1_ID in the next level)...
I wrote the following code which is after the statement...
Let me have the create & insert statements here..
create table CLOB_CLOBJECT_CDA
CDA_STEP_ID NUMBER,
CDA_ID NUMBER,
CDA_SEQ_NUMBER NUMBER,
CLOBJECT_SOURCE1_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE1_ID NUMBER,
CLOBJECT_OPERATOR VARCHAR2(3000),
CLOBJECT_SOURCE2_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE2_ID NUMBER,
LVL NUMBER
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (285, 285, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 74, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (286, 286, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 75, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (287, 287, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 91, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (288, 288, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 92, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4869, 4869, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 91, 3); -- **
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4870, 4870, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4871, 4871, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 93, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4880, 4880, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 91, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4881, 4881, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4882, 4882, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 93, 3);
create table CDA_MRN_RESULTS
CDA_STEP_ID NUMBER,
MRN NUMBER,
INSERT_DATE_TIME DATE
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 4, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 6, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
create table CLOBJECT_COUNTS
CDA_STEP_ID NUMBER,
CLOBJECT_COUNT NUMBER,
DATE_TIME DATE
Insert into CLOBJECT_COUNTS values (19,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (74,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (75,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (91,2, to_date('19-10-2011', 'dd-mm-yyyy'));The output goes into two tables...
CDA_MRN_RESULTS : O/p of intersection records between source1 & source2 id
CLOBJECT_COUNTS : Step id with counts ...(useful for skipping next level step id's if either of source id has "0" counts)
Any help is appreciated..
Thanks..I tried to code this..but looping takes a lot of time..I want to skip certain rows where source1_step_id & source_2_step_id are not in clobject_counts table as we proceed to the next levels..Not sure how to skip the rows..
declare
cursor c1 (p_level varchar2 ) is
Select * from clob_clobject_cda
where lvl = p_level ;
TYPE V_TT IS TABLE OF C1%ROWTYPE INDEX BY PLS_INTEGER;
L_TT V_TT;
v1 number;
v2 number;
v_step_id number;
v_operator varchar2(100) := '';
begin
for i in 2..8 loop
open c1(i);
LOOP
FETCH C1 BULK COLLECT INTO L_TT LIMIT 500;
FOR indx IN 1 .. L_TT.COUNT
LOOP
v1 := L_TT(indx).clobject_source1_id;
v2 := L_TT(indx).clobject_source2_id;
v_step_id := L_TT(indx).cda_step_id;
v_operator := L_TT(indx).clobject_operator;
Execute Immediate ('Insert into cda_mrn_results Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v1 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' ||
v_operator ||
' Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v2 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' );
Insert --+ Append
into clobject_counts Select cda_step_id, count(distinct mrn),
insert_date_time dt from cda_mrn_results where cda_step_id = v_step_id group by cda_step_id,insert_date_time;
COMMIT;
END LOOP;
EXIT WHEN L_TT.COUNT = 0;
END LOOP;
CLOSE C1;
End Loop;
Commit;
End; -
Hi
I need a procedure 4 this logic,
Need to get 32+ inputs in procedure of same type varchar2,
If comp_id !=360
insert 32 inputs in table column-> value using custom-id
Note:
Column : brand-code,value,custom_name using custom_id
brand-code gets from comp-id from another table
i/p- from procedure comp_id and 32 inputs
This 32 inputs should use varray cocept
end if;
ex:
table 1
brand_code custom-id value editble
table 2
custom-id custom-name
Could you please share ur suggestionsCreate or replace procedure cdm_cl_proc is
v_sqnum number(3);
cursor c1 is
select dcn, pp_code from d_cl_ext;
Cursor c2 is
Select t_code, s_date, area_chrg, rc_pct from d_c_p_ext;
Begin
for v1 in c1
Loop
update d_cl set pp_code = v1.pp_code
where dcn=v1.dcn;
select d_sqnum into v_sqnum from d_cl
where dcn=v1.dcn;
For v2 in c2
Loop
Update d_c_p set area_chrg= v2.area_chrg, rc_pct=v2.rc_pct
Where t_code= v2.t_code and s_date = v2.s_date
and d_sqnum = v_sqnum;
if mod(c2%rowcount,1000)=0 then
commit;
end if;
End loop;
if mod(c1%rowcount,1000)=0 then
commit;
end if;
End loop;
Commit;
End;
I amable to load the data when dcn is matched but, if the dcn is not matched no data found error is coming. can u suggest error handling for this. -
APP-ALR-04106: Please correct the user-defined SQL statement for this alert
Hi All,
I have created an alert for engineering module in R12. It got tested and was working fine. when the user testing it, while trigger the alert getting the error, "APP-ALR-04106: Please correct the user-defined SQL statement for this alert".
when verified the alert, it got verified and ran also. It parsed the query successfully and when run it fetched few records.
Need help in resolving the issue.
Thanks in advance.
Regards,
sri
Edited by: user10939296 on Jan 18, 2010 1:16 AMHi Sri;
I have already gone through the Note: 948037.1. But this note is related to 11i. The solution provided in the Note is for 11i.
I am facing this issue in R12. Is this patch applicable to R12?I belive its not. But u can check Solution part 4 for your instance, at least it can give you idea. The other note in metalink related bug and all for R11 too.
I belive its better way to rise Sr while waiting other forum user response to that thread
Regard
Helios -
Need sql query for typical scenario
Hello Champs,
I have a scenario where I am suppose to fetch data from a schema which is developed by other team ... (there are no primary keys even)
the table structure is -
Column A Column B Column C Column D
1 h 6 u
1 h 7 u
1 h 8 u
2 g 9 i
2 g 0 i
2 g 7 i
3 t 3 h
3 t 4 h
3 t 5 i
and my output should be exactly like :
1 h 6,7,8 u
2 g 9,0,7 i
3 t 3,4 h
so basically I want comma separated values for column c where remaining column values are same ...
is it possible to achieve this result via SQL?? if not then what is the other solution??
Please help .. I am working in IST and need solution urgently for this .. please help .
TIA,
Regards,
Chintanif you have 11g
WITH t AS (SELECT 1 cola,
'h' colb,
6 colc,
'u' cold
FROM DUAL
UNION
SELECT 1,
'h',
7,
'u'
FROM DUAL
UNION
SELECT 1,
'h',
8,
'u'
FROM DUAL
UNION
SELECT 2,
'g',
9,
'i'
FROM DUAL
UNION
SELECT 2,
'g',
0,
'i'
FROM DUAL
UNION
SELECT 2,
'g',
7,
'i'
FROM DUAL
UNION
SELECT 3,
't',
3,
'h'
FROM DUAL
UNION
SELECT 3,
't',
4,
'h'
FROM DUAL
UNION
SELECT 3,
't',
5,
'i'
FROM DUAL)
SELECT cola, colb, listagg (colc, ',') WITHIN GROUP (ORDER BY colc) colc, cold
FROM t
GROUP BY cola, colb, cold
COLA COLB COLC COLD
1 h 6,7,8 u
2 g 0,7,9 i
3 t 3,4 h
3 t 5 i -
Need sql querry to retive the data from sysdate to last365 days data.
Hi ,
I need sql querry to retrive the data based on this condition:date Between Previous 365 days and current day.
emp sal date
1 200 03-mar-2011
1 200 03-mar-2008
1 200 06-mar-2012
1 200 03-mar-2003
1 200 03-mar-2004
1 200 03-mar-2005
and so on.......lot of records....
i need the all the employee data from currentdate(sysdate) to previous 365 days data...
Edited by: 937506 on Jun 7, 2012 4:26 AM937506 wrote:
Hi ,
I need sql querry to retrive the data based on this condition:date Between Previous 365 days and current day.
emp sal date
1 200 03-mar-2011
1 200 03-mar-2008
1 200 06-mar-2012
1 200 03-mar-2003
1 200 03-mar-2004
1 200 03-mar-2005
and so on.......lot of records....
i need the all the employee data from currentdate(sysdate) to previous 365 days data...
Edited by: 937506 on Jun 7, 2012 4:26 AMJust you can do this
<date_column> between sysdate-365 and sysdateAnd DATE is a reserved word and you cannot use it as a column name. -
I want sql query for this output
hi guys
could u tell how can i write sql query for this out put
i have one table like this
ID ACCOUTID TAX
1 1 A
2 1 B
3 2 C
4 2 D
5 3 E
7 NULL F
8 NULL G
MY OUT PUT MUST BE LIKE THIS
ID AID TAX
2 1 A
4 2 D
7 NULL F
8 NULL G
HERE IN THIS OUTPUT I SHOULD HAVE
MAXIMAM ID VALUE FOR A REPEATED AID VALUES
AND
THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
I KNOW ONE SOLUTION LIKE THIS
SELECT MAX(ID),AID,TAX
FROM TABLE T
GROUP BY AID,TAX
UNION ALL
SELECT ID, AIC,TAX
FROM TABLE T
WHERE AID IS NULL;
BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
COULD U PLZ TELL A SOL.Will this help:
SQL> with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21 and (rn = 1 or ACCOUTID is null)
22 /
ID AID T
2 1 B
4 2 D
8 G
7 F
-- If I leave out the OR condition then you'll get this:
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (
3 select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
4 select 2, 1, 'B' from dual union all
5 select 3, 2, 'C' from dual union all
6 select 4, 2, 'D' from dual union all
7 select 5, 3, 'E' from dual union all
8 select 7, NULL, 'F' from dual union all
9 select 8, NULL, 'G' from dual
10 )
11 --
12 select id, ACCOUTID AID, Tax
13 from
14 (
15 select t.*
16 ,count(1) over (partition by t.ACCOUTID) cn
17 ,row_number() over (partition by t.ACCOUTID order by id desc) rn
18 from t
19 )
20 where cn > 1
21* and rn = 1
SQL> /
ID AID T
2 1 B
4 2 D
8 G
--which follows the description you've given, but not the output
Maybe you are looking for
-
Can two people access the same online number at th...
Me and my dad share the same online number for friends and colleagues to call us, but it seems that the calls that come through to me are ad-hoc whilst my dad gets every call on his system. I just wondered if this is because 2 systems are trying to
-
Error while sending Bdoc data frm CRM to R3
Hi All, We have created a BDoc containing a Ztable which is send from CRM to R/3 where it will update another Z table create for this in R3. We have tried here the follwoing steps:- a. Created the Z table in both systems. b. Created a new messaging B
-
What in the new update? i cant work it out? question 2. after ive update my fone why does it freeze an shut down.. i have to take the batter out etc? why that
-
Package for payroll what is the problem in this..
Specification CREATE OR REPLACE package PKG_PAYROLL as type cur is ref cursor; procedure pro_getstate(p_cid number,p_cur out cur); procedure pro_getcountry(p_cur out cur); procedure pro_getdesignation(p_cur out cur); procedure pro_getdepartment(p_cur
-
How to decrease the size of the JS and CSS File
Hi experts, I m facing a bandwidth problem because i m accessing an application from a PDA and i noticed that it takes a very long time to load a very simple page. After some investigation, i noticed that its because the JS and CSS files downloaded a