Updating records using self join or row number function
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP TABLE #Temp
GO
CREATE TABLE #Temp
ID INT
, CYear INT
, Val INT
, Descrp Varchar(10) NULL
, Cd INT
, ToBeUpdated Varchar(5) NULL
INSERT INTO #Temp
ID
, CYear
, Val
, Descrp
, Cd
, ToBeUpdated
SELECT 2014, 2013, 111, 'ABC', 2, NULL
UNION
SELECT 2014, 2014, 111, 'XYZ', 2, NULL
UNION
SELECT 2014, 2014, 222, 'TTT', 3, NULL
UNION
SELECT 2014, 2013, 333, 'ZZZ', 4, NULL
UNION
SELECT 2014, 2014, 333, 'VVV', 5, NULL
SELECT * FROM #Temp
ORDER BY Val, CYear
All, I have the above #table. You'll notice that there are duplicate values in "Cd" column i.e. "Cd=2".
If the values in ID, Val and Cd are same then, I want to update the "CodeFlag" column for those records with "Descrp" column of
the recent CYear. So, my "ToBeUpdated" column would have a value of "XYZ" for both the records where Cd=2 (Since, XYZ is the Descrp for CYear 2014(the latest one))
Also, if the values in ID and Val column are same but values in "Cd" is different, then ToBeUpdated = Descrp of that particular record. In my case the "ToBeUpdated" value for Cd=4 would be "ZZZ" and for Cd=5, it would be "VVV"
since the ID and Val column values are same for those records. Let me know if you have any questions.
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP TABLE #Temp
GO
CREATE TABLE #Temp
ID INT , CYear INT , Val INT , Descrp Varchar(10) NULL , Cd INT , ToBeUpdated Varchar(5) NULL)
INSERT INTO #Temp
ID , CYear , Val , Descrp , Cd , ToBeUpdated)
SELECT 2014, 2013, 111, 'ABC', 2, NULL
UNION
SELECT 2014, 2014, 111, 'XYZ', 2, NULL
UNION
SELECT 2014, 2014, 222, 'TTT', 3, NULL
UNION
SELECT 2014, 2013, 333, 'ZZZ', 4, NULL
UNION
SELECT 2014, 2014, 333, 'VVV', 5, NULL
;with mycte as (SELECT *, row_number() Over(partition By ID, Val , Cd order by CYear DESC) rn
, row_number() Over(partition By ID, Val order by Descrp) rn1
FROM #Temp)
SELECT m1.ID ,m1.CYear,m1.Val,m1.Descrp , ToBeUpdated=d.descrp from mycte m1
Cross apply (Select Top 1 descrp from mycte m2 WHERE m2.id=m1.ID AND m1.Val=M2.Val AND m1.cd=m2.cd AND m1.rn>=m2.rn) d(descrp)
Similar Messages
-
Oracle query with out using self join
hi friends,
i have one table for exeample PERSTATUS
pk/fK STUDENT NUMBER SUBJECT MARKS STATUS
1 ACCOUNTS 15 RED
1 MATHS 35 YELLOW
1 SCINECE 45 GREEN
2 ACCOUNTS 55 BROWN
2 MATHS 35 YELLOW
2 SCINECE 45 GREEN
3 ACCOUNTS 15 RED
3 MATHS 35 YELLOW
3 SCINECE 45 GREEN
i want students how status is both red and yellow so i am using self join
i want students status is both red and yellow so i am using self join
SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS1 FROM PERSTATUS PS ,PERSTATUS PS1
WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER
PS.STATUS='RED' AND PS1.STAUTS='YELLOW'
i want students status is both RD and YELLOW AND GREEN so i am using self join( two self joinS}
SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS,PS2.STATUS FROM PERSTATUS PS ,PERSTATUS PS1,PERSTATUS PS2
WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER AND PS.STUDENTNUMBER-PS2.STUDENTNUMBER
PS.STATUS='RED' AND PS1.STAUTS='YELLOW' AND PS2.STAUTUS='GREEN'
if i require MORE STATUS then more self joins required, is there any alternative to achive this
and if results comes in multiple rows are accepted (since with the above query result will come in single row)
i tried to use group by (studentnumber,status) with status='red' and status='yellow'
but it is not possible could you povidet he solutionHi,
Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, and the exact results you want from that data. Explain how you get those results from that data.
See the forum FAQ {message:id=9360002}
Here's an example of how to post the sample data:
CREATE TABLE perstatus
( studentnumber NUMBER
, subject VARCHAR2 (10)
, marks NUMBER
, status VARCHAR2 (10)
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (1, 'ACCOUNTS', 15, 'RED');
INSERT INTO perstatus (studentnumber, subject , marks, status)
VALUES (1, 'MATHS', 35, 'YELLOW');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (1, 'SCINECE', 45, 'GREEN');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (2, 'ACCOUNTS', 55, 'BROWN');
INSERT INTO perstatus (studentnumber, subject , marks, status)
VALUES (2, 'MATHS', 35, 'YELLOW');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (2, 'SCINECE', 45, 'GREEN');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (3, 'ACCOUNTS', 15, 'RED');
INSERT INTO perstatus (studentnumber, subject , marks, status)
VALUES (3, 'MATHS', 35, 'YELLOW');
INSERT INTO perstatus (studentnumber, subject, marks, status)
VALUES (3, 'SCINECE', 45, 'GREEN');You were on the right track, thinking about GROUP BY. You're interested in something about the whole group of rows that has the same studentnumber. Looking at any individual row won't tell you if that row is part of the group you're interested in or not.
If you want to see information about the group as a whole, you can do the whole job with GROUP BY. In this case, studnetnumber is the only thing that an entire group has in common. If you wanted to see the studentnumbers that had both RED and YELLOW, that is:
STUDENTNUMBER
1
3here's one way you could do it:
SELECT studentnumber
FROM perstatus
WHERE status IN ('RED', 'YELLOW')
GROUP BY studentnumber
HAVING COUNT (DISTINCT status) = 2 -- That is, both RED and YELLOW
ORDER BY studentnumber
;But say you wanted to see details about individuals in the group; for example, say we want to see all the columns for students that have all 3 of RED, YELLOW and GREEN, like this:
STUDENTNUMBER SUBJECT MARKS STATUS
1 SCINECE 45 GREEN
1 ACCOUNTS 15 RED
1 MATHS 35 YELLOW
3 SCINECE 45 GREEN
3 ACCOUNTS 15 RED
3 MATHS 35 YELLOWWe used the aggregate COUNT function earlier, but aggregate functions require collapsing the results down to one row per group.
However, most of the aggregate functions, like COUNT, have analytic counterparts, that can give the same results without collapsing the result set. Here's one way to get the results above, using the analytic COUNT function:
WITH got_cnt AS
SELECT studentnumber, subject, marks, status
, COUNT ( DISTINCT CASE
WHEN status IN ('RED', 'YELLOW', 'GREEN')
THEN status
END
) OVER (PARTITION BY studentnumber) AS cnt
FROM perstatus
SELECT studentnumber, subject, marks, status
FROM got_cnt
WHERE cnt = 3
ORDER BY studentnumber
, status
; -
How to achieve parent-child relationship using self join?
my table structure is as follows
parent child name
-1 1 A1
1 2 A2
1 3 A3
how to achieve the hierarchy model using self join. this can be easily achieved using "connect by prior". but how to achieve the same using self join?Hi,
Yes, that's definitely possible. If you only need to display two levels from the hierarchy, a self-join is a good option. Make it an outer join if you need to show everyone on one level, regardless of whether they have a match on the other level or not; for example, if you want the output:
child_name child_id parent_name parent_id
A1 1
A2 2 A1 1
A3 3 A1 1It's good that you posted some sample data. Now post the results you want from that data, and your query (what you think is the best attempt you've made so far). If you haven't tried anything so far, then look at some other simple self-join to get ideas. -
Self-join query to Analytical function query
Hi All,
I have converted a self-join query to Analytical function query due to the performance reasons.
Query which is using Analytical function is giving the correct count as I compared it with query using Self-Join. Can you please tell what is wrong in the query.
==========================
Query using Self-Join
select count(1)
From (select t1.*, max(t1.dw_creation_dt) over (partition by t1.empl_id) pers_max_date
from ohr_pers_curr t1 ) pers
, (select t2.*, max(t2.dw_creation_dt) over (partition by t2.empl_id, t2.empl_rcd) job_max_date
from OHR_JOB_CURR t2) job
where pers.empl_id = job.empl_id
and pers.dw_creation_dt=pers.pers_max_date
and job.dw_creation_dt=job.job_max_date
and job.dummy_row_flag = 'N'
and pers.dw_creation_rsn_cd in ('N', 'U')
and job.dw_creation_rsn_cd in ('N', 'U')
================================================
Query Using Analytical function
select count(1)
From (select t1.*, max(t1.dw_creation_dt) over (partition by t1.empl_id) pers_max_date
from ohr_pers_curr t1 ) pers
, (select t2.*, max(t2.dw_creation_dt) over (partition by t2.empl_id, t2.empl_rcd) job_max_date
from OHR_JOB_CURR t2) job
where pers.empl_id = job.empl_id
and pers.dw_creation_dt=pers.pers_max_date
and job.dw_creation_dt=job.job_max_date
and job.dummy_row_flag = 'N'
and pers.dw_creation_rsn_cd in ('N', 'U')
and job.dw_creation_rsn_cd in ('N', 'U')
==================================Hi David,
The base is same but the problem is different.
As far as implementation concern these queries looks same, but when I see there counts, they do not match. I do not have any reason why this happening.
Regards
Gaurav -
Query for create manual tabular form using apex collection add row button functionality
Hello everyone
My requirement is i created a tabular form manually using apex collection but if i click on add row button then previously selected data refreshed and added new row in this form it is fine.but i don't want to refreshed previously selected data and click on add row button then add new row .how it is possible? plz help
Thanks & Regards,
UjwalaUjwala
Instead of starting a new thread with the same question as Query for create manual tabular form using apex collection add row button functionality.
Could you answer the question about what you see while debug the javascript code.
If you don't understand the question or have trouble debug javascript let us know.
Nicolette -
Update record using SQL statement
I have VB6.0 and Oracle 10G Express Edition in Windows 2000 Server. My procedure in VB 6.0 can't update record in the table using SQL statement, and the Error Message is " Missing SET keyword ".
The SQL statement in VB6.0 look like this :
General Declaration
Dim conn as New ADODB.Connection
Dim rs as New ADODB.Recordset
Private Sub Command1_Click()
dim sql as string
sql = " UPDATE my_table " & _
" SET Name = ' " & Text3.Text & " ' " & _
" AND Unit = ' " & Text2.Text & " ' " & _
" WHERE ID = ' " & Text1.Text & " ' "
conn.Execute (sql)
Private Sub Form Load()
Set conn = New ADODB.Connection
conn.Open "Provider=MSDASQL;" & "Data Source=my_table;"& "User ID =marketing;" & "Password=pass123;"
I'm sorry about my language.
What's wrong in my SQL statement, I need help ........ asap
Best Regards,
/Harso AdjieThe syntax should be
UPDATE TABLE XX
SET FLD_1 = 'xxxx',
FLD_2 = 'YYYY'
WHERE ...
'AND' is improperly placed in the SET. -
Hi,
By registering the populated java object with the unit of work will insert a new record in the database.How about updating an existing record using UOW?
If any sample code, it will be very helpful.
thanks
vasuhttp://otn.oracle.com/products/ias/toplink/technical/unitOfWorkWP.pdf
http://otn.oracle.com/products/ias/toplink/index.html
http://download-west.oracle.com/docs/cd/B10464_01/index.htm -
Updated records using Dynamic FORMS_DDL
Hello everybody:
I need help for you guys. I'm working with Form9i and created a push button that when I press it, it should be updated some record depending of some conditions. I read that with dynamics FORMS_DDL, I can able to perform it, but when I put the below code in the âWHEN-BUTTON-PRESSEDâ trigger I get an âErrorâ that meaning that the forms was not success. Please, somebody tell me where is the error. Thanks.
if (:CONTROL_BTN.CHK_FINAL = 'N') then
forms_ddl('update aapt_checklists
set achk_reviewed_date = ' || :CONTROL_BTN.DATE_LETTER ||
' where achk_item in (select achk_item
from aapt_checklists, aapt_reviews
where ' || :global.where_updated ||
' and achk_reviewed_date is null
and achk_1st_notification_date is null
and arev_seq = achk_arev_seq)
and achk_1st_notification_date is null
and achk_reviewed_date is null');
end if;
if (form_success) then
message('OK');
else
message('Error');
end if;You don't need dynamic SQL for that. Here is what you can do (Note the new v_fmt variable, and the update SQL below):
DECLARE
def_where varchar2(500) := NULL;
v_month varchar2(2) := :CONTROL_BLOCK.Q_MONTH;
v_day varchar2(2) := :CONTROL_BLOCK.Q_DAY;
v_year varchar2(4) := :CONTROL_BLOCK.Q_YEAR;
v_fmt varchar2(10);
v_date varchar2(20) := NULL;
PROCEDURE check_date (in_date IN varchar2) IS
al_id Alert;
al_button Number;
temp_date date := NULL;
BEGIN
temp_date := to_date(in_date, 'MM/DD/YYYY');
EXCEPTION
when others then
al_id := Find_Alert('CFG_ERROR');
Set_Alert_Property(al_id, alert_message_text, 'You have selected an Invalid Date');
al_button := Show_Alert( al_id );
raise FORM_TRIGGER_FAILURE;
END;
BEGIN
-- Criteria entered as MM/DD/YYYY
if (v_month <> '00') and (v_day <> '00') and (v_year <> '0000') then
v_date := v_month||'/'||v_day||'/'||v_year;
v_fmt := 'MM/DD/YYYY';
check_date (v_date);
-- Criteria entered as MM/DD
elsif (v_month <> '00') and (v_day <> '00') and (v_year = '0000') then
v_date := v_month||'/'||v_day;
v_fmt := 'MM/DD';
check_date (v_date||'/'||'2000'); -- Hardcoded 2000 to check all possible MM/DD combos including Leap Year
def_where := ' to_char(arev_appl_received_date, ''MM/DD'') = ''' || v_date || '''';
-- Criteria entered as MM/YYYY
elsif (v_month <> '00') and (v_day = '00') and (v_year <> '0000') then
v_date := v_month||'/'||v_year;
v_fmt := 'MM/YYYY';
def_where := ' to_char(arev_appl_received_date, ''MM/YYYY'') = ''' || v_date || '''';
-- Criteria entered as MM
elsif (v_month <> '00') and (v_day = '00') and (v_year = '0000') then
v_date := v_month;
v_fmt := 'MM';
def_where := ' to_char(arev_appl_received_date, ''MM'') = ''' || v_date || '''';
-- Criteria entered as DD/YYYY
elsif (v_month = '00') and (v_day <> '00') and (v_year <> '0000') then
v_date := v_day||'/'||v_year;
v_fmt := 'DD/YYYY';
def_where := ' to_char(arev_appl_received_date, ''DD/YYYY'') = ''' || v_date || '''';
-- Criteria entered as DD
elsif (v_month = '00') and (v_day <> '00') and (v_year = '0000') then
v_date := v_day;
v_fmt := 'DD';
def_where := ' to_char(arev_appl_received_date, ''DD'') = ''' || v_date || '''';
-- Criteria entered as YYYY
elsif (v_month = '00') and (v_day = '00') and (v_year <> '0000') then
v_date := v_year;
v_fmt := 'YYYY';
def_where := ' to_char(arev_appl_received_date, ''YYYY'') = ''' || v_date || '''';
end if;
update aapt_checklists
set achk_reviewed_date = :CONTROL_BTN.DATE_LETTER
where achk_item in
in (select achk_item
from aapt_checklists, aapt_reviews
where to_char(arev_appl_received_date,v_fmt) = v_date
and achk_reviewed_date is null
and achk_1st_notification_date is null
and arev_seq = achk_arev_seq)
and achk_1st_notification_date is null
and achk_reviewed_date is null;
--Condition for updated records in aapt.checklists table
:global.where_updated := def_where;
--Only when "INCOMPLETE - NEED ADD'L INFO" Status is selected
def_where := def_where || ' and arev_status = 1427';
END; -
DBA_CONSTRAINTS - self join - duplicate rows?
Hi,
I have two tables in 'I' schema.
===========
SQL> desc dept;
Name Null? Type
DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14)
LOC VARCHAR2(13)
DEPT.DEPTNO - pk_dept_deptno - PRIMARY KEY
SQL> desc emp;
Name Null? Type
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
EMP.DEPTNO - fk_emp_deptno - FORIGN KEY (DEPT. DEPTNO)
SQL> desc emp2
Name Null? Type
DEPTNO NUMBER
FUNCTION VARCHAR2(10)
EMP2 . DEPTNO - fk_emp2_deptno - FORIGN KEY (DEPT. DEPTNO)
I executed the query as DBA,
SQL>
select p.constraint_name,p.table_name,p.r_constraint_name,r.constraint_name,r.table_name
from dba_constraints p, dba_constraints r
where p.r_constraint_name=r.constraint_name and p.owner='I'
order by p.constraint_name;
CONSTRAINT_NAME | TABLE_NAME | R_CONSTRAINT_NAME | CONSTRAINT_NAME | TABLE_NAME
FK_EMP2_DEPTNO | EMP2 | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO | DEPT
FK_EMP2_DEPTNO | EMP2 | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO | DEPT
FK_EMP_DEPTNO | EMP | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO | DEPT
FK_EMP_DEPTNO | EMP | PK_DEPT_DEPTNO | PK_DEPT_DEPTNO|
DEPT
Why I am getting duplicate rows? Any think wrong in my query?
regards
MathewHi,
You can query on USER_CONSTRAINTS instead of DBA_CONSTRAINTS.
SQL> ed
Wrote file afiedt.buf
1 select p.constraint_name, p.table_name, p.r_constraint_name, r.constraint_n
ame, r.table_name
2 from user_constraints p , user_constraints r
3* where p.r_constraint_name = r.constraint_name
4 /
SQL> /
CONSTRAINT_NAME TABLE_NAME R_CONSTRAINT_NA CONSTRAINT_NAME TABLE_NAME
SYS_C005292 B PK_NO PK_NO A
FK_DEPTNO EMP PK_DEPT PK_DEPT DEPT
SQL> ed
Wrote file afiedt.buf
1 select p.constraint_name, p.table_name, p.r_constraint_name, r.constraint_n
ame, r.table_name
2 from dba_constraints p , dba_constraints r
3 where p.r_constraint_name = r.constraint_name
4 and p.owner = 'SCOTT'
5* order by p.constraint_name
SQL> conn sys as sysdba
Enter password:
Connected.
SQL> /
CONSTRAINT_NAME TABLE_NAME R_CONSTRAINT_NA CONSTRAINT_NAME TABLE_NAME
FK_DEPTNO EMP PK_DEPT PK_DEPT DEPT
SYS_C005292 B PK_NO PK_NO A
SYS_C005292 B PK_NO PK_NO A
SQL>Message was edited by:
Mohammad Taj -
Outer Join or Row-Level Function
Hi ALL,
I have a query which involves five tables T1, R1, R2, R3 and R4. T1 is a transaction table, whereas R1, R2, R3 and R4 are reference tables (Parent tables, with foreign keys defined in T1). T1 table always contains R1 and R2 referenced data. BUT T1 table may contain sometimes NULL for R3 and R4.
Now my question is simple;
Should i use an OUTER Join for R3 and R4 in the query? like
<code>
select T1.col1, R1.col2, R2.col2, R3.col2, R4.col2
from T1, R1, R2, R3, R4
where T1.col2 = R1.col1
and T1.col3 = R2.col1
and T1.col4 = R3.col1(+)
and T1.col5 = R4.col1(+)
</code>
OR
Should i use row-level functions for R3 and R4, like
<code>
select T1.col1, R1.col2, R2.col2,
(Select R3.col2 from R3 where R3.col1 = T1.col4),
(Select R4.col2 from R4 where R4.col1 = T1.col5)
from T1, R1, R2
where T1.col2 = R1.col1
and T1.col3 = R2.col1
</code>
which approach is better and why?
Records in T1 = 2,000,000
Records in R1 = 1000
Records in R2 = 300
Records in R3 = 1800
Records in R4 = 200
Please note that all foreign keys are indexed, there are primary keys in all R tables
Thanks,
QQ.dwh_10g wrote:
I have preferred to go for Outer Joins, as there might be a possibility, if data grows than there will be more row-level scans; hence slower output in future.
If i go with a row-level scan, then there will be more usage of Hash tables (Memory), so if more memory is required and our SGA limits is crossed, then there will be more disk I/O i guess. which is a costly operation.
QQ,
as already explained, unfortunately it's hard to predict how the "row-level" approach is going to perform in case of increased data volume. Since it is dependent on some factors it could be faster or slower than the outer join approach.
You shouldn't worry too much about the size of the in-memory table. You haven't mentioned your version, but since your alias is "dwh10g" is assume you're using 10g.
In 10g the size is defined by the hidden parameter "_query_execution_cache_max_size" and set to 65536 bytes by default. In pre-10g the size is always 256 entries which might grow bigger than 64k in case you have large input/output values (e.g. large VARCHAR2 strings). Compared to potentially multiple several megabytes large sort and/or hash SQL work areas used by each open cursor this table seems to be relatively small.
I don't think that this memory is taken from the SGA, but belongs to the PGA of the process executing the query and therefore it should not allocate SGA memory (I think even in Shared Server configuration this part should be allocated from the PGA of the shared server process).
So in summary if your data volume increases it shouldn't have an noticeable impact on the memory usage of the "row-level" approach, and therefore this I think is negligible.
But as a recommendation I would say, since the "row-level" approach doesn't seem to be significantly faster than the "outer join" approach and it's behaviour in future is hard to predict (e.g. it could become worse if your data pattern changes or the execution plan changes and therefore the order of the row processing changes) I would stick to the "outer-join" approach. I assume it could be more stable in terms of performance.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Update records using Pl/Sql procedure
Hi
I have wriitten a stored procedure to update the Organisation_Name in a table based on the Full_Org_Nm of an another table.
Though the procodure got executed sucessfully but it is not updating the records.
I even tried executing the procedure by writing Execute <Procedure name>,the database got hanged.
Please find my procedure below.
Create or Replace
PROCEDURE UPDT_ISSUE_USR_ROLE
As
Cursor cur_user_role Is
Select a.org_id,a.user_id
from prts_user a,issue_user_role b
where a.user_id=b.user_id;
v_rows_processed Number:=0;
Begin
For rec in cur_user_role Loop
update Issue_user_role
set User_org_nm=(Select full_org_nm from VW_Org where org_id=rec.org_id)
Where Issue_User_Role.rowid in
(select issue_user_role.rowid
FROM issue_user_role,issue,issue_workflow,Issue_step_dtl_wrkflw
Where Issue_User_Role.Issue_Id=Issue.Issue_id
And Issue_User_Role.Issue_id=issue_workflow.issue_id
And Issue_User_Role.Workflow_compnt_id=Issue_Workflow.CURR_STEP_WORKFLOW_COMPNT_ID
And Issue_User_Role.Workflow_compnt_id=Issue_Step_Dtl_wrkflw.Workflow_compnt_id
And Issue_User_Role.Issue_id=Issue_Step_Dtl_wrkflw.Issue_Id
And Issue.Issue_id=Issue_workflow.Issue_Id
And Issue.Issue_id=Issue_Step_Dtl_Wrkflw.Issue_id
And Issue_workflow.Issue_id=Issue_Step_Dtl_Wrkflw.Issue_id
And Issue_Workflow.CURR_STEP_WORKFLOW_COMPNT_ID=Issue_Step_Dtl_wrkflw.Workflow_compnt_id
And issue_workflow.primry_workflow_flag='Y'
And issue_user_role.user_id = rec.user_id
And issue.issue_status_id in (1636,50738,275,50737,2090)
And issue_step_dtl_wrkflw.Issue_step_status_id in (61248,61249,61250));
v_rows_processed :=v_rows_processed + SQL%ROWCOUNT;
End Loop;
COMMIT;
dbms_output.enable;
dbms_output.put_line('There were '||v_rows_processed||' rows updated');
End;
Please let me know where i am wrong.
Thanks in advance.
CheersHi Blushadow
Now if i want to update say only 10 records at a time what should i put into my Proc?
Please go thru my Proc below..
CREATE OR REPLACE PROCEDURE PRTS.UPDT_ISSUE_USR_ROLE
As
Cursor cur_user_role Is
Select a.org_id,a.user_id
from prts_user a,issue_user_role b
where a.user_id=b.user_id;
upd_rec cur_user_role%rowtype;
v_rows_processed Number:=0;
Begin
Open cur_user_role;
Loop
Fetch cur_user_role into upd_rec;
If cur_user_role%NOTFOUND
Then
Exit;
Else
update Issue_user_role
set User_org_nm=(Select full_org_nm from VW_Org where org_id=upd_rec.org_id)
Where Issue_User_Role.rowid in
(select issue_user_role.rowid
FROM issue_user_role,issue,issue_workflow,Issue_step_dtl_wrkflw
Where Issue_User_Role.Issue_Id=Issue.Issue_id
And Issue_User_Role.Issue_id=issue_workflow.issue_id
And Issue_User_Role.Workflow_compnt_id=Issue_Workflow.CURR_STEP_WORKFLOW_COMPNT_ID
And Issue_User_Role.Workflow_compnt_id=Issue_Step_Dtl_wrkflw.Workflow_compnt_id
And Issue_User_Role.Issue_id=Issue_Step_Dtl_wrkflw.Issue_Id
And Issue.Issue_id=Issue_workflow.Issue_Id
And Issue.Issue_id=Issue_Step_Dtl_Wrkflw.Issue_id
And Issue_workflow.Issue_id=Issue_Step_Dtl_Wrkflw.Issue_id
And Issue_Workflow.CURR_STEP_WORKFLOW_COMPNT_ID=Issue_Step_Dtl_wrkflw.Workflow_compnt_id
And issue_workflow.primry_workflow_flag='Y'
And issue_user_role.user_id = upd_rec.user_id
And issue.issue_status_id in (1636,50738,275,50737,2090)
And issue_step_dtl_wrkflw.Issue_step_status_id in (61248,61249,61250));
v_rows_processed :=v_rows_processed + SQL%ROWCOUNT;
If Mod (v_rows_processed,v_rows_processed)=10
then
COMMIT;
End if;END IF;
End Loop;
Commit;
dbms_output.enable(1000000);
dbms_output.put_line('There were '||v_rows_processed||' rows updated');
Close cur_user_role;
End;
I would appreciate if you can let me know any other alternative way to meet this requirment.
Cheers
Vineet -
UPDATE records using Database Conectivity toolset
I´m using LabVIEW 8.5 & Database Connectivity toolset ver 1
When I try to update a record of a MS ACCESS 2003 with the SQL UPDATE TablenName SET field1=newvalue, field2=newvalue........WHERE condition=x, I get the error -2147217900 Exception occurred in Microsoft Jet DataBase engine: Sintax error in the instruction UPDATE.vi ComExec (8.5 bug Workaround)vi.
I ´dont think I have made a sintax error. If the field is an string I use the 'newvalue' following by a comma, in case of numeric field just the coma. For instance :
UPDATE TableName SET Name='John', Age=22,Hair='blond' WHERE height=1.85
I have discarded the reserved word´s problem, as I can insert records in the data base without any problem
Any idea to solve the problem
Thanks
SimbaniDid you try it like this?
UPDATE TableName SET TableName.Name='John', TableName.Age=22,TableName.Hair='blond' WHERE TableName.height=1.85 -
Updating record using table contorl
hi ABAPers,
i have a problem while updating the record to a database table from table control,
please,check the code writtern,
Code in Top include:
Tables: MARA,
MAKT.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
SPRAS LIKE MAKT-SPRAS,
MAKTX LIKE MAKT-MAKTX,
END OF ITAB.
*data:ok_code(20).
CONTROLS TC1 TYPE TABLEVIEW USING SCREEN 2000.
*DATA: cols LIKE LINE OF TC1-cols,
lines TYPE i.
Screen_1000:Code in PAI:
module USER_COMMAND_1000 input.
CASE SY-UCOMM.
WHEN 'DISPLAY'.
SELECT SPRAS MAKTX FROM MAKT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE MATNR = MARA-MATNR.
IF SY-DBCNT IS INITIAL.
MESSAGE I127(ZKC_MSGCLS).
ELSE.
SET SCREEN 2000.
ENDIF.
WHEN 'EXIT'.
LEAVE PROGRAM.
SET SCREEN 0.
ENDCASE.
endmodule. " USER_COMMAND_1000 INPUT
Screen_2000:Code in PBO:
module ctrl_pai output.
MOVE-CORRESPONDING ITAB TO MAKT.
endmodule. " ctrl_pai OUTPUT
Screen_2000:Code in PAI:
module USER_COMMAND_2000 input.
CASE SY-UCOMM.
WHEN 'UPDATE'.
LOOP AT TC1-cols INTO cols WHERE index GT 2.
IF cols-screen-input = '0'.
cols-screen-input = '1'.
ELSEIF cols-screen-input = '1'.
cols-screen-input = '0'.
ENDIF.
MODIFY TC1-cols FROM cols INDEX sy-tabix.
ENDLOOP.
WHEN 'EXIT'.
LEAVE PROGRAM.
SET SCREEN 0.
WHEN 'BACK'.
SET SCREEN 1000.
ENDCASE.
endmodule. " USER_COMMAND_2000 INPUT
Screen_2000:Code outside PBO
LOOP AT itab WITH CONTROL TC1 CURSOR TC1-TOP_LINE.
MODULE ctrl_pai.
ENDLOOP.
Screen_2000:Code outside PAI
LOOP AT itab.
ENDLOOP.
regards,
vinodHi,
Go thro' the coding in this link.It will help you.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/table%20control%20in%20abap.pdf
Message was edited by:
Jayanthi Jayaraman -
How can I delete and update records using where conditions?
I want to delete and update the coherence records with some conditions, I describe it to use SQL as follows:
delete from "contacts" where getStreet() = "dsada";
update contacts set getStreet() = "dddd" where getCity() = "ssss";
Can I use the filter like query to achieve this requirement as follows:
ValueExtractor::View vHomeStateExtractor = ChainedExtractor::create(
ChainedExtractor::createExtractors("getHomeAddress.getState"));
Object::View voStateName = String::create("MA");
Set::View setResults = hCache->entrySet(
EqualsFilter::create(vHomeStateExtractor, voStateName));
I know I can use get and put to achieve this requirement , but it Requires a two-interaction between the client and coherence server. Does it have And another way?
Thanks very much, and please Forgive my English is not very good.Hi,
You have a couple of options for updating or deleting using a Filter.
For deleting you can use an Entry Processor and the cache invokeAll method. Using "out of the box" Coherence you can use the ConditionalRemove entry processor. I'm a Java person so the C++ below might not be exactly right but you should get the idea.
ValueExtractor::View vHomeStateExtractor = ChainedExtractor::create(
ChainedExtractor::createExtractors("getHomeAddress.getState"));
Object::View voStateName = String::create("MA");
hCache->invokeAll(EqualsFilter::create(vHomeStateExtractor, voStateName),
ConditionalRemove::create(AlwaysFilter.getInstance());For update you would either need to write custom Entry Processor implementations that perform the updates you require or you can use out of the box POF or Reflection ValueUpdaters that update specific fields of the entries in the cache. These valueUpdaters would be wrapped in an UpdaterProcessor so the call would be very similar to the code above.
JK -
JDBC- How Update record using preparedStatement() into MS Access?
Actually i got an error when i update the record,The setString() Parameter are stored in terms of arrays .
The Error is
ErrorSQL3.java.sql.SQLException:[Microsoft][ODBC Microsft Access Driver] Syntax Error in UPDATE StatementActually i got an error when i update the record,The
setString() Parameter are stored in terms of arrays
The Error is
ErrorSQL3.java.sql.SQLException:[Microsoft][ODBC
Microsft Access Driver] Syntax Error in UPDATE
Statement
Believe the error message - your SQL syntax is wrong.
Either fix it or post what you have and get some advice.
%
Maybe you are looking for
-
G3 Monitor saying "out of range" after itunes upgrade - HELP PLEASE
I'm running a G3 with 512RAM. It has been running Panther totally reliably for a year. I upgraded to 10.3.9 and the G3 ran no problem. I upgraded to the latest Itunes, restarted the G3 and now after the tones the monitor turns black with the message
-
Moving activities from one track to another
Hi, I was wondering whether it's possible to move activities (not activated nor transported yet) from one track to another. Here's our setup: Project is divided into 2 phases: Phase A is completed developed - Still waiting for the results of UAT. Pha
-
Hello guys, I need help in writing XSLT.I have a XML structure as below. <PushEventResult> <pushEventDT> <id>XX</id> <serialNumber>111</serialNumber> <Mpxn>1X1</Mpxn> <EventData> <alarmDtime
-
[solved] Building xfce4-panel-git
Hello. I've satisfied all depps for xfce4-panel-git. However, I have a problem: Build Configuration: * Debug Support: yes * GNU Visibility: yes * Documentation: no make all-recursive make[1]: Entering folder `/tmp/yaourt-tmp-kant/aur-xfce4-panel-git/
-
Acegi 1.0.7 weblogic cluster
Hello Anyone :-) We're using Acegi 1.0.7 for concurrent login handling in our application, i.e. to prevent a user from logging to the application with the same username twice (at the same time). Our application is deployed in 2 weblogic servers, clus