How to use rownum=2 in update statement ?
Hi all,
we are migrating the data from mainframe to oracle. migration team extracted the data into flat file. we are using this flat file to load in oracle.Finacle have menu option to load data from flat file to corresponding oracle tables.whenever i given this flat file to Menu it will give error report like below if any rows have error.
here "A/c. Opening Matrix" is the error.
error report:-
A/c. Opening Matrix
The Above Error Was For record No: 1
A/c. Opening Matrix
The Above Error Was For record No: 2
we are extracting and storing all the error message and corresponding record no in shell script as below.
err_msg=`echo ${error_msg[i]}`
rec_num=`echo ${error_msg[i]}| cut -d: -f2`
we need to update the upload status either upload success or failure and error message in upload history table. iam writing the update statement as below.
update statement:-
update upld_hist set upld_status='ERR' ,upld_err='$err_msg' where rownum=$rec_num;
This is statement is updating only for rownum=1. other than this it is not updating the table. Please suggest me how to update the rows based on rownum?
Thanks,
Venkat Vadlamudi
868591 wrote:
Hi all,
we are migrating the data from mainframe to oracle. migration team extracted the data into flat file. we are using this flat file to load in oracle.Finacle have menu option to load data from flat file to corresponding oracle tables.whenever i given this flat file to Menu it will give error report like below if any rows have error.
here "A/c. Opening Matrix" is the error.
error report:-
A/c. Opening Matrix
The Above Error Was For record No: 1
A/c. Opening Matrix
The Above Error Was For record No: 2
we are extracting and storing all the error message and corresponding record no in shell script as below.
err_msg=`echo ${error_msg[i]}`
rec_num=`echo ${error_msg[i]}| cut -d: -f2`
we need to update the upload status either upload success or failure and error message in upload history table. iam writing the update statement as below.
update statement:-
update upld_hist set upld_status='ERR' ,upld_err='$err_msg' where rownum=$rec_num;
This is statement is updating only for rownum=1. other than this it is not updating the table. Please suggest me how to update the rows based on rownum?
Thanks,
Venkat VadlamudiUse Analytic ROW_NUMBER() ..
http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions156.htm#i86310
Similar Messages
-
How to use escape character in update statement.
Hi All,
I'm trying to update table using following sql update statement, but everytime it's asking me for the input due to the '&' value in below sql.
UPDATE xyz_xyz
SET NAME = 'ABC & PQR'
WHERE ID = (SELECT ID
FROM abc_abc
WHERE NAME = 'C & PQR');Please let me know how to use escape character syntax or let me know if there is any alternative solution.
Thanks,
VishwasHi,
By default, & marks a substitution variable name.
If you're not using substitution variables in that statement (or, if this is in PL/SQL, in that entire package or procedure) then the easiest thing to do is just diable substitution variables; then & will be a normal character:
SELECT DEFINE OFF
UPDATE xyz_xyz
SET NAME = 'ABC & PQR'
WHERE ID = (SELECT ID
FROM abc_abc
WHERE NAME = 'C & PQR');
SET DEFINE ONIf you can't do that, then & is always taken literally if it comes right before a single-quote, so you could say:
UPDATE xyz_xyz
SET NAME = 'ABC &' || ' PQR'
WHERE ID = (SELECT ID
FROM abc_abc
WHERE NAME = 'C &' || ' PQR');There is a SQL*Plus "SET ESCAPE" command, too, but if you use it, you have to worry about whether the escape character is to be taken literally or not.
SET ESCAPE \Yet another alternative is to make some other character, such as ~, mark the substitution variables:
SET DEFINE ~Read all about them in the SQL*Plus manual.
http://download.oracle.com/docs/cd/B28359_01/server.111/b31189/ch2.htm#sthref103 -
Can I use a select and update statement in a single jsp file?
I want to update the BUY table everytime I would add a SELL transaction.....I want to minus the stocks that I sold to those that Ive bought before.....
note: I used a seperate table in BUY and SELL transaction
After I Have added a transaction, I want to update the buy table. This is my problem, can I used both SELECT and UPDATE statement at the same time in a single jsp file for example like this:
select * from test, test1;
update test
set total_shares=total_shares-Stotal;
where stock_code=Scode AND name_broker=Sbroker;
Can i have both of these statements in the same jsp file in oder to update the buy table?
Or can anyone suggest how can process that update?THANKS!
--------------------Can i have both of these statements in the same jsp file in oder to update the buy table?Yes. But wouldn't it have been easier just to try it?
-
How to use multipule join in update stmt
hi,
i have a query in mssql i want to translate it using oracle 11g r2 latest sysntex
UPDATE trips
SET locations = trips.city + ', ' + poi.city
FROM trips INNER JOIN poi
ON poi.trip_guid = trips.guid
where trips.trip_guid =1
UPDATE trips t
SET locations = t.city + ', ' + p.city
FROM poi p
ON p.trip_guid = t.guid
where t.trip_guid =1
please tel me how i can write it in oracel 11g r2
i also show there is mearge statmet is it sql or plsql
yours sincerelyupdate trips t
set locations = t.city || ', ' ||
(select p.city || e.allow
from poi p
, emp e
where p.trip_guid = t.guid AND e.id = t.id
update trips t
set locations = t.city || ', ' ||
(select p.city || e.allow
from poi p
left join emp e on e.id = t.id
where p.trip_guid = t.guid
1)are these both query same and correct if i want to upate all rows.
2) some body said following two query are different
if there is any theory then pls tel me. because i have to use rownum<2 to get the top most row rather than distinct
in few cases
at some other places.
-- works but look at the number of rows updated
UPDATE test t
SET (tablespace_name, extent_management) = (
SELECT DISTINCT u.tablespace_name, u.extent_management
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name
AND t.table_name LIKE '%A%');
-- works properly
UPDATE test t
SET (tablespace_name, extent_management) = (
SELECT DISTINCT (u.tablespace_name, u.extent_management)
FROM user_tables a, user_tablespaces u
WHERE t.table_name = a.table_name
AND a.tablespace_name = u.tablespace_name)
WHERE t.table_name LIKE '%A%';
yours sincerely
Edited by: 944768 on Feb 20, 2013 5:36 AM
Edited by: 944768 on Feb 20, 2013 5:39 AM -
How to use where clause with get statement in LDB programs
Hi All,
I am using logical databse in my report program.I am not getting how to use the where clause in the get statement is it possible to use?or if not possible only option is we should filter it after get statment is right?Can you please some body throw some idea on this?
Regards
MaheshHi,
Reffer these links
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw04/helpdata/en/c6/8a15381b80436ce10000009b38f8cf/frameset.htm
/people/srivijaya.gutala/blog/2007/03/05/why-not-logical-databases
reward if helpful
Thanks,
Suma. -
Delete adjacent duplicates how to use in the below select statement
hi i have a problem
i am suing the below select statement
SELECT a~extno
a~guid_lclic " for next select
e~ctsim
e~ctsex
*revised spec 3rd
f~guid_pobj
f~amnt_flt
f~amcur
f~guid_mobj
e~srvll "pk
e~ctsty "PK
e~lgreg "PK
INTO TABLE gt_sagmeld
FROM /SAPSLL/LCLIC as a
INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
inner join /sapsll/legcon as f on fguid_lclic = aguid_lclic " for ccngn1 selection
inner join /sapsll/corcts as g on gguid_pobj = fguid_pobj
where a~extno in s_extno.
sort gt_sagmeld by guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ.
delete adjacent duplicates from gt_sagmeld comparing guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ .
now i am confused how to use delete adjacent dupliacate and on which fields
as first table /sal../lclic primary key is guid_lclic
and it is joined to table
legcon by guid_lclci ( not a primary key here)
legcon primary key is guid_legcon
and table 3 legsv by lgreg (pk here)
table 3 has tow more primary key srvll and ctsty also
NOW MY QUESTIO IS TAHT IS I USE ABOVE DELETE ADJACENT STATMENT IT FETCHES 20 LAKH RECORDS
I WANT TO REDUCE IS LET ME KNOW ON WHAT fields i need to use delete adjacen duplicates
or use comparing all fields?
regards
Arorahi sudha
if u see my select statement is contains four Primary keys
srvll
lgreg
ctsty
guid_lclic
but the next table connected to this table legcon is by guid_pobj and anothe table by guid_mobj
and if i take this gt_sagmeld to another temp table and i find abt 10 lakh uniques guid_pobj
similary 6 lakh guid_mobj so the next slect is hanpering because of this
not COMING TO OUR POINT IF I SORT ONLY BY OUR PRIMARY KEYS NOT TAKING INTO ACCOUNT TEH GUID_POBJ AND GUID_MOBJ
THE ENTRIES ARE VERY LESS BUT IF I TAKE INOT ACCCOUNT IN GT_SAGMELD THE ENTRIES ARE ABT 20 LAKH
SO I AM NOT SURE WHETHER TO TAKNE GUID_POBJ AND GUID_MOBJ INOT ACCOUNT FOR DELECTING ADJACENT DUPLICATES?
HENCE THE QUESTION OF ON WHICH FIRLD DELETE OR COMPARING ALL FIELDS I USE? -
Please help how to use WITH query in UPDATE
Hi Experts,
Please help me.
Thanks.Not sure about your required output. But try using WITH clause query inside SET clause of UPDATE statement.
UPDATE SALES_REVENUE SR
SET
(SR.TODAY_REV,
SR.TODAY_MARGIN,
SR.TODAY_UNIT
) =
(WITH result_sum_temp
AS(
SELECT SALE_ID, IN_TEAM, 1 SALE_FLAG, loc, seg,
SUM(REV * rate) AS sum_rev,
SUM(MARGIN * rate) AS sum_mar,
SUM(UNIT) AS SUM_UNIT
FROM SALES
WHERE (IGNORED IS NULL OR IGNORED <> 'Y')
AND SALE_SPOT = 7
AND SALE_ID = 375
AND SALE_MODEL = 'D'
AND IN_TEAM IS NOT NULL AND loc IS NOT NULL
GROUP BY SALE_ID, IN_TEAM, loc, seg
UNION ALL
SELECT SALE_ID, OUT_TEAM, 2 SALE_FLAG, loc, seg,
SUM(REV * rate) AS sum_rev,
SUM(MARGIN * rate) AS sum_mar,
SUM(UNIT) AS SUM_UNIT
FROM SALES
WHERE (IGNORED IS NULL OR IGNORED <> 'Y')
AND SALE_SPOT = 2
AND SALE_ID = 375
AND SALE_MODEL = 'D'
AND OUT_TEAM IS NOT NULL AND loc IS NOT NULL
GROUP BY SALE_ID, OUT_TEAM, loc, seg)
(SELECT t.sum_rev, t.sum_mar, t.sum_unit
FROM result_sum_temp t
WHERE SR.SALE_ID = t.SALE_ID
AND SR.team_id = t.team_id
AND SR.SALE_FLAG = t.SALE_FLAG
AND SR.SEG = t.seg
AND SR.loc = t.loc
AND t.SALE_ID = 255)
WHERE SR.SALE_SPOT = 890
AND SR.SALE_ID = 255
AND (SR.SALE_ID, SR.team_id, SR.sale_flag, SR.SEGMENT, SR.LOB) IN
(SELECT SALE_ID,
team_id,
sale_flag,
seg,
loc
FROM result_sum_temp)); -
Using Escape character in UPDATE statement
SELECT REPLACE
( REPLACE
( REPLACE( REPLACE( REPLACE( REPLACE( BODY, '<STARTOFLINK>' )
, '<ENDOFLINK>' )
FROM ARTICLEI need to use the above in an UPDATE statement to remove some HTML tags from a CLOB column. However when I run the script it asks for the substitution variables for the '&' characters. I've tried "ESCAPE '\'" but I think you can only use that with a like operand.
Any suggestions?
Message was edited by:
Terrible
As you can see the HTML tags have been converted in this post!! I'm trying to remove:
& amp;
& quot;
& ndash;
& #039;This may help;
SQL> create table t (col1 varchar2(200))
Table created.
SQL> insert into t values('<STARTOFLINK>')
PL/SQL executed.
SQL> insert into t values('<ENDOFLINK>')
PL/SQL executed.
SQL> insert into t values(chr(38) || 'amp;')
PL/SQL executed.
SQL> insert into t values(chr(38) || 'quot;')
PL/SQL executed.
SQL> insert into t values(chr(38) || 'ndash;')
PL/SQL executed.
SQL> insert into t values(chr(38) || '#039;')
PL/SQL executed.
SQL> insert into t values('<STARTOFLINK>link<ENDOFLINK> '
|| ' AMP:' || chr(38) || 'amp;'
|| ' DQT:' || chr(38) || 'quot;'
|| ' DASH:'|| chr(38) || 'ndash;'
|| ' SQT:' || chr(38) || '#039;')
PL/SQL executed.
SQL> select * from t
col1
<STARTOFLINK>
<ENDOFLINK>
<STARTOFLINK>link<ENDOFLINK> AMP:& DQT:" DASH:– SQT:'
7 rows selected.
SQL> select regexp_replace(
regexp_replace(
regexp_replace(
regexp_replace(
regexp_replace(col1, '<.*OFLINK>',NULL),
chr(38) || 'amp;', chr(38)),
chr(38) || 'quot;', chr(34)),
chr(38) || 'ndash;', chr(45)),
chr(38) || '#039;', chr(39))
new_col from t
NEW_COL
AMP:& DQT:" DASH:- SQT:'
7 rows selected.Message was edited by:
MScallion
The SELECT * values were not as they are displayed due to HTML conversions. -
Hi everyone,
Suppose I am having 100,000 records, and i want to filter only 50,000 records.
How i can use rownum in OWB.
I think in join i can use it, other that else any other way
Regards
Rachittyr to use a view to reference the data and create rownum along with it.
in 9.2 we dont have a true support to analytic functions. using a view would be my chocie. -
Updating a column using deleted/inserted during update statement execution
I need to capture the old value while update statement is executed. I can not insert into temp table (there are many samples online where you can use OUTPUT clause to insert data in same table or another temp table)
something like
declare @count table
id int,
changed varchar (50)
insert into @count (id,changed) values (2,'T')
insert into @count (id,changed) values (3,'T')
insert into @count (id,changed) values (4,'T')
select * from @count
UPDATE @count
SET id=5,
Changed = GETDATE() -- here instead of date, I want to get inserted.id and deleted.id
OUTPUT inserted.id,
deleted.id
where id = 2
SELECT *FROM @count
Any help on this will be very much appreciated....I am not sure to follow your question but you can get the old value just by doing:
UPDATE @count
SET id=5,
Changed = id
OUTPUT inserted.id,
deleted.id
WHERE id = 2;
since SQL Server uses all-at-once operations.
Microsoft SQL Server 2012 T-SQL Fundamentals
http://shop.oreilly.com/product/0790145321978.do
AMB
Some guidelines for posting questions... -
How to use SET ID in select statement of SQ02
Hi,
I have a infoset, where for one of my Zfield, i have writen a select statement in order to get my ouput.
if aufk-aufnr = 'XYZ'.
select sum( FKBTR ) from fmifiit into zfmifiit
where fikrs = aufk-kokrs
and fipex IN capex
and wrttp NE '51'.
endif.
For the above statement, i have created (with 10 single values, table name FMCI, field name FIPEX) a SET id named CAPEX and used with IN operator.
But when i generating the infoset i am getting error like below
The IN operator with "CAPEX" is followed neither by an internal table nor by a value list
I was using IN opeartor for set ids during validation / substitutions, where if i have to validate multiple single values.
What to do here?
Regards,
Srinu[OPEN-SQL|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_GENERAL.htm] set of statement, [SELECT|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] statement, [WHERE|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP.htm] addition requires a selection table (type range, [WHERE - IN seltab |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]) of parameter and not a set. We are in Abap here, not in a Customizing screen
You have to convert the set to a selection table in an ABAP coding before using it in a SELECT statement.
(Check FM like G_SET_TREE_IMPORT to import definition of set (values and intervals) and map them to a select-table, or ask a developper to perform it, look at G_SET_TREE_IMPORT -> select statement)
Regards,
Raymond -
There are 1000 records in the employee table.I need to display 50 records each time by the order of the employees' names. In order to get the employee records from the 51st to the 100nd in the table, I tried to use ROWNUM.
However, the following query doesn't do the job:
select first_name, last_name from employee where rownum < 101 and rownum >49 order by last_name, first_name
I currently use the following query:
select * from (
(select first_name, last_name from employee where rownum < 101 order by last_name, first_name)
Minus
(select first_name, last_name from employee where rownum < 50 order by last_name, first_name )
) order by 2,1
The query works but is quite complictated. I would like to know if there a simpler way to do so.
Thanks in advance.
HelenaThe generally preferred query is something along the lines of
SELECT *
FROM ( SELECT a.*, rownum rn
FROM (<<your query>>) a
WHERE rownum <= <<MAX VALUE>>)
WHERE rn >= <<MIN VALUE>><<your query>> here would be
SELECT first_name, last_name
FROM employee
ORDER BY first_name, last_nameNote that if you wanted to use the MINUS construct, you would generally need to move the rownum clause outside the query that is doing the ORDER BY. The query
SELECT first_name, last_name
FROM employee
WHERE rownum < 101
ORDER BY first_name, last_namefetches the first 100 rows and then orders them, which is not generally what you want.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
How to use one form to update two tables
How can I do that? HTMLDB wizard or form on table doesn't give me an option to use more than one table in a form or I don't know about it. I created new process which redirects the form to another page after submitting the form. On the second page I created new process which uses the same variables from the previous form page. This process runs on page load before header but it is just not working right.
So, what is the proper way to update two tables with the same form fields?Hello Vikas,
"The Automatic Row Fetch and Automatic DML processes are a pair, you can't have one without the other."
Are you sure about that? I have a page, which populate some of the items from TableA, using manual select statement, and after the user input, save some of it in TableB, using Automatic DML. No ARF in this process and it seems to work just fine. Come to think of it, what about a simple form, populated entirely by the user input, and then being saved to the db, using Automatic DML? No ARF here also.
For the problem in hand, if you can't have more then one Automatic DML per page, I think that the simplest solution will be to define a pl/sql process, with two INSERT statement to the two different tables.
Regards,
Arie. -
How to use the WHENEVER SQLERROR EXIT statement in a PL/SQL block.
Hi,
I am getting the following error when trying to add the following statement in an PL/SQL block.
WHENEVER SQLERROR EXIT SQL.SQLCODE
[exec] ERROR at line 23:
[exec] ORA-06550: line 23, column 12:
[exec] PLS-00103: Encountered the symbol "SQLERROR" when expecting one of the
[exec] following:
[exec] := . ( @ % ;
How can i use the above statement in the PL/SQL Block? I have only IF statement in that block( between BEGIN and END).
ThanksHi,
Usually there's always more than one solution.
Can you post an example of what you're trying to accomplish?
That would be useful.
(Place the tag before and after your example to maintain formatting en spacing, see the [fac|http://forums.oracle.com/forums/help.jspa] regarding available tags) -
How to use BAPI extension for updating field which is not in BAPI stracture
I am doing a conversion for control cycle create. The data is maintained in DB Table "PKHD". i have to update 12 fields threre through BAPI "BAPI_KANBANCC_CREATE". there are 11 fields in BAPI structure. but 1 field called"BERKZ" is not there . How can i update it through EXTENSION.
Hi ,
in the bapi extension check one structure with name BAPIPAREX will available..
you need to pass custom structure in that..
ands conactenate 12 field of your structure and pass in to value1 in bapirex structure and append.
go to se11 and enter >bapiparex> check where it is used -->see the zprogram and check how it is used the add your code according to that..
Regards,
Prabhudas
Maybe you are looking for
-
I was making new Apple ID with my other Email on iTunes, but I canceled the process on payment page. After a while I went to make a new ID with same Email but it says the Email is already in use! what should i do?
-
How can I run both versions of Firefox at the same time?
Alright, so I decided to install the Firefox 4 beta 3 as a test sort of thing. But now it's set as the default browser, and, no matter what I do, I can't switch back to the old one! I can't use any of my old add-ons now!
-
Item category related to Quotation, Statistical value field
Hi All, IN my Project, Item category Y003 which is used in creation of Quotions, for which Statistical value is 'X' which means "No cumulation - Values can not be used Statistically". My requirement is I need to change this filed value to 'Y' which m
-
How to include the ordinary program in the BOR object type program
Hi Guys, while i am trying to include a program in the BOR object type program. It is showing the following error: "Statement 'INCLUDE Z_ERC_SEARCH_VALOFACT_MACRO .' is not permitted in BOR". then, i tried to add "<" and ">" to enclose it, but it wa
-
We are trying to create a view in Service Manager 2012 R2 using the class System.WorkItem.Incident.View.SLAProjectionType so we can pick up the SLA status (breached/warning) while also picking up the assigned to user, incident id, etc. When we use t