update of NULL in the column with the values of the adjacent column
Examples of data
with test_data as (select 1 as one, null as two, 2 as three,5 as four, 6 as five, null as six from dual union all select 1 as one, null as two, 2 as three,5 as four, 6 as five, null as six from dual) select * from test_data;
This is one of those cases, the case may be where any value of a column can be null
or two similar columns can be null. If the column is null then I want to update the adjacent column
average value of the column, if the first column is null so I want to take the next non-null column and update, if the last column is null
so I want to take prev not zero column and to update.
In this case would be my expected output
Un | Two | Three | Four | Five | Six |
---|---|---|---|---|---|
1 | 1.5 | 2 | 5 | 6 | 6 |
1 | 2 | 3 | 5 | 6 | 6 |
Prospects for the future the suggesion or advice.
Or, using Analytics:
SQL> with test_data (id, one, two, three, four, five, six) as ( 2 select 1, 1 , null, 2 , 5, 6, null from dual union all 3 select 2, 1 , null, 3 , 5, 6, null from dual union all 4 select 3, 1 , null, null, 5, 6, null from dual union all 5 select 4, null, null, null, 5, 6, null from dual 6 ) 7 select * 8 from ( 9 select id 10 , cell 11 , case when next_nn is not null and prev_nn is not null 12 then (next_nn + prev_nn)/2 13 else nvl(next_nn, prev_nn) 14 end val 15 from ( 16 select id 17 , cell 18 , val 19 , last_value(val) ignore nulls over(partition by id order by cell) as prev_nn 20 , first_value(val) ignore nulls over(partition by id order by cell range between current row and unbounded following) as next_nn 21 from test_data 22 unpivot include nulls (val for cell in (one as 1, two as 2, three as 3, four as 4, five as 5, six as 6) ) 23 ) 24 ) 25 pivot ( min(val) for cell in (1 as "ONE", 2 as "TWO", 3 as "THREE", 4 as "FOUR", 5 as "FIVE", 6 as "SIX") ) 26 ; ID ONE TWO THREE FOUR FIVE SIX ---------- ---------- ---------- ---------- ---------- ---------- ---------- 1 1 1,5 2 5 6 6 2 1 2 3 5 6 6 3 1 3 3 5 6 6 4 5 5 5 5 6 6
Tags: Database
Similar Questions
-
Update on nulls in the column vs add column not null default 11 g
Hello
Let's take a scenario following 1. *
We have a large partitioned table LARGE_TABLE1 (say: NUM_ROWS 5 904 977 029, size GB 326) in the Oracle 11 database.
We want to add a new column NEW_COLUMN (NUMBER) and give a value of-999 to NEW_COLUMN each record in this table.
In Oracle 11 it would probably a second since the value of default -999 would be permanently added in metadata without updating each and every record 6 bln.ALTER TABLE LARGE_TABLE1 ADD (NEW_COLUMN NUMBER DEFAULT -999 NOT NULL);
Take a scenario 2 *
We have another large partitioned table LARGE_TABLE2 (of similar size as LARGE_TABLE1) in the Oracle 11 database.
We have an existing EXISTING_COLUMN (NUMBER) column that contains nulls 90% (90% of scores only contain null values in the field, and 10% of the scores only contain non-null values in this field)
I would like to replace null values in EXISTING_COLUMN with number - 999.
Update the column full Ascension not going :-) and doing so in a loop (the partition partition) would take a few days.
Question:
Do you know a way somehow write this -999 "overall" in the metadata as in scenario 1 instead of updating a null value in all the records to-999? No clever workaround solution would be appreciated...
Edited by: SwPiotr 2012-04-24 07:26ALTER TABLE LARGE_TABLE1 ADD NEW_COLUMN NUMBER GENERATED ALWAYS AS nvl(col1, -999);
-
Update a record of ORM, but with empty value
Hi all, excuse my poor English and my level of coldfusion poor
I have some problems to update the data with ORM objects.
(1) I have an object of customer with a task property (many-to-one relationships)
(2) I have a job object (a list of works)When I update a client with customerOBJ.setjob (jobOBJ); It is ok
But when I can't seem to restore an empty value for the job.
When I try this:
customerOBJ.setJob (), I have an error because the settings is not a type of employment
You have some information about this?
Thanks in advance.
Hi friend
This allows to obtain a value zero: javacast("null",'"")
That is why to delete the value:
customerOBJ.setJob (javacast("null",""));
That should make you well. If you use it in a few places, you can create yourself a function:
Then use:
customerOBJ.setJob (null);
-
Update multiple rows in a table with one value of another multiple
Using SQL Server
How this can be done:
In all the lines in the upper table PS_CA_BILL_PLAN, we want to update the field LAST_XREF_SEQ_NUM with the MAX (XREF_SEQ_NUM) + 1 of the bottom table
Where the CONTRACT_NUM and the BILL_PLAN_ID are equal
This SQL below (in green) works for one line only
I think it's the SQL code you're looking for:
UPDATE PS_CA_BILL_PLAN SET LAST_XREF_SEQ_NUM =
(SELECT MAX (XREF_SEQ_NUM) + PS_CA_BP_XREF 1 B)
WHERE B.CONTRACT_NUM = A.CONTRACT_NUM AND B.BILL_PLAN_ID = A.BILL_PLAN_ID)
-
Not Null on the column of a primary key constraint
I came across a table defined in the same way to...
create table t (t_id int constraint nn_t_id not null constraint pk_t primary, data key number);
Of course, the primary key is the is not null, then is there a reason to add the redundant constraint not null?There are two parts to your question, I think:
(1) why add a NOT NULL if a primary key is also reported.
(2) why is null is NOT a name defined by the user (in this case nn_t_id).1 > I think you are right: there is no difference in behavior in the way that Oracle is going to reject the creation of NULL in this column (whether through the direct insert or update with a NULL value). I personally always declares the NOT NULL for columns, I know to never have null, regardless of whether the column is (member of) a PK.
It's pretty funny, btw, the SQL standard as chosen able to be the NULL default value. I think that we all type much less, if the SQL standard chose NOT NULL default value. But that's another story.
2 > I don't see given nullability defined by the user of the explicit names now and then, because of some "coding guideline' which dictates that constraint names must never be generated System. This guideline is often presented as a result of the exception handling of "client-side", where the constraint name is filtered SQLERRM and then more personalized to be displayed to the end user. However for NOT NULL constraint violations, I think (does not fully to check) that you are always thrown an ORA-01400 is an ORA-01407. Who nowadays both will tell you exactly (in SQLERRM) which column of this table is currently in violation of a NOT NULL constraint.
Toon
-
Update of Table, summarizing the content of the separate column.
Hi all
Small update problem: -.
CREATE THE TABLE:
DATA: -.CREATE TABLE TestTab10 ( GROUPID VARCHAR2(10), ITEMS_1 NUMBER(2), ITEMS_2 NUMBER(2), ITEMS_3 NUMBER(2), TOT_ITEMS VARCHAR(50), SEQNO NUMBER(10) );
Select * from TestTab10;INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','13','','','123456'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','','16','','123457'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10002','','','','','123458'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123459'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123460'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123461'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','11','13','','','123462'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','12','','','123463'); INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','13','14','','123464');
Desired results: -.GROUPID ITEMS_1 ITEMS_2 ITEMS_3 TOT_ITEMS SEQNO ---------- ---------- ---------- ---------- -------------------------------------------------- ---------- 10001 12 13 123456 10001 12 16 123457 10002 123458 10003 13 123459 10003 13 123460 10003 13 123461 10004 11 13 123462 10004 12 123463 10004 13 14 123464
I need to update the Tot_items column with the number of distinct elements which is held within each groupid.GROUPID ITEMS_1 ITEMS_2 ITEMS_3 TOT_ITEMS SEQNO ---------- ---------- ---------- ---------- -------------------------------------------------- ---------- 10001 12 13 121316 123456 10001 12 16 121316 123457 10002 123458 10003 13 13 123459 10003 13 13 123460 10003 13 13 123461 10004 11 13 11131214 123462 10004 12 11131214 123463 10004 13 14 11131214 123464
The ideas people?
Thanks in advance.Lack OP wants ordered items:
merge into testtab10 a using ( with t as ( select rowid rid, listagg(items_1 || ',' || items_2 || ',' || items_3,',') within group (order by seqno) over(partition by groupid) items from testtab10 ) select rid, xmlquery( 'string-join(for $n in distinct-values(ora:tokenize($str,",")) order by xs:integer($n) return $n,",")' passing ',' || items as "str" returning content ) tot_items from t ) b on (a.rowid = b.rid) when matched then update set a.tot_items = b.tot_items / 9 rows merged. SQL> select * 2 from testtab10 3 / GROUPID ITEMS_1 ITEMS_2 ITEMS_3 TOT_ITEMS SEQNO ---------- ---------- ---------- ---------- -------------------- ---------- 10001 12 13 12,13,16 123456 10001 12 16 12,13,16 123457 10002 123458 10003 13 13 123459 10003 13 13 123460 10003 13 13 123461 10004 11 13 11,12,13,14 123462 10004 12 11,12,13,14 123463 10004 13 14 11,12,13,14 123464 9 rows selected. SQL>
SY.
-
Some columns of the values of the selected line returns NULL in the table of the adf.
Hello..
My version of jdev 11.1.1.5.0
I have a vision with some columns. This view is mapped to a table of adf with some of the displayed columns. My task is to get the column values selected line (including the values of the column not displayed).
But I'm certain values such as null, although there are values present when I run the query from the view.
My code:
DCIteratorBinding tableVO = ADFUtils.findIterator ("myVO");
ViewObject voTableData = tableVO.getViewObject ();
Line rowSelected = voTableData.getCurrentRow ();
+ / / codeto display column and the values +.
int x = 0;
* for (the names of the objects: rowSelected.getAttributeNames ()) {*}
* for (int i = x; i < rowSelected.getAttributeValues () .length; i ++) {*}
* System.out.println (x + "." + name + "=" + rowSelected.getAttribute (i)); *
break;
*}*
x ++ ;
continue;
*}*
MY table:
* < af:table value = "#{bindings.myVO.collectionModel}" *.
* var = "row" rows = "#{bindings.myVO.rangeSize}" *.
* EmptyText = "#{Bindings.myVO.Viewable?" "{'No data to display.': 'Access Denied.'}". *
* fetchSize = "#{Bindings.myVO.rangeSize}" *.
* rowBandingInterval = "0."
* filterModel = "#{Bindings.myVO.queryDescriptor}" *.
* queryListener = "#{Bindings.myVO.processQuery}" *.
* filterVisible = "true" varStatus = "vs."
* selectionListener = "#{myBean.method_onRowSelect}" *.
* rowSelection = "single" id = "t1" styleClass = "AFStretchWidth."
"* partialTriggers =": sbcClose: sbcOpen: socWarehouse. "
* inlineStyle = "height: 217px;" / > *.
Thank youQuestion: the attributes are not null in the DB?
The attributes are part of the past of the query select?
And they are part of the binding of the tree?Timo
-
What SYS (or tables) store the value of a spec /not/ NULL columns? (It doesn't seem to be COL$)
NOTE: This is NOT a trick question - although it seems to be.
Test configuration:
Test configuration:BANNER Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
1. a table is created by SCOTT in the SCOTT schema with a NULLABLE column.
2. a primary key constraint is added using only the NULLABLE column
3. Requests for information on USER_TAB_COLS, ALL_TAB_COLS, DBA_TAB_COLS and SYS. COL$ see NOT NULL for the column NULLABLE
as necessary for a primary key constraint. Views derive their data from the column of $ NULL the sys. Table of $ COL
using
and the table of $ COL shows a numerical value of '0' before you add the primary key and a value of "1" later.'DECODE (SIGN (c.null$), -1, 'D', 0, 'Y', 'N'),
4. a query on the DDL metadata table shows the specification for column NULLABLE of origin involved.
Question - where this original specification NULLABLE is stored?
This question is based on a question asked by another user in this thread
Columns becoming nullable after a fall of primary key?
I created the following specially for that matter test case
The DOF shows that Oracle keeps the original spec NULLABLE for the column and uses it to generate the DDL orginal, even if there is a primary key on the table and the system views (and COL$) show the column non NULLABLE.-- scott ensures table does not exist DROP TABLE tbl_test CASCADE CONSTRAINTS; -- scott creates a table CREATE TABLE tbl_test ( col_1 NUMBER, col_2 NUMBER NOT NULL); -- scott queries to check the the column nullable status SELECT table_name, column_name, nullable FROM user_tab_cols WHERE table_name = 'TBL_TEST'; -- TABLE_NAME | COLUMN_NAME | NULLABLE -- TBL_TEST | COL_1 | Y -- TBL_TEST | COL_2 | N -- Scott addes a primary key constraint using only the nullable column ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1); -- scott queries to check the the column nullable status SELECT table_name, column_name, nullable FROM user_tab_cols WHERE table_name = 'TBL_TEST'; TABLE_NAME,COLUMN_NAME,NULLABLE TBL_TEST,COL_1,N TBL_TEST,COL_2,N -- scott queries to get the table DDL select dbms_metadata.get_ddl('TABLE', 'TBL_TEST', 'SCOTT') FROM DUAL; DBMS_METADATA.GET_DDL('TABLE','TBL_TEST','SCOTT') CREATE TABLE "SCOTT"."TBL_TEST" ( "COL_1" NUMBER, <------ where is this NULLABLE spec stored? "COL_2" NUMBER NOT NULL ENABLE, CONSTRAINT "TBL_TEST_PK" PRIMARY KEY ("COL_1") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOCOMPRESS LOGGING TABLESPACE "USERS" ENABLE ) SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE "USERS"
So where is the original information NULLABLE actually stored?rp0428 wrote:
What SYS (or tables) store the value of a spec /not/ NULL columns? (It doesn't seem to be COL$)I think that it becomes a bit messy depending on order of activity:
You can see Col. .null$ is set to a non-zero when the desrcibe command displays the column as not null, but it can happen for two reasons:
(a) user sets the column as not null - in which case you get a line in cdef$ with type # = 7
(b) the user adds a primary key to table - in which case you get a line in cdef$ with type # = 2If you declare null AND add a primary key, you get two lines - that's why it is possible for Oracle to determine if he should remove the flag not null when you remove the primary key and also allows dbms_metadata show the create statement of table without a NOT NULL even when describe it the watch with a NOT NULL - dbms_metadata can respond to the presence of the type # = 2 and absence of the type # = 7.
Concerning
Jonathan LewisBy the way: by a strange coincidence, it seems to me answering the previous post, three days before it was asked: http://jonathanlewis.wordpress.com/2012/04/19/drop-constraint/#comment-46140 (on the doubts, this isn't - it answers a different question on the removal of constraints).
Published by: Jonathan Lewis April 23, 2012 11:07
-
I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?
Add two new columns after than the original with space separated values column.
Select cell B1 and type (or copy and paste it here) the formula:
= IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
shortcut for this is:
B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")
or
the formula of the C1 could also be:
= IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")
Select cells B1 and C1, copy
Select cells B1 at the end of the C column, paste
-
I tried firefox update, but it is not compatible with leopard op. If I try to re - install the old version my favorites will always be there?
Yes. This should not be a problem.
-
I don't like updates of firefox, trying to be more and better than the competition, I get it. However, each update is incompatible with Java 100% and where people who work together and makes these updates are not aware, the world wide web all use Java. Why would anyone want to use firefox, when they can't even use the internet?
JavaScript is not Java, as said and JavaScript is part of Firefox, so nothing to update.
Regarding the Flash go to http://www.adobe.com/software/flash/about/ to see if it detects and if you have the latest version.
The https://www.mozilla.org/en-US/plugincheck/ is underway while the
https://www-trunk.stage.Mozilla.com/en-us/plugincheck/ suggested that the post above is not to update the flash plugin. -
my phone does not work after last update itunes on my phone connection with my pc, it shows only i tunes icon and the application of itune on my pc does not work
For general advice, see troubleshooting problems with iTunes for Windows updates.
The steps described in the second case are a guide to remove everything related to iTunes and then rebuild what is often a good starting point, unless the symptoms indicate a more specific approach.
Review the other boxes and other support documents list to the bottom of the page, in case one of them applies.
More information area has direct links with the current and recent buildings if you have problems to download, must revert to an older version or want to try the version of iTunes for Windows (64-bit-for old video cards) as a workaround for problems with installation or operation, or compatibility with QuickTime software or a third party.
Backups of your library and device should be affected by these measures but there are links to backup and recovery advice there.
Once iTunes to work properly, you should be able to fix your device.
TT2
-
Having a problem with the update of the window. He said that windows could not search for new updates. It's the found error 80245003 code
Take a look at this article as it addresses this error code. Mike - Engineer Support Microsoft Answers
Visit our Microsoft answers feedback Forum and let us know what you think. -
Remember - this is a public forum so never post private information such as numbers of mail or telephone!
CODE 66 has when the update NET FRAMEWORK 4 with WINDOWS UPDATE can't update more far until the issue is resolved. Help, please... I almost tried everything. Ideas:
- You have problems with programs
- Error messages
- Recent changes to your computer
- What you have already tried to solve the problem
Take a look at this link and see if it helps-
http://social.answers.Microsoft.com/forums/en-us/vistawu/thread/3adefda0-69f3-4075-96ee-e2c61bd599cc>
-
On a m950y of HP with AMD Phenom Quad Core processor 2.4 GHz, 8 GB of RAM, lots of available hard disk space, accepted the software license agreement. Can you tell me what's happening, if this should be fixed, and how it can be fixed?
Mike-
UH! After posting the added information in my last post, I have acted on an intuition, uninstalled, Office Live 1.5 from the Control Panel, rebooted, reinstalled and everything went well.
So I guess there's a glitch somewhere where Windows Live Update thought I needed the upgrade while in fact I have not, and he is involved in a problem that cannot be resolved.
Thank you for your help.
Bill
Maybe you are looking for
-
iMac 24 "early 2009. 4 GB of RAM to 8 GB upgrade?
I have an Apple iMac 24 "early 2009, 2.66 GHz Intel Core 2Duo, NVIDIA GeForce 9400 256 MB. Memory 4 GB 1067 MHz DDR3, but I would like to upgrade. I just install OS X El Capitan and having been informed that a RAM upgrade is a good idea? Eager 2 x
-
Satellite U840T - mouse disappears on the right of the screen and down
I have a problem with my Satellite U840T screen The mouse disappears on the right of the screen and the background in the black bars at the top and then the left side of the mouse cannot go to bars. In the display settings, everything is good, I thin
-
Can I insert disc HARD 160 GB in Satellite U200-181
Dear friends!If I insert disc HARD 160 GB laptop Toshiba U200-181?Version 3.40 BIOS Thank you!
-
Why Apple TV 4 will not upload my pictures?
For several months now, my Apple TV 2 (a new one) has not uploaded any new photos that are uploaded to iCloud. At one point, I could see a few photos in albums shared, but lately it does not display anything. He will show me the names of shared album
-
ProBook 4530 s: need to Win 7 Home premium 64-bit USB controller driver
HelloI need Win 7 64 bit USB controller driver. This problem was detected on my Probook s 4530 by Microsoft.The printer has no connection, so I can't print.Thank you.Earlier, everything was ok, but as a first step, I installed win 10 and did not work