Swivel data insertion
Greetings,
version: 11.2.0.2
Test case-
create the table TEST_S
(number of req_id,
number of comment_id,
Comments varchar2 (2000));
Insert into TEST_S values (1, 20, ' it's comment #1, id #1 "');
Insert into TEST_S values (2, 10, ' it's comment #1, id #2 "');
Insert into TEST_S values (2, 20, ' it's comment #2, id #2 "');
insert into TEST_S values (2, 100, "this is the comment #3, id #2" ');
Insert into TEST_S values (3, 15, ' this is comment #1, id #3 "');
Insert into TEST_S values (3, 25, "comment #2, id #3" ');
Insert into TEST_S values (3, 16, "this is comment #3, id #3" ');
Insert into TEST_S values (3, 25, "comment #4, id #3" '); -req_id can have same comment_id
Insert into TEST_S values (8, 9, ' it's comment #1, id #8 "');
commit;
;
I need to rotate and insert the data of this table TEST_S in TEST_D:
create the table TEST_D
(number of req_id,
COMMENT1 varchar2 (2000).
VARCHAR2 (2000) comment2,.
comment3 varchar2 (2000).
VARCHAR2 (2000) comment4,.
comment5 varchar2 (2000));
...
and rotated once the result should be:
req_id | COMMENT1 | comment2 | comment3 | comment4 | comment5 |
---|---|---|---|---|---|
1 | It comes to comment #1, id #1 | ||||
2 | It comes to comment #1, id #2 | It comes to comment #2, id #2 | It is observation #3, id #2 | ||
3 | It comes to comment #1, id #3 | It comes to comment #2, id #3 | It is observation #3, id #3 | It comes to comment #4, id #3 | |
8 | It comes to comment #1, id #8 |
- and my attempt...
DECLARE
CURSOR C2
IS
SELECT req_id,
comment_id,
Comments
OF TEST_S
order by 1, 2;
Id1 c2% ROWTYPE;
Id2 c2% ROWTYPE;
ID3 c2% ROWTYPE;
ID4 c2% ROWTYPE;
ID5 c2% ROWTYPE;
BEGIN
FOR THE ID IN
(SELECT DISTINCT FROM TEST_S ORDER BY req_id req_id
)
LOOP
OPEN C2;
Get c2 INTO id1;
Get c2 INTO id2;
Get c2 INTO id3;
Get c2 INTO id4.
Get INTO id5 c2;
CLOSE C2;
INSERT INTO test_D
SELECT id.req_id,
MAX)
CASE
WHEN comment_id = id1.comment_id
THEN the comments
END) AS comment1,.
MAX)
CASE
WHEN comment_id = id2.comment_id
THEN the comments
END) AS comment2,.
MAX)
CASE
WHEN comment_id = id3.comment_id
THEN the comments
END) AS comment3,.
MAX)
CASE
WHEN comment_id = id4.comment_id
THEN the comments
END) AS comment4,.
MAX)
CASE
WHEN comment_id = id5.comment_id
THEN the comments
END) AS comment5
OF TEST_S
WHERE req_id = id.req_id
GROUP BY id.req_id;
END LOOP;
END;
... but the result is:
REQ_ID | COMMENT1 | COMMENT2 | COMMENT3 | COMMENT4 | COMMENT5 |
---|---|---|---|---|---|
1 | It comes to comment #1, id #1 | It comes to comment #1, id #1 | |||
2 | It comes to comment #2, id #2 | It comes to comment #1, id #2 | It comes to comment #2, id #2 | It is observation #3, id #2 | |
3 | It comes to comment #1, id #3 | ||||
8 |
What I am doing wrong? or is there a better approach?
Actually, "TEST_S" has 453K lines, 178K distinct "req_id" and each "req_id" has between 1 and 24 'comment_id '.
'TEST_S' can contain up to 16 comments / 'comment_id '. If there is more than 16 'comment_id' for a 'req_id"then the rest of the s 'comment_id' goes to a
another table (that is another story).
Thanks for your time,
T
Hello
Here's one way:
INSERT INTO test_d (req_id comment1, comment2, comment3, comment4, comment5
-..., comment16 - according to needs
)
WITH got_r_num AS
(
SELECT req_id, comments
ROW_NUMBER () OVER (PARTITION BY req_id
ORDER BY reviews - or what you want
) AS r_num
OF test_s
)
SELECT *.
OF got_r_num
PIVOT (MIN (comments)
FOR r_num IN (1 AS comment1
2 AS comment2
3 AS comment3
4 AS comment4
5 AS comment5
-..., 16 AS a comment16 - according to needs
)
)
;
You can add as many columns comment more at your leisure. Just add them to the list of columns at the beginning and the PIVOT clause at the end; nothing else in the statement must change.
If you have more comments 5 (or 16 or another) for the same req_id, then those extra will be simply ignored. no error.
I guess that you replicate the data to display only, as in a data warehouse. For most purposes, including where you might need to look in the comments, the structure of the test_s table is much better than test_d.
Tags: Database
Similar Questions
-
How to find - including the table - the data insertion
Hi all
We have oracle 10g need to table name which records the last "data inserted the name of the table.
Any help on this query,
Thank you
My understanding is correct
1 sales man Insert customer details
2. this information is stored in a DB with 200 + tables
3. sales manager need a report for review and approve the details of the customer entered by sales man.
4. you are asked to prepare this report
5. you have no idea of what are the paintings to study to get information
If this is true the correct way is the look in the design of your application document.
-
Data insertion Smartphones blackBerry 9900 if unable to restore
I have 9700 to 9900 upgrade I have several insertions 922, impossible to restore in the 9900.
Thank you
If you have a backup of the 9700, you can return the Desktop software > device > restore > select the appropriate to the 9700 backup file, select data (not full restoration) > select ONLY the automatic and continuous integration database.
-
I m using the detailed form master and I m off the sup_rec_no in the main table bcz and I m using the trigger in the database backend
but problem is when I click on the Insert button of data detail cannot be inserted
You control the order of your rows.after post by inserting the master line, you need to get the lines PK masters and ti value line details.
Read the doc to http://docs.oracle.com/cd/E23943_01/web.1111/b31974/bcadveo.htm#ADFFD1149 , which describes how to do this.
Timo
-
Date inserted to save updates on case sensitive when I record!
OK, so the question, I go to the Insert menu, choose the date and click on 'update automatically on save', but when I save it, it breaks.
Here are the screenshots illustrating the issue.
Front
After
I've looked everywhere for a solution without success, it's really frustrating me, especially that it is supposed to be for one of my college papers, not only the code breaks when I save, but I need also a way to put in shape the "thing", considering that when I insert it before saving it, I can not format the text 'copyright' in the second photo in mach.
Anyway, help would be appreciated and thank you for taking your time to read and possibly to resolve this dilemma.
Why not use a
tag for your paragraph text? SPAN tags have no semantic meaning.
INSERT YOUR DATE HERE...
Nancy O.
-
Logging what data inserted in the outer table
Hello
We load a large number of data using external tables and inserts into tables partitioned by day nor the hour.
Other parts of the system want to know what partitions have been updated and when, so before load us all the data, we make a
That's when inserting into partitions of day, IE get all separate days of that specific file.insert into new_data(date_of_event) values (select distinct(trunc(date_of_event) from external_table)
These files, however, can be very substantial and after this first analysis, we do a full insertion in to the correct data table, that is, read the entire file again.
So my question is, is there another (better) way to retrieve the different days/times? A way to make the effective insertion in the table of data and information on which partitions Oracle inserted data into any dictionary etc.?
Haven't tried creating a 'good' temp-table, insert the data into it, extraction of dates and then inserting to the actual data table. But then, what is the best, creating a table and a fall or read the file twice?
Thanks in advanceYou don't say how you are querying and inserting, but if you have a control on a few possibilities come to mind.
1. use INSERT ALL make a multi-table insert. Insert the "date_of_event" into a new "Journal" table and insert data to the table that you insert now.
Then you can make the separate (trunc (date_of_event) "select" on the new table of newspaper. Just truncate the new log table before each query or add a column that contains the file that was imported.2. create a VIEW that includes all the columns in your current query and another copy of "date_of_event" and peel the date of the event in another table.
Option #1 is the simplest.
See ALL INSERT in SQL Reference: http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9014.htm
-
data insert a problem...
I am creating a table type nested and used in a type of table column after that I want to insert data in the table... but there is an occurred.when problem I am executing the insert view ',' missing...
Insert a statement like that...
INSERT INTO TAB_EMPLOYEE_DTL
(EMP_ID,
EMP_CODE,
EMP_NAME,
SEX,
Date of birth
NT_EMP_ADDRESS (TY_EMP_ADDRESS (ADD_LINE_1,
ADD_LINE_2,
DISTRICE,
PIN_NUBER,
STATE)))
VALUES
(1,
"a01",.
"Patricia."
'.
To_date (10-mar-87', 'dd-MON-rr'),
NT_EMP_ADDRESS (TY_EMP_ADDRESS ('a', 'sss', 'wer', 561234, "UP")));You must provide a column name to «*»
and also delete
NT_EMP_ADDRESS(TY_EMP_ADDRESS(ADD_LINE_1,ADD_LINE_2,DISTRICE,PIN_NUBER,STATE)
and replace it with a column name
Published by: bluefrog August 22, 2011 17:02
-
I WANT THE RESULT OF MY FORM PAGE TO INSERT A FORM OF UPDATE OF THE DATA INSERTED JUST
I WANT THE RESULT OF MY FORM PAGE TO INSERT A FORM OF UPDATE OF THE MEASURE WITH THE HELP OF JUST INSERTED DATA. PLS HELP FOR EXAMPLE. Thank you
It doesn´t works because the to-be-set record´s to update primary key cannot be determined by using a static value:
$upd_capital-> setPrimaryKey ("cap_id", "NUMERIC_TYPE", "VALUE", "new_id"); current code in page 2
Basic now needs to ensure that the primary key matches the Session Variable "new_id' thus:
See you soon,.
Günter
-
Third issue of the day, I know I'm breaking all records.
Try to insert the date below to db;
I get the following error;to_date('2010/05/27 4:52:02 PM', 'yyyy/mm/dd hh12:mi:ss'))
Also I tried not to change to hh24 hh12 no chance.ORA-01830: date format picture ends before converting entire input string
I followed this tutorial:
[http://www.techonthenet.com/oracle/questions/insert_date.php | http://www.techonthenet.com/oracle/questions/insert_date.php]
I left for the day but will come back tomorrow and check this.
Thank you so much as always.The chain has PM, so you must use the appropriate format, IE;
to_date('2010/05/27 4:52:02 PM', 'yyyy/mm/dd hh:mi:ss am')
-
Loading is successful ODI but data inserted is 0
Hi John,.
I tried to push data from sql to Hyperion. It has worked well. But the number of inserted rows is 0... Pleae suggestAll I can say is that you must be able to run the same query that ODI creates then you can check if joins are correct.
ODI just generates the SQL code and then happened to the Java API to load into essbase, if the SQL produces no result then it will not be loaded into essbase.
You might be getting string is too long if you load values in a column that are longer than the length of the column.
See you soon
John
http://John-Goodwin.blogspot.com/ -
2 blocks from the database data insert into the same base table?
Hello
I have the C_NEW canvas. On this canvas, elements of 3 blocks are usable by the user.
1 block NEW_HEAD: 3 Articles say X 1, X 2, X 3
2 block NEW: record multi say Y1 thru Y10 text fields. Also a scroll bar.
3 block NEW_ACTION: 6 buttons say B1 to B6 (one of them is N_OK which matches the element in question)
two NEW, NEW_HEAD blocks are blocks of db and have the same basic so-called BT table when users click on the N_OK (after filling the data in the NEW_HEAD and then NEW block in that order), I need the data between the two the NEW, NEW_HEAD to enter the BT. currently only the NEW data goes to BT. in the BT table fields that correspond to the fields X 1, X 2, X 3 in the NEW_HEAD remains null after clicking on the N_OK button. I put commit_form in the N_OK code, since the blocks are blocks of db (as suggested by the people, it is easier to issue a commit_form that a lot more work in writing my own SQL).
How can I achieve this?
Thank you
ChiruThere is therefore no N_LC_DMG_ALLOW column in the table, that the block is the result. You must set the property "Section of the database" not for all the elements that are not of the columns in your database table.
And when an error occurs, then the full treatment stops, so its clear that there is no inserted record.
-
SELECT the data inserted into a global temporary Table in a stored proc
A stored procedure is run from Oracle SQL Developer to insert data into a global temporary table. A SQL (in Oracle SQL Developer) worksheet is open to run a SELECT query to retrieve the data from the temporary table overall which was populated in the stored procedure. No row is returned. I guess it's because the stored procedure and the SELECT statement executed in different sessions.
Is it possible to run the stored procedure in Oracle SQL Developer and then execute a select statement on the temporary table overall which was filled in the stored procedure by using the same connection so that the data can be extracted?
I use version 1.5.1 build HAND-5440 of Oracle SQL Developer.In a worksheet, do something like
Start
insert_proc;
end;Select * from my_temp_table;
Place the cursor on each statement in turn and Press f9 (where it all began... the end is a single statement.
-
Hello
I use jdeveloper 11.1.1.7
I have a few inputText in my user interface.
I have inserted several values in them.
When I want to insert a new value, Which suggest me some old values
but I don't want his suggestion . I want to clear the history of the user interface of the values inserted.
How can I delete it?
Thank you
Hello
You can disable the components individually add the attribute "AutoComplete":
To disable all form elements, consult the following article:
https://blogs.Oracle.com/jdevotnharvest/entry/disabling_the_browser_form_auto
RFH.
-
Oracle of data insertion error
Hi all
I pulled the following create statement in Oracle database
CREATE TABLE S_ETL_DAY)
Stamp DAY_DT,
CAL_MONTH int,
Int jour_du_mois,
DAY_NAME char (12),
Int DAY_OF_YEAR,
Int DAY_OF_WEEK,
CAL_WEEK int,
MONTH_NAME char (15),
CAL_YEAR int,
PER_NAME_MONTH varchar (50),
PER_NAME_QTR varchar (20),
FSCL_YEAR int,
FSCL_QTR char (5),
Stamp DAY_AGO_DT,
Stamp WEEK_AGO_DT,
Stamp MONTH_AGO_DT,
Stamp QUARTER_AGO_DT,
Stamp YEAR_AGO_DT,
ROW_WID int
)
;
and then if I get the statement
INSERT INTO S_ETL_DAY VALUES (timestamp('1980-01-01-00.00.00'), 1, 1, "Tuesday", 1, 3, 1, 'January', 1980, '198001', '1980 Q 1', 1980, "Q3", NULL, NULL, NULL, NULL, NULL, 19800101);
its shows error
Error at startup on line 28 of the command:
INSERT INTO S_ETL_DAY VALUES (timestamp('1980-01-01-00.00.00'), 1, 1, "Tuesday", 1, 3, 1, 'January', 1980, '198001', '1980 Q 1', 1980, "Q3", NULL, NULL, NULL, NULL, NULL, 19800101)
Error in the command line column: 28:29
Error report:
SQL error: ORA-22803: object type contains the attributes of zero
22803 00000 - "object type contains zero attributes.
* Cause: An attempt was made to create or specify a column or a constructor
of a type of object which has no attributes. Only object types
who have at least one attribute are allowed in this context.
* Action: specify a valid object type
I googled a lot about this error, but in vain.
can someone help me why this is the case?
Thank you
BivinTO_TIMESTAMP (February 27, 2002 15:51.12.539880 ',' dd/mm/yyyy hh24:mi.ss.ff')
INSERT INTO S_ETL_DAY VALUES(to_timestamp('27/02/2002 15:51.12.539880', 'dd/mm/yyyy hh24:mi.ss.ff'), 1, 1, 'Tuesday', 1, 3, 1, 'January', 1980, '198001', '1980Q1', 1980, 'Q3', NULL, NULL, NULL, NULL, NULL, 19800101 );
-
Connection from Oracle to DB2 LUW and Asian data insertion/selection.
Hello
I have configured the connectivity between Oracle and DB2 LUW, using DG40DBC but my requirement is to see the characters Asian (Chinese, Japanese, etc). Then, when I select the data through DB DB2 link I get of the question marks (?). We need to change the settings in the configuration files to support this language?
Any help is very appreciated!
Thank you
Steve.Isql instruction is not able to display characters unicode is partly justified. In my (Linux with LANG value UTF8) env it displays Chinese and Japanese characters.
You can also try to use the unicode equivalent to "isql" called "iusql. In addition, please provide the character set of your DB2 database.
Published by: kgronau on January 16, 2012 06:31
Also DG4ODBC displays correctly using your ODBC from above and these DG4ODBC settings:
HS_FDS_SHAREABLE_NAME =/home/odbc64/unixODBC/2.3/lib/libodbc.so
HS_NLS_NCHAR = UCS2
HS_LANGUAGE = AMERICAN_AMERICA. AL32UTF8For a DB2 database using this character set parameter:
Database code page = 1208
Database of codeset = UTF - 8
Maybe you are looking for
-
It was on my laptop - it entered the password on his own voliton but do not write it down. I want to control my laptop - can I get a permission to change password please.
-
Cannot use acoustic silent software on my WXP Tecra A8
Hello I'm on a Toshiba Tecra A8 (PTA83E). I lowered the from VISTA to XP.My problem is that I can't get the DVD drive in quiet mode. I have the silent acoustic software installed, click on the ' Mode silencer Set "but this cooler keeps the DVD player
-
Windows 8 Probook 4530 s chipset drivers
Hello support HP Forum! I have laptop Base model. I want to switch to Windows 8, Windows 7, but in the drivers section it is not CHIPSET DRIVERS! (NOT IN x 64, x 86) Windows 8 must drivers Chipset? And what is my Probook s 4530 will bring them? It wi
-
Error ox80072751 when you try to update to BioShock 2
Error ox80072751 when you try to update of BioShock 2 (Steam bought) I tried to install the most recent GFWL, PC rebooted, signed in to GFWL with old or newly created account. Installed all the updates of Windows currently needed. Tried again above.
-
Standard user account to log on to the question. Cannot open a session
Can anyone help. I have an account administrator and standard user for my kids two accounts. Something seems to have gone wrong. I have no problem to logon as administrator, but when my kids are trying to connect to their accounts using their passwor