update a table using a date to_char
Hello all;I have the following query and the table below
create table t1
(
cid varchar2(200),
yearid varchar2(200),
begin_date date
);
insert into t1
(cid, yearid, begin_date)
values
('A', '2010_1', sysdate);
insert into t1
(cid, yearid, begin_date)
values
('B', '2010_1', to_date('03/04/2011', 'MM/DD/YYYY'));
insert into t1
(cid, yearid, begin_date)
values
('C', '2010_1', to_date('01/02/2011', 'MM/DD/YYYY'));
and I have the following update statement update t1 t
set t.yearid = '2011_1'
where to_char(t.begin_date, 'YYYY') = substr(t.yearid, 1, 4);
what I'm trying is basically update table t1 yearid which is a varchar2 in to_char start the date are irregular... so in my case of the sample,TO_CHAR date start back a 2011
Therefore, the yearid must be 2011_1 instead.
However, my udate statement does not work well
Don't know what exactly you want, but it looks like everything that you need is to change = to! = where year clause and using begin_date in update the value:
SQL> select * from t1;
CID YEARID BEGIN_DAT
--- ---------- ---------
A 2010_1 26-JAN-11
B 2010_1 04-MAR-11
C 2010_1 02-JAN-11
SQL> update t1 t
2 set t.yearid = to_char(t.begin_date, 'YYYY') || '_1'
3 where to_char(t.begin_date, 'YYYY') != substr(t.yearid, 1, 4);
3 rows updated.
SQL> select * from t1
2 /
CID YEARID BEGIN_DAT
--- ---------- ---------
A 2011_1 26-JAN-11
B 2011_1 04-MAR-11
C 2011_1 02-JAN-11
SQL>
SY.
Tags: Database
Similar Questions
-
Update a table using the clause
Hello
I want to update a table using the selected values.
Cases in the sample:
create table as empsalary)
Select 1 as empid, 0 in the wages of all the double union
Select option 2, the double 0);
Data update are as follows
with saldata as
(
Select 1 as empid, 5000 as wages, 500 as double pf
Union of all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
I tried the following query but does not work
updated set of empsalary table (empid, salary) =
(
Select * from)
with saldata as
(
Select 1 as empid, salary, 500 5000 as pf Union double all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
) sl
where sl.empid = empsalary.empid
)
I use oracle 10g.
Help, please.
Krishna Devi wrote:
Hello
I want to update a table using the selected values.
Cases in the sample:
create table as empsalary)
Select 1 as empid, 0 in the wages of all the double union
Select option 2, the double 0);
Data update are as follows
with saldata as
(
Select 1 as empid, 5000 as wages, 500 as double pf
Union of all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
I tried the following query but does not work
updated set of empsalary table (empid, salary) =
(
Select * from)
with saldata as
(
Select 1 as empid, salary, 500 5000 as pf Union double all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
) sl
where sl.empid = empsalary.empid
)
I use oracle 10g.
Help, please.
Thanks for posting creates table and test data.
The error message would have helped because it's pretty obvious that this is the problem:
Update table empsalary
*
ERROR on line 1:
ORA-00903: invalid table name
Just remove the word "table".
-
I want to update the verson using celluler data how is possible
I want to update the verson using celluler data how is possible
WiFi or iTunes > update the iOS on your iPhone, iPad or iPod touch - Apple Support software
-
Update of the data in the Table using XMLTYPE DATA
I did insertions using XMLTYPE data but have never done it and update. Can someone give me some advice?
PROCEDURE ADD_LABORDER_CODES)
IN_ORDERCODESXML IN CLOB DEFAULT NULL,
Number of OUT OUT_AFFECTEDROWS
)
AS
X SYS. XMLTYPE;
BEGIN
X: = SYS. XMLTYPE. CREATEXML (IN_ORDERCODESXML);
INSERT INTO MAINT_LABORD_CODES)
INSERT INTO MAINT_LABORD_CODES)
LABORD_CODE_ID,
COMPENDIUM_ID,
ORDER_CODE,
ORDER_DESC,
ACTIVE,
TIMESTAMP,
MODIFIED_BY)
SELECT MLOCDS_SEQ. NEXTVAL,
EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/COMPENDIUM_ID') AS COMPENDIUM_ID,
EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/ORDER_CODE') AS ORDER_CODE,
EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/ORDER_DESC') AS ORDER_DESC,.
EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/LOINC_CODE') AS LOINC_CODE,
EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/ACTIVE') AS ACTIVE.
EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/TIMESTAMP') AS TIMESTAMP.
EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/MODIFIED_BY') AS MODIFIED_BY
TABLE (XMLSEQUENCE (EXTRACT(X,'/ORDERCODES/ORDERCODE'))) NMCO;
OUT_AFFECTEDROWS: = NUMBER OF ROWS SQL %;
EXCEPTION
WHILE OTHERS THEN
dbms_output.put_line (SQLERRM);
RAISE_APPLICATION_ERROR (-20001, SQLERRM);
END;
Example of use of the FUSION-
If the line exists in the target table (based on the COMPENDIUM_ID and ORDER_CODE values), the UPDATE is, if not to INSERT:
declare in_ordercodesxml clob := '
500 696231 ABO Group & Rh Type NULL 12345 Y 2014-08-13 1 Also note that I used XMLTABLE instead of TABLE/XMLSEQUENCE, which is much easier to use (and not deprecated in the latest versions).
You have not precisely the date format in the TIMESTAMP element so I assumed a conform to W3C.
If you have a problem with this part, return to a projection of VARCHAR2 and use TO_DATE with actual size.
-
Extracting data from table using the date condition
Hello
I have a table structure and data as below.
create table of production
(
IPC VARCHAR2 (200),
PRODUCTIONDATE VARCHAR2 (200),
QUANTITY VARCHAR2 (2000).
PRODUCTIONCODE VARCHAR2 (2000).
MOULDQUANTITY VARCHAR2 (2000));
Insert into production
values ('1111 ', '20121119', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20121122', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20121126', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20121127', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20121128', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20121201', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20121203', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20121203', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20130103', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20130104', ' 1023', 'AAB77',' 0002');
Insert into production
values ('1111 ', '20130105', ' 1023', 'AAB77',' 0002');
Now, here I want to extract the data with condition as
PRODUCTIONDATE > = the current week Monday
so I would skip only two first rows and will need to get all the lines.
I tried to use it under condition, but it would not give the data for the values of 2013.
TO_NUMBER (to_char (to_date (PRODUCTIONDATE, 'yyyymmdd'), 'IW')) > = to_number (to_char (sysdate, 'IW'))
Any help would be appreciated.
Thank you
MaheshHello
HM wrote:
by the way: it is generally a good idea to store date values in date columns.One of the many reasons why store date information in VARCHAR2 columns (especially VARCHAR2 (200)) is a bad idea, it's that the data invalid get there, causing errors. Avoid the conversion of columns like that at times, if possible:
SELECT * FROM production WHERE productiondate >= TO_CHAR ( TRUNC (SYSDATE, 'IW') , 'YYYYMMDD' ) ;
-
insert into the table using dynamic data
Oracle form 6i
Hai
I need to insert data into a table. I have generated my data text file with data in a form, now I need to insert data into a table. How can insert my field at that table if it is given in the table, I need to update, and there is no data I need to insert... Pls tell me the solution...
Concerning
Srikkanth.MCreate the trigger of the sur-insert and check the data are thre or not through the value of the primary key in this trigger. If the data is thre then update or it is then do not insert in the same trigger.
Thank you
SUN -
Problem with update of table (using the subquery to retrieve value)
Hello
I update a table based on the value of the subquery.
Here's the update statement.
UPDATING temp xm
SET xm.col1 = (SELECT DISTINCT col1
Of
(SELECT col1, col2 COUNT (col2)
FROM table2
WHERE col1 = xm.col1
AND col2 = xm.col2
GROUP BY col1)
where col2 in (select... in the table3)
)
WHERE xm.col5 = < value >
AND xm.col6 = < value >
When I run this statement I get following error.
ORA-00904: "XM". "" Col1 ": invalid identifier.
Can someone help me why I get this error?
Why doesn't the main table alias in the subquery?
Is it possible to avoid this / re - write the query in a different way?
Thank you
Published by: user552703 on November 2, 2009 20:42You can nest only 1 level deep (referring to the table to be updated).
Have you looked at using the MERGE command? It is "easier" perform updates of this nature, assuming you are using a recent version of Oracle (9 or MORE).
-
Update the table using discoverer
Hello
I'm trying to update a table whenever the user runs a report of the Office of the discoverer. I tried to use a function to do the job, but I get the error below.
ORA-14551: cannot perform the DML operation within a query.
I also tried to
1. create a procedure and update the table in this procedure.
2. function to create and call the procedure created earlier in this function and use it in the discoverer, but still does not work and I get the same error ORA-14551.
Please let me know if this is possible at all the. If SO, let me know the steps to do so.
Thank you.Hello
Yes you can update the discoverer dashboards using a PL/SQL function. You must make the function a standalone transaction. for example
FUNCTION update_record (key_field VARCHAR2) RETURN VARCHAR2
IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
..
UPDATE your_table
..
COMMIT;
..Rod West
-
issue update a table using a function in pipeline
OK, I have an example simplified below what is happeningBANNER Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for HPUX: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production
I try to make updates or inserts in the tables and I use a function pipeline for this bed of the same tables of the to do.
and it gives me
My solution was to do a slider and update record row by row, but I was wondering if there is a way around this error?ORA-04091: table DSAMSTRC.T is mutating, trigger/function may not see it ORA-06512: at "DSAMSTRC.GET_T_ARRAY", line 6
Here's my example
DROP TABLE t; ------------------------------------------------------------------------------------ CREATE TABLE t AS SELECT LEVEL id, 'A' txt FROM DUAL CONNECT BY LEVEL <= 10; ------------------------------------------------------------------------------------- CREATE OR REPLACE TYPE t_table_type AS OBJECT (id NUMBER, txt VARCHAR2 (200)); ------------------------------------------------------------------------------------ CREATE OR REPLACE TYPE t_array AS TABLE OF t_table_type; ----------------------------------------------------------------------------------- CREATE OR REPLACE FUNCTION get_t_array (v_txt IN t.txt%TYPE) RETURN t_array PIPELINED IS BEGIN FOR EACH IN (SELECT id, txt FROM t WHERE t.txt = v_txt) LOOP PIPE ROW (t_table_type (EACH.id, EACH.txt)); END LOOP; RETURN; END; --------------------------------------------------------------------------------------- UPDATE t SET txt = 'B' WHERE id IN (SELECT id FROM TABLE (get_t_array ('A')));
You can create a global temporary table that has the same columns that use your function to insert in there, and then use it to update t.
CREATE GLOBAL TEMPORARY TABLE t_temp (id INTEGER, txt VARCHAR2(100)) ON COMMIT DELETE ROWS; INSERT INTO t_temp (SELECT id, txt FROM get_t_array('A')); UPDATE t SET t.txt = (SELECT txt FROM t_temp WHERE t_temp.id = t.id) WHERE t.id IN (SELECT id FROM t_temp);
-
How to build a table using incoming data stream?
I'm programming in VBAI but use LV as my Interface of Inspection. The VBAI program will go into a finite loop (x 1000) and the digital indicator with dbl vaule of food in front of the LV Panel if the value double is in order.
In LV, how to build a table (index 0-999) with this stream?
-
Update a table using COUNT (*)
I was wondering if there is a way to write the following code uses a single stmt:
Kind regards.FOR update_rec IN ( SELECT CODE, COUNT(APPOINTMENT) TOT FROM TEST GROUP BY CODE ) LOOP UPDATE TEST SET TOT_APPOINTMENT = update_rec.TOT WHERE CODE = update_rec.CODE; END LOOP;
You can use what is called a statement update correlated . Note that this is not tested:
UPDATE test t1 SET tot_appointment = ( SELECT COUNT(*) FROM test t2 WHERE t1.code = t2.code ) ;
-
Import of differnet schema table using the data pump in
Hi all
I try to export a table to a diagram MIPS_MDM and import it in the MIPS_QUIRINO schema in the different database. I get the below error.
expdp MIPS_MDM/MIPS_MDM@ext01mdm tables = QUARANTINE directory = DP_EXP_DIR dumpfile = quarantine.dmp logfile = qunat.log
To import
Impdp MIPS_QUIRINO/MIPS_QUIRINO@mps01dev tables = QUARANTINE directory = DP_EXP_DIR dumpfile = quarantine.dmp logfile = impd.log
Please can I know what is the exact syntax to import in the scheme of differnet.
Thank you.http://download.Oracle.com/docs/CD/E11882_01/server.112/e16536/dp_import.htm#BEHFIEIH
-
should I turn off my IKM for faster migration update if I have static data?
I have no much experience with ODI and I know that sounds like a very long explanation, but if you have experience using ODI respondent should not be that difficult, please bear with me on this one...
I move data between Postgres, Oracle 12 c. Use my interfases: incremental update for IKM Oracle and IKM Oracle incremental update PL SQL (using long data types). The tables are in the order of several hundred million of 100 million more 500 million lines from wherever we have to run the interfases as soon as possible. Because of my inexperience with ODI, I'm not sure if I select the right options to run the interfaces:
1 as soon as possible
2 - with the possible minimum measures
The aim is only to move static data to Postgres to Oracle, that's all. (there is very few transformations, for most of the castings to force data to a certain type of data)
With my current selections, the IKM Oracle incremental update (PL SQL) ODI does the following:
-working table, create work table C$ _0 < TABLE TARGET - >
-working table charges <-this step loads the postgres data in the oracle table... <-that's ALL I NEED! .. .load of Postgres to Oracle...
-creates the flow table: I have$ _ < TABLE TARGET - >
-then using a cursor selects all data from the TABLE of WORK C$ _0, load: I have$ _ < TABLE-TARGET > <-is there a way to avoid all these additional tables?
-create indexes and statistics on I$ _ < TABLE TARGET - >
-flags of lines for the realization of the update if the lines already exist in the < TARGET > TABLE
-Using a cursor selects all I$ __ where IND_UPDATE = 'I' and inserts data into the TABLE < TARGET > < TABLE TARGET >
My data source are static and its integrity is verified by FK in Postgres, so I'm not worried about the quality of the db of the source, to the IKM my options are:
Insert is: TRUE
Update: TRUE <-would it be wrong? (I think this one can be false for me because my source table is static and my target doesn't support only once for the first time is always empty table)
flow control is FALSE
static control is FALSE
Has. are all of the options to reduce the steps performed during the interface? (it seems I need to UPDATE set to false on the revenge for each interface)
I load a table with 110 millions of rows, work began in 24 hours. To load the table of Postgres to Oracle took 4 hours and 10 minutes, but to load the flow table (PLSQL cursor) took more than 20 hours for barely half of labour (52 million lines)
All the data I need is on the work table, I can stop the interface and rename the columns but I wonder... B. what is the right action to take here? how to change the settings of the ODI, so they just move the data from the source to the target only and avoid any other measure reducing the total execution time.
C. the server has 32 processors, but ODI seems to use one. How can I take advantage of the CPU?
Thanks for your help.
P.S. I have read all the documentation there, but it is difficult to get concrete responses with no experience using the product and no other indication. I'm learning to use the tool by using the documentation only.
Hello
I would check this vlog by Craig Stewart first to see if can do you need:
http://odiexperts.com/direct-load-by-interface-with-no-work-tables/
Otherwise, there are a few points I would make:
You use the bad IKM with a cursor, if you load Oracle and you want to insert / update, then I always would start by merging first.
Second, feel free to hack the km to get what you want (always duplicate an existing and start from there, he avoids you to come once upgrade). If you look at the LKM, the insert in $ CAN use a different API call to get table name of $ CAN, you can always get the name of the target table (see the appropriate step of revenge for syntax) and to use it in the same place (perhaps to tweak the getColList in the same way) I've done it before - I created a LKM to write directly in the target table , I need an IKM has nothing so used a dummy not (interface complains with no set IKM), not to the customer more, don't have it to hand, but I'm willing to help if you want to PM me.
For Question C - seems you want o use parallelism, see the Oracle documentation first to get on the same page. You need optimizer parameters set correctly and your tables must be created with parallel hint in the DDL (maybe need to change any ODI create table steps accordingly).
Try to get the optimizer to get correct PX parameters before you use to alter session strength parallel etc etc.
Rgrds
Alastair
-
Best way to update a table with separate values
Hi, I would really appreciate some advise:
I need to regularly perform a task where I update 1 table with all the new data that has been entered in another table. I cannot perform a complete insert because this will create data duplicated each time it works, so the only way I can think of is the use of cursors in the script below:
CREATE OR REPLACE PROCEDURE update_new_mem IS
tmpVar NUMBER;
CURSOR c_mem IS
SELECT nom_membre, member_id
OF gym.members;
CREC c_mem % ROWTYPE;
BEGIN
OPEN c_mem.
LOOP
SEEK c_mem INTO crec;
EXIT WHEN c_mem % NOTFOUND;
BEGIN
UPDATE gym.lifts
Name = crec.member_name
WHERE member_id = crec.member_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
IF SQL % NOTFOUND THEN
BEGIN
INSERT INTO gym.lifts
(name, member_id)
VALUES (crec.member_name, crec.member_id);
END;
END IF;
END LOOP;
CLOSE C_mem;
END update_new_mem;
This method works, but y at - it a (faster) easier way to update another table with new data only?
Thank you very much>
This method works, but y at - it a (faster) easier way to update another table with new data only?
>
Almost anything would be better than this treatment of slow-by-slow loop.You don't need a procedure, you should just use MERGE for this. See the examples in the section of the MERGER of the doc of the SQL language
http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_9016.htmMERGE INTO bonuses D USING (SELECT employee_id, salary, department_id FROM employees WHERE department_id = 80) S ON (D.employee_id = S.employee_id) WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01 DELETE WHERE (S.salary > 8000) WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus) VALUES (S.employee_id, S.salary*.01) WHERE (S.salary <= 8000);
-
Could not send an individual column by using a data binding
Hello
I have a data set (testdatalink) link to access the table of database SQL Server reading
now in my Toad or sql prompt I quried the table using this data binding
Select * from sqltable@testdatalink;
With this I have no problem
But when I ask a specific column as
Select col1 from sqltable@testdatalink;
or when I try to update a column
It says COL1 IS not a VALID IDENTIFIER;
My final requirment is to update a column in this table of SQL server based on certain conditions.
I tried to give a name, alis, but no use.
Please let me know if is there any method of reference in the columns of the table
Thanks in advance
Published by: DharV on August 10, 2011 02:45If the columns are lowercase in Sukkelserver, you must
Select 'col1' of reading @...
--------
Sybrand Bakker
Senior Oracle DBA
Maybe you are looking for
-
Re: Satellite M100: BSOD at each start of the first up - but ok after that
I have a weird problem. Recently, I bought a laptop series M100 in Thailand - he has worked there. Brought to the United Kingdom and since then now on a startup cold upward, I get a blue screen every time, and after that one or 2 other blue screens -
-
Download Microsoft updates caused life cam microsoft to have initialization error!
After that microsoft download these updated my microsoft life cam won't work, received error message "initialization error". It worked fine before downloads. I tried to uninstall and re install - suggestions?
-
__I need RIO mp3 drivers___Mike
I NEED HELP PLEASE!I have a computer Dell Dimension with Windows Vista Home Premium installed, but I have a RIO carbon MP3 PLAYER C E 2100 series that was provided with a program disk that is for Windows XP I have on a separate computer. This drive d
-
Change the order of VLAN native?
Can someone refresh me please as to what the command is to change the VLAN native for the whole switch? (IE: not only on the trunk, I mean the default native for the whole switch). Thank you
-
missing commands on IOS 3.6.4E
Hi ISE experts. I recently had a switch Catalyst 3850-24 p upgrade to IOS 3.6.4E and we found below 2 commands are missing from the running configuration. RADIUS vsa server send accountingRADIUS vsa server send authentication the switch seems to be t