Update of the data in the table using LAG/LEAD
Hello!I have a table that looks like:
CREATE TABLE CUSTOMER_INFO_TEST
(
ACCOUNT_NUM VARCHAR2 (40 BYTE),
PHONE VARCHAR2 (100 BYTE),
E-MAIL VARCHAR2 (300 BYTE),
DATE OF START_DT,
DATE OF CHANGE_DT,
END_DT DATE
);
The example data:
INSERT INTO CUSTOMER_INFO_TEST VALUES ('BOB', 555-1234', ", TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-06', 'YYYY-MM-DD'), TO_DATE ('2011-01-10', 'YYYY-MM-DD'));
INSERT INTO CUSTOMER_INFO_TEST VALUES ('BOB', 555-1234', ' BOB@GMAIL.) COM', TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-11', 'YYYY-MM-DD'), NULL);
INSERT INTO CUSTOMER_INFO_TEST VALUES ('BOB', 555-1234', ' BOB@GMAIL.) COM', TO_DATE ('2011-01-01', 'YYYY-MM-DD'), TO_DATE ('2011-01-15', 'YYYY-MM-DD'), NULL);
INSERT INTO CUSTOMER_INFO_TEST VALUES ('JACK', 555-4321', ", TO_DATE ('01-03-2011', 'YYYY-MM-DD'), TO_DATE ('2011-03-06', 'DD-MM-YYYY'), NULL);
INSERT INTO CUSTOMER_INFO_TEST VALUES ('JACK', 555-4321', ' JACK@GMAIL.) COM', TO_DATE ('01-03-2011', 'YYYY-MM-DD'), TO_DATE ('2011-03-11', 'YYYY-MM-DD'), NULL);
My question:
How can I configure end_dt (if null), to the next change_dt minus one
It shows what I want to do:
Select the rowid, account_num, phone, e-mail, start_dt, change_dt, end_dt, nvl (end_dt, lead (change_dt-1, 1) over (partition by account_num of start_dt order)) enddt CUSTOMER_INFO_TEST where end_dt is null;
So, I want to update the table itself with the date in enddt. But how do I do this?
This must be done in a single statement...
Thanks in advance
Richard
Published by: user6702107 on 05-Jan-2011 09:11
Edited by: Rydman on April 17, 2012 15:01
Please post sample data!
If your query returns the desired results, you can use the MERGE:
SQL> select *
2 from customer_info_test;
ACCOUNT_NU PHONE EMAIL START_DT CHANGE_D END_DT
---------- ---------- ------------------------- -------- -------- --------
BOB 555-1234 01-01-11 06-01-11 10-01-11
BOB 555-1234 [email protected] 01-01-11 11-01-11
BOB 555-1234 [email protected] 01-01-11 15-01-11
JACK 555-4321 01-03-11 06-03-11
JACK 555-4321 [email protected] 01-03-11 11-03-11
5 rows selected.
SQL> --
SQL> merge into customer_info_test a
2 using ( select rowid rid
3 , nvl(end_dt, lead(change_dt-1, 1) over (partition by account_num order by start_dt)) new_end_dt
4 from customer_info_test
5 where end_dt is null
6 ) b
7 on (a.rowid = b.rid )
8 when matched then update set a.end_dt = b.new_end_dt;
4 rows merged.
SQL> --
SQL> select *
2 from customer_info_test;
ACCOUNT_NU PHONE EMAIL START_DT CHANGE_D END_DT
---------- ---------- ------------------------- -------- -------- --------
BOB 555-1234 01-01-11 06-01-11 10-01-11
BOB 555-1234 [email protected] 01-01-11 11-01-11 14-01-11
BOB 555-1234 [email protected] 01-01-11 15-01-11
JACK 555-4321 01-03-11 06-03-11 10-03-11
JACK 555-4321 [email protected] 01-03-11 11-03-11
5 rows selected.
Tags: Database
Similar Questions
-
Build the value of 100 mb of data in the table using the loop
DB version: 11.2
How can I create about 100 MB of test data in a table using minum number of records.
If I use the below for loop. It takes 100,000 records to fill only 2 MB.
SQL> create table a2 (mynum1 number, mynum2 number); Table created. begin for i in 1..100000 loop insert into a2 values(i,i*2); end loop; end; select segment_name, bytes/1024/1024 MB from dba_segments where segment_name = 'A2' AND owner='SCOTT' SEGMENT BYTES/1024/1024 -------- --------------- A2 2
Hello
Is that what you are looking for?
SQL> CREATE TABLE tbl1(c1 CHAR(1024)); -- ~1KB per row Table created. Elapsed: 00:00:00.00 SQL> INSERT /*+ APPEND */ INTO tbl1 SELECT 'X' FROM dual CONNECT BY LEVEL < 100000; -- 100K rows * 1KB = 100MB + some additional overhead 99999 rows created. Elapsed: 00:00:13.02 SQL> SELECT bytes/1024/1024 MB FROM user_segments WHERE segment_name = 'TBL1'; MB ---------- 113.75
Lukasz
-
Hi people,
I looked through many messages about refreshing the page, but still did not solve my problem. Please help me. It's quite URGENT.
I have a table with a command button. After you click the data insertion is engaged and the table is supposed to be updated to reflect the changes.
Now I use PPR as my solution: the button is the initiator and the table is the target. I put the button property: part delivery = true and its id as a partial release of the table value
What I missed, please?
Note: reloading of the entire page is not a solution for me. (The table is incorporated within a region of showOneTab and there are other tables in different tabs)
Thanks in advance!Assuming that nothing wrong with the JavaScript syntax, the explanation might be: If you ActionListener Installer (data transaction method) and javaScript on a button-click the button, the button click javaScript will not be executed. (???)This is not the case. In my application, the two actions of script and java onclick button are executed. Javascript onclick fires first, then the action of the button. It should be the same for actionlistener as well.
Regarding the updating of the table after a click of a button inside the table, you can do this by forcing the partial relaxation of the table of a bean to support using addPartialTarget.
On the actionListener to the button call the below the backup method of bean.
Here is the code example:
public void btnSample_actionListener(ActionEvent actionEvent) { // First execute the method on the button BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding("buttonMethod"); Object result = operationBinding.execute(); //Refresh the iterator of table and partial trigger the table OperationBinding operationBindingTab = bindings.getOperationBinding("RefreshTable"); Object resultTab = operationBindingTab.execute(); AdfFacesContext.getCurrentInstance().addPartialTarget(myTable);
RefreshTable is an action that runs the Execute method on the table iterator.
Thank you
Mitesh. -
How to insert image from mysql into the table using php and create the checkbox in the table?
How can I insert image from mysql into the table using php and create the checkbox for each data as a vote? Here is my code...
WELCOME
If you have saved the file name in the database, it's pretty simple.
echo '';
Is the same for the box:
echo '';
If you have saved the image file in the database, it is much more complicated. I recommend you store only the file name in the database.
-
The table used to run very quickly
I read about 22000 records of weak financial data in a graph of candel stick. The table used to run very quickly, but now it works slow Koala after some small changes. Ideas of probable causes?I figured out that the disabledDays was originally the slow almost 10 times slower
disabledDays = "{offDays}.
-
How to know the tables used in packages of a schema.
How to know the tables used in packages of a pattern that I have connected.
SELECT DISTINCT referenced_owner, referenced_name
Of all_dependencies
Owner WHERE = "MY_USER_NAME".
AND type ('PACKAGE', 'BODY of PACKAGE')
AND referenced_type = 'TABLE '.
-
Trying to create the table using Clause any Union with Select multiple stmts
The motion seeks to get the substring of the value to for example.
If the value is * ASA 2 * then so do ASA
where as if the value is * 1.5 TST * it sholud come as TST as wise for others too.
I am trying to execute stmt SQL written but in error as below:
* ' ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias. "
CREATE TABLE TEST_CARE AS
(
SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
WHERE LENGTH (old_care_lvl) = 5
UNION ALL
SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
WHERE LENGTH (old_care_lvl) = 7
UNION ALL
SELECT row_id, old_care_lvl, SUBSTR(old_care_lvl,3), len test_care_lvl FROM
WHERE LENGTH (old_care_lvl) = 14
UNION ALL
Row_id SELECT, old_care_lvl, SUBSTR (old_care_lvl, 3), LEN test_care_lvl
WHERE LENGTH = 7 AND old_care_lvl (old_care_lvl) = "Regular."
);
I want to create the table using the above given the multiple selection by using the Union ALL clause, but trying to create run query error like "ORA-00998 must appoint this expression with the alias column 00998.00000 - must appoint this expression with the column alias.
Please guide me how to approach to solve this problem.
Thanks in advance.Try this->
CREATE TABLE TEST_CARE AS select * from ( SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl WHERE LENGTH(old_care_lvl) =5 UNION ALL SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl WHERE LENGTH(old_care_lvl) =7 UNION ALL SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl WHERE LENGTH(old_care_lvl) =14 UNION ALL SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular' );
N.B.: Not tested...
Kind regards.
LOULOU.
-
SQL Loader loading data into two Tables using a single CSV file
Dear all,
I have a requirement where in I need to load the data into 2 tables using a simple csv file.
So I wrote the following control file. But it loads only the first table and also there nothing in the debug log file.
Please suggest how to achieve this.
Examples of data
Source_system_code,Record_type,Source_System_Vendor_number,$vendor_name,Vendor_site_code,Address_line1,Address_line2,Address_line3
Victor, New, Ven001, Vinay, Vin001, abc, def, xyz
Control file script
================
OPTIONS (errors = 0, skip = 1)
load data
replace
in the table1 table:
fields ended by ',' optionally surrounded "" "
(
Char Source_system_code (1) POSITION "ltrim (rtrim (:Source_system_code)),"
Record_type tank "ltrim (rtrim (:Record_type)),"
Source_System_Vendor_number tank "ltrim (rtrim (:Source_System_Vendor_number)),"
$vendor_name tank "ltrim (rtrim (:Vendor_name)),"
)
in the Table2 table
1 = 1
fields ended by ',' optionally surrounded "" "
(
$vendor_name tank "ltrim (rtrim (:Vendor_name)),"
Vendor_site_code tank "ltrim (rtrim (:Vendor_site_code)),"
Address_line1 tank "ltrim (rtrim (:Address_line1)),"
Address_line2 tank "ltrim (rtrim (:Address_line2)),"
Address_line3 tank "ltrim (rtrim (:Address_line3)).
)the problem here is loading into a table, only the first. (Table 1)
Please guide me.
Thank you
Kumar
When you do not provide a starting position for the first field in table2, it starts with the following after a last referenced in table1 field, then it starts with vendor_site_code, instead of $vendor_name. So what you need to do instead, is specify position (1) to the first field in table2 and use the fields to fill. In addition, he dislikes when 1 = 1, and he didn't need anyway. See the example including the corrected below control file.
Scott@orcl12c > test.dat TYPE of HOST
Source_system_code, Record_type, Source_System_Vendor_number, $vendor_name, Vendor_site_code, Address_line1, Address_line2, Address_line3
Victor, New, Ven001, Vinay, Vin001, abc, def, xyz
Scott@orcl12c > test.ctl TYPE of HOST
OPTIONS (errors = 0, skip = 1)
load data
replace
in the table1 table:
fields ended by ',' optionally surrounded "" "
(
Char Source_system_code (1) POSITION "ltrim (rtrim (:Source_system_code)),"
Record_type tank "ltrim (rtrim (:Record_type)),"
Source_System_Vendor_number tank "ltrim (rtrim (:Source_System_Vendor_number)),"
$vendor_name tank "ltrim (rtrim (:Vendor_name)).
)
in the Table2 table
fields ended by ',' optionally surrounded "" "
(
source_system_code FILL (1) POSITION.
record_type FILLING,
source_system_vendor_number FILLING,
$vendor_name tank "ltrim (rtrim (:Vendor_name)),"
Vendor_site_code tank "ltrim (rtrim (:Vendor_site_code)),"
Address_line1 tank "ltrim (rtrim (:Address_line1)),"
Address_line2 tank "ltrim (rtrim (:Address_line2)),"
Address_line3 tank "ltrim (rtrim (:Address_line3)).
)
Scott@orcl12c > CREATE TABLE table1:
2 (Source_system_code VARCHAR2 (13),)
3 Record_type VARCHAR2 (11),
4 Source_System_Vendor_number VARCHAR2 (27),
5 $vendor_name VARCHAR2 (11))
6.
Table created.
Scott@orcl12c > CREATE TABLE table2
2 ($vendor_name VARCHAR2 (11),)
3 Vendor_site_code VARCHAR2 (16).
4 Address_line1 VARCHAR2 (13),
5 Address_line2 VARCHAR2 (13),
Address_line3 6 VARCHAR2 (13))
7.
Table created.
Scott@orcl12c > HOST SQLLDR scott/tiger CONTROL = test.ctl DATA = test.dat LOG = test.log
SQL * Loader: release 12.1.0.1.0 - Production on Thu Mar 26 01:43:30 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Path used: classics
Commit the point reached - the number of logical records 1
TABLE1 table:
1 row loaded successfully.
Table TABLE2:
1 row loaded successfully.
Check the log file:
test.log
For more information on the charge.
Scott@orcl12c > SELECT * FROM table1
2.
RECORD_TYPE SOURCE_SYSTEM_VENDOR_NUMBER $VENDOR_NAME SOURCE_SYSTEM
------------- ----------- --------------------------- -----------
Victor Ven001 new Vinay
1 selected line.
Scott@orcl12c > SELECT * FROM table2
2.
$VENDOR_NAME VENDOR_SITE_CODE ADDRESS_LINE1 ADDRESS_LINE2 ADDRESS_LINE3
----------- ---------------- ------------- ------------- -------------
Vinay Vin001 abc def xyz
1 selected line.
Scott@orcl12c >
-
How to publish data from a table using the form
Oracle forms6i
Hai All
I have download the data to the table of forms...
My table T1 columns are in, out, intrinsically, introut, empname, empno
and another table T2 consist of three columns is empno, date, time
In table T2 time fields consist of symbol I, o... I mean IN, O OUT
My Question is when an employee consist of 3 I - the three IN the time
0815 I, 1200 I, 1415 I and OUT 3 times O 1245, 1445 O, O 1715 and empno is 001
If there is no record for empno 001 then insert first 0815 I in table T1 in column IN time then
to update 1200 intrinsically and 1245 update to Introut and 1415 up-to-date addin and 1445 to update addout
Finally in 1715 to outtime
If it is possible to do without Hardcoding the moment Pls tell with some good example
Thanks in advance
Srikkanth.MThere now things are clear... whenever I have free I'll post the code u how to do this...
for now, a few tips can help u
-create the table to store operations travel so then u can't fix your code
-Create the cursor on the T1 line through all the records.
-Control what empno and action i.e. the current cursor (I or O) exists on the same date in T2 or not
-otherwise exists insert a new record check also the SHIFT is coming in time IF is between MAJ 0815 and 1645 and action is 'I' then insert record and column values accordingly
s ' there is, then update the record of the place where empno = cur.empno and attendance_date = mydate;
It may be useful
Baig,
[My Oracle Blog | http://baigsorcl.blogspot.com/] -
How to add data to the table using Manager POST for restful Apex application
Hi all
I managed to create a service application web Manager restful using GET for the Restful service module. I am able to get the data in row on the presentation of a table row id in the application. But I can't find an appropriate example, how the new data in the table can be posted or deleted. I created a POST handler for a URI scheme and look forward on how to proceed. Any help would be really appreciated.
Source for the POST Manager:
Start
insert into ALL_BOOKS values(:id,:book);
end;
Also created 2 parameters id and the book.
Hi jerry2134,
jerry2134 wrote:
I managed to create a service application web Manager restful using GET for the Restful service module. I am able to get the data in row on the presentation of a table row id in the application. But I can't find an appropriate example, how the new data in the table can be posted or deleted. I created a POST handler for a URI scheme and look forward on how to proceed. Any help would be really appreciated.
Source for the POST Manager:
Start
insert into ALL_BOOKS values(:id,:book);
end;
Also created 2 parameters id and the book.
Check out the following tutorials OBE, that explains the creation of GET and POST RESTful Web Services and how to use them in the APEX.
- Creation and use of RESTful Web application services Express 4.2
- Creation and use of RESTful Web application services Express 5.0
Also what yo mean "looking forward on how to proceed? Do you want to or created for use/consume in your Oracle APEX application hosted RESTful web services?
If Yes, in your Application, you must create a RESTful Web Service reference -> shared components. Then, create a form/report based on Web Service reference.
Kind regards
Kiran
-
XML data in the table using sql/plsql
Hi experts,
Could you please help with the following requirement. I have the tags xml (.xml on a server file) below. I need to access this file and read the XML and insert into the db table using sql and plsql. Is it possible with the cdata below? And there is a nested this table.
Could someone please guide me if you have a sample code file and xml.
<? XML version = "1.0" encoding = "UTF-8"? >
< generation_date > <! [CDATA [17/11/2015]] > < / generation_date >
< generated_by > <! [CDATA [Admin Admin]] > < / generated_by >
< year > <! [CDATA [2015]] > < / year >
< month > <! [CDATA [01]] > < / month >
< author >
< author > <! [CDATA [user author]] > < / author > < author_initial > <! [CDATA [user]] > < / author_firstname > < author_country > <! [CDATA [author]] > < / author_lastname >
< author_email > <! [CDATA [[email protected]]] > < / author_email >
< author_data_01 > <! [CDATA []] > < / author_data_01 >
< author_data_02 > <! [CDATA []] > < / author_data_02 >
< items >
< article_item >
< article_id > <! [CDATA [123456]] > < / article_id >
< publication > <! [CDATA [Al Bayan]] > < / publication >
< section > <! [CDATA [Local]] > < / section >
< issue_date > <! [CDATA [11/11/2015]] > < / issue_date >
< page > <! [CDATA [2]] > < / print this page >
< article_title > <! [CDATA [title.]] > < / article_title > < number_of_words > <! [CDATA [165]] > < / number_of_words >
< original_price > <! [CDATA [200]] > < / original_price >
< original_price_currency > <! [CDATA [DEA]] > < / original_price_currency >
< price > <! [CDATA [250]] > < / price >
< price_currency > <! [CDATA [DEA]] > < / price_currency >
< / article_item >
< / articles >
< total_amount > <! [CDATA [250]] > < / total_amount >
< total_amount_currency > <! [CDATA [DEA]] > < / total_amount_currency >
< / author >
< / xml >
Thanks in advance,
Suman
XMLTABLE using...
SQL > ed
A written file afiedt.buf1 with t (xml) as (select xmltype ('))
2 ") of the double)"
3
4
5
6
7
8
9
10
11
[[12[email protected]]] >
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34-
35 end of sample data
36-
37 - assumptions:
(38 - a) XML may have several tags
(39 - b) eachmay contain more
40-
41 select x.gen_by, x.gen_date, x.mn, x.yr
42, y.author, y.auth_fn, y.auth_ln, y.auth_cnt, y.auth_em, y.auth_d1, y.auth_d2
43, z.id, z.pub, z.sec, z.iss_dt, z.pg, z.art_ttl, z.num_wrds, z.oprice, z.ocurr, z.price, z.curr
44 t
45, xmltable ('/ authxml')
from $ 46 t.xml
path of 47 columns gen_date varchar2 (10) '. / generation_date'
48, path of varchar2 (15) of gen_by '. / generated_by'
49, path of varchar2 (4) year '. "/ year"
50 varchar2 (2) mn road '. "/ month"
51, path of xmltype authors '.'
52 ) x
53, xmltable ('/ authxml/authors ')
from $ 54 x.authors
author of 55 path of varchar2 columns (15) '. / author'
56, path of varchar2 (10) of auth_fn '. / author_firstname'
57, path of varchar2 (10) of auth_ln '. / author_lastname'
58 road of VARCHAR2 (3) auth_cnt '. / author_country'
59 road of varchar2 (20) of auth_em '. / author_email'
60 road of varchar2 (5) of auth_d1 '. / author_data_01'
61, path of varchar2 (5) of auth_d2 '. / author_data_02'
62, path of xmltype articles '. / Articles'
63 ) y
64, xmltable ('/ Articles/article_item ')
from $ 65 y.articles
path id 66 number columns '. / article_id'
67, path of varchar2 (10) pub '. ' / publication.
68 road of varchar2 (10) dry '. / section'
69, path of varchar2 (10) of iss_dt '. / issue_date'
70 road of VARCHAR2 (3) pg '. "/ print this page"
71, path of varchar2 (20) of art_ttl '. / article_title'
72, path of varchar2 (5) of num_wrds '. / number_of_words'
73, path of varchar2 (5) of oprice '. / original_price'
74 road to VARCHAR2 (3) ocurr '. / original_price_currency'
75, path of varchar2 (5) price '. "/ price"
76, path of VARCHAR2 (3) curr '. / price_currency'
77* ) z
SQL > /.GEN_DATE GEN_BY YEAR MN AUTHOR AUTH_FN AUTH_LN AUT AUTH_EM AUTH_ AUTH_ ID PUB DRY ISS_DT PG ART_TTL NUM_W OPRIC HEARTS PRICE OCU
---------- --------------- ---- -- --------------- ---------- ---------- --- -------------------- ----- ----- ---------- ---------- ---------- ---------- --- -------------------- ----- ----- --- ----- ---
17/11/2015 Admin Admin 2015 01 user author user author [email protected] 123456 UAE Al Bayan Local 11/11/2015 2 is the title. 165 200 AED AED 250Of course, you'll want to change the types of data, etc. as needed.
I assumed that the XML can contain several "
" sections and that each section can contain several entries. Thus the XMLTABLE aliasing as 'x' gives information of XML, and supplies the data associated with the XMLTABLE with alias 'y' which gets the multiple authors, which itself
section of the XMLTABLE with alias 'z' for each of the article_item. CDATA stuff are handled automatically by SQLX (XML functionality integrated into Oracle's SQL)
-
Update on the table by extracting the data from the table even under certain conditions
Hi Experts,
I have the table EMP which currently has 6 entries.
EMP_SYS BATCH_NO JOIN_DATE LOGIN_ID STATUS FLAG
1 FEBRUARY 10 PROD 84 Y IND123 ABC
DEV 1-23 APRIL 98 Y IND123 ABC
2 12 APRIL PROD 98 Y IND123 ABC
2 2 APRIL DEV 98 Y IND123 ABC
3 13 APRIL PROD 98 Y IND123 ABC
3 3 APRIL DEV 98 Y IND123 ABC
CONDITION: I need to take lines which has the minimum BATCH_NO for each of the EMP_SYS
for example,.
1 FEBRUARY 10 PROD 84 Y IND123 ABC
DEV 1-23 APRIL 98 Y IND123 ABC
For the above two lines, I need to update the status of DEF. How to select this criterion and update in the same query?
Currently, I used the query to select the minimum BATCH_NO for each of the EMP_SYS below.
SELECT EMP_SYS, BATCH_NO, JOIN_DATE, FLAG, LOGIN_ID, STATUS
Of
(
EMP_SYS, BATCH_NO, JOIN_DATE, FLAG, LOGIN_ID, STATUS, SELECT ROW_NUMBER)
COURSE NR (PARTITION BY ORDER OF EMP_SYS OF EMP_SYS)
FROM EMP
WHEN STATUS = 'ABC' AND FLAG = "Y".
)
WHERE
NR = 1;
If I try to use the update on the above query statement... It updates every 6 rows instead of 2 rows.
Please suggest me a way to update only the two lines that has the minimum BATCH_NO for each of the EMP_SYS.
But is possible to write the query without using the Group of?
Update e EMP
set STATUS = "DEF".
where BATCH_NO = (select min (BATCH_NO) from EMP I where STATUS = 'ABC' AND FLAG = 'Y' and i.emp_sys = e.emp_sys)
-
update of the lookup using the fusion query table
Hi Experts,
My requirement is, we have total 4 tables called x, y, z and a_lookup table. join between these tables column is deptno.
I need to update a_lookup table based on less than the conditions of the
condition1: table a_lookup update with the corresponding records of X and Y
condition2: If there is no record in X does not match, then we have to compare with Z and update the table a_lookup accordingly
Here is the table scripts and my attempt as well.
Only doubt is, is my fine appearance of MERGE statement, or is it otherwise better update the a_lookup table?
Please share your ideas on this.
create table x (empno, deptno number);
-Samples
Insert into x
Select the level, level * 10 double connect by level < = 10;create table y (empno number, number deptno).
-Samples
Insert y
Select the level, level * 10 double connect by level < = 5;create table z (empno number, number deptno);
-SamplesInsert into z
Select the level, level * 10 double connect by level < = 10;create the table a_lookup (empno number, deptno_lookup number);
-Samples
insert into a_lookup
Select null, level * 10 double connect by level < = 10;-Merging of records in a_lookup based on X, Y, z. using right outer join on X and Y
Fusion in a_lookup one
using the ((select x.deptno, x.empno from x, y where x.deptno = y.deptno)
Union of all the
(select z.deptno, z.empno in z, (select x.deptno from x, y where x.deptno = y.deptno and y.deptno is null) res1)
where z.deptno = res1.deptno)
) res
on (a.deptno_lookup = res.deptno)
When matched then
update set a.empno = res.empno;
See you soon,.
Suri ;-)
Like this
Fusion in a_lookup one
a_l'_aide_de)
Select deptno nvl (a.deptno, z.deptno)
empno nvl (a.empno, z.empno)
z
left
Join them)
Select x.deptno
x.empno
x
left join y
On x.deptno = y.deptno
where y.empno is not null
) a
On z.deptno = a.deptno
) b
on)
a.deptno_lookup = b.deptno
)
When matched then
update set a.empno = b.empno;
-
My select statement fails with the error:
The ORA-19011 string buffer too small
The select statement looks like:
SELECT TO_CLOB)
XMLELEMENT ("accounts",
XMLELEMENT ("count",
XMLATTRIBUTES)
rownum AS "recordId."
To_date('20130520','YYYYMMDD') AS "datestarted."
123456 AS "previousBatchId."
56789 AS 'previousRecordId '.
),
....
.... .
.....
XMLFOREST)
SIG_ROLE AS "SignatoryRole."
To_char(TRANSFER_DATE,'YYYY-mm-DD') AS "TransferDate."
NVL(Reason,0) AS 'reason '.
) AS the 'transfer '.
)
()) AS CRDTRPT
OF ANY_TABLE;
- It looks like I can choose only 4000 characters using the SELECT statement (please, correct me if I'm wrong)
I'd use the XMLGEN package. But the environment team says no mounted drives in the future with the arrival of the EXADATA.
NO HARD DRIVE MOUNTED, NO ACCESS TO THE DATABASE DIRECTORIES
No UTL_FILE
I need to use the REEL spool the resulting XML data of the SELECT query.
SQL is a standard in my org, but I can do with a PL/SQL solution also to load data into a table (cannot use a COIL with PL/SQL)
What I do is:
- a column of type CLOB to a xml_report of the loading of the above SELECT query table
- Then using SELECT * FROM xml_report to SPOOL the data to a file report.xml
No need of XMLTYPE data behind. Xml data stream is fine for me.
In addition, I need to validate the XML file, also using XSD.
Problem is that the resulting lines of the select query are supposed to be from 15000 to 20000 bytes long.
Oracle database version: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
A Suggestion or a solution to this problem would be appreciated.
(Sorry for the use of "BOLD", just to make it more readable and highlight the imp points)
Bravo!
Rahul
It looks like I can choose only 4000 characters using the SELECT statement (please, correct me if I'm wrong)
You use the right method.
There is an implicit conversion from XMLType to the data type VARCHAR2 as expected by the function TO_CLOB, where the limitation, and the error.
To serialize XMLType to CLOB, use the XMLSerialize function:
SELECT XMLSerialize (DOCUMENT
XMLELEMENT ("accounts",
...
)
)
OF ANY_TABLE;
For the rest of the requirement, I wish you good luck trying to spool the XML correctly.
You may need to play around with the SET LONG and SET LONGCHUNKSIZE commands to operate.
-
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
Maybe you are looking for
-
Need information about Toshiba Reeltime
Hello, could someone please tell me what Toshiba Reeltime is and how it works? He said nothing about it in the owners manual. Thank you
-
Y580 GTX 660 m &; HD 4000 supported Technologies?
Hi again, I have another question on my new Y580 and his GTX 660 m. NVIDIA posted: support technology: 3D Vision, CUDA, DirectX 11, PhysX, Optimus, OpenCL, DirectCompute. When I open the GPU - Z (with my gtx 660 m running) on the bottom, I don't get
-
Error: "Signal out of range".
Original title: monitor sensitivity while trying to adjust my screen monitor sensitivity I have increased it too far and now get a blank screen and the message... out of the range of scan... I can't use my main computer now and need help to get the s
-
Cannot install Windows update due to error codes: 0 x 80244015 or 80070020. What should I do to correct errors?
-
My taskbar has disappeared.
When I turn on the cpu, it is, but once all the loading, he faints. I can bring up the menu start by pressing the windows, but if I reduce all the windows, they're just gone.