Model data update - need to insert records
I have a data model that needs to be updated (at least the correspondence table must be changed and the base table must be updated as well).
The base table looks like this:
Original painting | |||
ID_PK | ID_FK | ID_DATE | EMP_ID |
1 | 100 | 1 sep-14 | 5900 |
2 | 200 |
February 1, 14
5900
3
300
1 January 14
5900
4
400
1 January 14
5900
5
500
1 January 14
5900
The fact ID_FK column refers to a lookup table that needs to be updated. The ID of 100 and 200 are eliminated and now refers to different IDS. ID_FK 100 actually equals 300 and 400. So for each record with ID 100, 2 records must be inserted in the table. a folder for 300 and a record for 400, with all other information in the record (in this case ID_DATE and EMP_ID). It's the same story for 200 ID_FK. For each record with a FK_ID of 200, 2 records must be inserted in the table. a folder for 300 and a record for 400.
It's the final product expected to the base table:
EXPECTED Final product | |||
ID_PK | ID_FK | ID_DATE | EMP_ID |
3 | 300 | 1 January 14 | 5900 |
4 |
400
1 January 14
5900
5
500
1 January 14
5900
6
300
1 sep-14
5900
A ID_FK 100
7
400
1 sep-14
5900
8
300
February 1, 14
5900
AT ID_FK 200
9
400
February 1, 14
5900
I don't know how to build the UPDATE statement. Any advice?
Thank you
Aqua
SQL> create table a 2 as 3 ( 4 select 100 id_pk 5 from dual union all 6 select 200 id_pk 7 from dual union all 8 select 300 id_pk 9 from dual union all 10 select 400 id_pk 11 from dual union all 12 select 500 id_pk 13 from dual 14 ); Table created. SQL> create table b 2 as 3 ( 4 select 1 id_pk, 100 id_fk, to_date('1-Sep-14', 'dd-mon-rr') id_date, 5900 emp_id 5 from dual union all 6 select 2 id_pk, 200 id_fk, to_date('1-Feb-14', 'dd-mon-rr') id_date, 5900 emp_id 7 from dual union all 8 select 3 id_pk, 300 id_fk, to_date('1-Jan-14', 'dd-mon-rr') id_date, 5900 emp_id 9 from dual union all 10 select 4 id_pk, 400 id_fk, to_date('1-Jan-14', 'dd-mon-rr') id_date, 5900 emp_id 11 from dual union all 12 select 5 id_pk, 500 id_fk, to_date('1-Jan-14', 'dd-mon-rr') id_date, 5900 emp_id 13 from dual 14 ); Table created. SQL> alter table a add constraint a_pk primary key(id_pk); Table altered. SQL> alter table b add constraint b_pk primary key(id_pk); Table altered. SQL> alter table b add constraint b_fk foreign key (id_fk) references a; Table altered. SQL> create sequence b_id_pk_seq start with 6; Sequence created. SQL> insert into b 2 ( 3 id_pk 4 , id_fk 5 , id_date 6 , emp_id 7 ) 8 select b_id_pk_seq.nextval 9 , id_fk 10 , id_date 11 , emp_id 12 from ( 13 select x.id_fk 14 , b.id_date 15 , b.emp_id 16 from b 17 cross 18 join ( 19 select 300 id_fk from dual union all 20 select 400 id_fk from dual 21 ) x 22 where b.id_fk in (100, 200) 23 order 24 by b.id_fk 25 , x.id_fk 26 ); 4 rows created. SQL> delete from b where id_fk in (100, 200); 2 rows deleted. SQL> select * from b; ID_PK ID_FK ID_DATE EMP_ID ---------- ---------- -------- ---------- 3 300 01-01-14 5900 4 400 01-01-14 5900 5 500 01-01-14 5900 6 300 01-09-14 5900 7 400 01-09-14 5900 8 300 01-02-14 5900 9 400 01-02-14 5900 7 rows selected.
Tags: Database
Similar Questions
-
CS3 breaks date format in MS Access on insert record
It's strange.
I worked on one of my old sites, built in MX 2004. After updating the record insertion on the page using CS3 behavior, I noticed that my date fields are messy. My LCID is set to 2057 UK date (dd/mm/yyyy) format, but it is now getting back to mm/dd/yyyy.
I recall it being a 'Date, MS Access' option in the ' submit under "fall down on the insert record behavior MX 2004, but this seems to be missing.
I have nothing on the output allows to reverse the change, so now my old disks display dates in the correct format, and new records have the wrong date on them.
And of course, you don't notice this error before the 12th of the month, after which the system can decide who should be the month.
So my clients resonate me up to two weeks after that day to tell me that their application is broken. Arrgh.
Is there an extension for this problem / add the necessaru to the insertion of a plug or someone behavior at - it a snippet of code that works?
Is this something a bug in CS3?OK, I found a solution quick and dirty, which is basically does not submit the field as a date.
I found that I needed to change this line of code:
Quote:
MM_editCmd.parameters.Append MM_editCmd.CreateParameter ("param5", 135, 1, -1, MM_IIF (UploadFormRequest ("article_date_updated"), UploadFormRequest ("article_date_updated"), null)) ' adDBTimeStampwith this:
Quote:
MM_editCmd.parameters.Append MM_editCmd.CreateParameter ("param5", 202, 1, 150, MM_IIF (UploadFormRequest ("article_date_updated"), UploadFormRequest ("article_date_updated"), null)) ' adDBTimeStampThe difference being these settings: "135, 1, - 1" becomes "202, 1, 150".»
I don't understand what these are (can't find a reference for them), but the third should be the length of the string, the first of the type of data (e.g. variable text, number, date) and one in the Middle, unsure, whether his need maybe?
If the first of these parameters can be set for the exact date, it would be the right solution, but I don't know if this is possible.
Anyway, the work around is OK - condition that there is sufficient validation on the form to choose the invalid date formats.
-
Need to insert test data in all the tables that were present in a schema
Hello
I use Oracle 9i.
10 tables were present in my current schema. All tables are not having all the records.
I need to insert test data in each table using a single procedure. (the table name is inparameter for the procedure)
For example, I test_emp, test_sal tables.
CREATE TABLE test_emp (ename varchar2 (40), number of sal);
CREATE TABLE test_sal (it NUMBER, rank NUMBER, will designate the NUMBER);
I need to insert some test data in these tables. I shouldn't use utl_file or sql * loader for this.
I tried below way.
I am not able to transmit these values to the collection dynamically to the INSERT statement. I tried many ways, but I am not satisfied with the code I've written.-- Incomplete code CREATE OR REPLACE PROCEDURE test_proc_insertdata(p_table_name IN VARCHAR2) IS BEGIN --Selected all the column_names, data_type, data_length into a collection variable from user_tab_columns. SELECT u.column_name, u.data_type, u.data_length --BULK COLLECT INTO l_col_tab FROM user_tab_columns u WHERE u.table_name = p_table_name; -- generated the values using below statement SELECT decode(u.DATA_TYPE,'VARCHAR2',dbms_random.string('A', u.data_length),'NUMBER',TRUNC(dbms_random.value(1, 5000)),'DATE',SYSDATE) val_list -- INTO collection varaible FROM user_tab_columns u WHERE TABLE_NAME = p_table_name; END;
Please help me if you know a better idea.
Thank you
SuriSuri wrote:
HelloI use Oracle 9i.
10 tables were present in my current schema. All tables are not having all the records.
I need to insert test data in each table using a single procedure. (the table name is inparameter for the procedure)
For example, I test_emp, test_sal tables.
CREATE TABLE test_emp (ename varchar2 (40), number of sal);
CREATE TABLE test_sal (it NUMBER, rank NUMBER, will designate the NUMBER);I need to insert some test data in these tables. I shouldn't use utl_file or sql * loader for this.
I tried below way.
-- Incomplete code CREATE OR REPLACE PROCEDURE test_proc_insertdata(p_table_name IN VARCHAR2) IS BEGIN --Selected all the column_names, data_type, data_length into a collection variable from user_tab_columns. SELECT u.column_name, u.data_type, u.data_length --BULK COLLECT INTO l_col_tab FROM user_tab_columns u WHERE u.table_name = p_table_name; -- generated the values using below statement SELECT decode(u.DATA_TYPE,'VARCHAR2',dbms_random.string('A', u.data_length),'NUMBER',TRUNC(dbms_random.value(1, 5000)),'DATE',SYSDATE) val_list -- INTO collection varaible FROM user_tab_columns u WHERE TABLE_NAME = p_table_name; END;
I am not able to transmit these values to the collection dynamically to the INSERT statement. I tried many ways, but I am not satisfied with the code I've written.
Please help me if you know a better idea.
Thank you
SuriWith some effort, you can write dynamic insert queries. Read the data dictionary views ALL_TABLES and ALL_TAB_COLUMNS to get the data you need. You may need to limit the list to the tables you specify to hardcode the names of the tables. You can read the views for the information of table and column that you need generate the insert column orders. It will be a lot of work and it might be easier to simply hardcode values. Dynamic SQL is difficult to debug and work with: (.) Something like this (untested and totally undebugged)
declare cursor v_tab_col(p_table_name) is select * from all_tab_columns where table_name = p_table_name; v_text varchar2(32767); v_table_name varchar2(30); begin v_table_name := 'DUAL'; --chr(10) is a newline for readability when debugging v_text := 'insert into '||v_table_name||chr(10)||'('; --loop to build column list for v_tab_rec in v_tab_col loop --add comma if not first item in list if v_tab_col%rowcount > 1 then v_text := v_text ||','; end if; v_text := v_text || v_tab_rec.column_name; end loop; v_text := v_text ||') values ('|| --loop to build column values for v_tab_rec in v_tab_cur loop if (v_tab_rec.datatype = 'VARCHAR2') then --add comma if not first item in list if v_tab_col%rowcount > 1 then v_text := v_text ||','; end if; if v_tab_rec.datatype = 'NUMBER' then v_text := v_text || '9'; elsif v_tab_rec.datatype = 'VARCHAR2' then v_text := v_text ||'X'; end if; end loop; v_text := v_text || ')'; execute immediate v_text; end;
This code is not effective, but shows how to do what you described. You'll have to code for all data types you need and find a way to take into account the primary/foreign keys, yourself. I leave it to you to find a way to avoid selecting the data twice ;)
Good luck!Published by: riedelme on July 24, 2012 13:58
-
Due to a hard drive crash, I had to reformat my hard drive,
therefore lost my copy previous update of MS Money.
I reloaded the software from the CD, but it does not automatically download the update needed to read my existing data files.
Can someone help me read my old data files?Microsoft or anyone have made available as a patch to download?
Hi Derek,.
Since the problem is related to Microsoft Money, I suggest you post your question on the Forums of money from Microsoft.
-
Use with need to collect in bulk to insert records from multiple tables
Hello
I plsql record type with several tables with multiple columns. so when I used bulk collect with education for ALL. I want to insert records in multiple tables.
Please give me suggestions.
ForAll is designed to be used with a single DML statement, which may include dynamic SQL statements. However, I do not know what advantage this will give you your list iteration save several times, one for each table - especially since there is an air show with SQL dynamic.
Example 1 (dynamic SQL):
begin
...
forall i in vRecList.First..vRecList.Last
execute immediate '
begin
insert into Table1 (Col1, Col2, Col3) values (:1, :2, :3);
insert into Table2 (Col1, Col2, Col3) values (:1, :2, :3);
end;' using vRecList(i).Col1, vRecList(i).Col2, vRecList(i).Col3;
end;Another approach that I should work (but not tested) is using to insert all the Scriptures and based record inserts, but you need to try on your version of Oracle forall has changed between the versions. In this case vRecList must be compatible with the Table % ROWTYPE and Table2% ROWTYPE type.
Example 2 (insert all):
begin
...
forall i in vRecList.First..vRecList.Last
insert all
into Table1 values vRecList(i)
into Table2 values vRecList(i)
select 1 from dual;
end; -
How do I enable the update, but not insert
Hello
I have a LOV (sports say) and a checkbox (say flag). The user must select at the time of the creation of record.
for the first time when a user selects a sport in LOV, the check box will be disabled.
the user should not be able to create a record with the same sport, unless the existing record indicator is checked.
To do this, I created a display criteria in the PVO of the same table, linking the LOV and the flag.
created GOES in the EO with parameter flag = 'n'.
then he created a validator for the entity using the method.
inside the method, I ran the query'S and used the following condition.
public boolean validatesport() {}
this.getSportsChoicePVO () .executeQuery ();
Set of lines rs = this. getSportsChoicePVO ();
If (RS. GetRowCount() > 0)
Returns true;
on the other
returns the value false;
}
What happen to a sport, it's... If there is no record with indicator = N, its allowing to insert the record.
but as he tried to update the indicator = Y the number be 1 and its not allowing to update.
If I put the count > 1, its to insert the same record with indicator = N, which should not happen twice.
Please suggest what I can do,
whereas when there is already a record, he should be able to update and no insert with the same choice.
Hi Timo,
Thanks.I was able to reach my need of the following logic in the validator of the method.
When count = 0, this means that the user inserts for the first time.
When count = 1, if the entity is changed, it means that it will update and therefore allowed.
public boolean validatesport() {}
this.getSportsChoicePVO () .executeQuery ();
All lines rs = this.getSportsChoicePVO ();
If ((RS. GetRowCount () == 0) | ((getEntityState () == Entity.STATUS_MODIFIED & rs.getRowCount () == 1))
Returns true;
on the other
Returns false;
}
-
Apex 5 How do I retrieve the value inserted record in the form of DML
Hi Experts,
I have a DML form page which I created with the Wizard "form on a Table with the report." This form has a created apex "automatic processing line (DML) ' process that inserts, updates, and deletes the record in the TRXHIST table. This form use ROWID as a primary key column. The table TRXHIST is to have primary key as a field that uses the TRX_ID_SEQ sequence. There's a trigger on this table that deals with this sequence. Now the records are get inserted, updated and deleted and I am able to show the message with equal success.
Now, I have a requirement to indicate problem (that will be generated over this insertion using the sequenceof TRX_ID_SEQ ) in the success message, so that the user can be noted.
Can you please help in this.
Thank you very much
Thierry
Hi Thierry,.
- The page element existing Pxxx_ROWID and rename it to Pxxx_TRX_ID, set the attribute column of field data.
- In the LMD processes change the ROWID to TRX_ID and Pxxx_ROWID to Pxxx_TRX_ID references
- Make sure "Return Key in Item" is defined on Pxxx_TRX_ID
- In your success message of process you can use & Pxxx_TRX_ID to replace the id generated recently.
Concerning
Patrick
-
Creates a new database of GR 11, 2 dw, tested insert record 10million took 1 hour - slow
I just created a 11.2.0.3 db based on data warehouse model and tested 10 000 000 insert records through sysbench and took 1 hour.
IT is extremely slow. I did not tune the db parameters still, I guess that the parameters are good for datawarehouse.
Operating system is linux redhat.
Anyone has any advice on this?
Thanks in advancce.Hello
This is a forum for issues of data retrieval.
Try the DB general forum
Thank you, Mark -
Insert records in the W_EXCH_RATE_G table.
Hi all
Can someone help me with the following scenario.
I would like to know how to insert additional record of exchange rates in the W_EXCH_RATE_G table in the data warehouse.
I checked records in this table ate PS_RT_RATE_TBL of peoplesoft.
But I have just a flat file and I have to complete additional registration.
Can you let me know if I have to use and update the query to do the same thing or do I change the mapping in Informatica?
Thanks for the help in advance!
-NikkiNikki, see also my response to your similar message: -.
Change SIL_GLBalanceFact to populate the Balance_Global1_Amt column.
Please indicate if helpful/useful.
Andy. -
Inserting record than a single SHARED folder
Hi all, I have table ap_comm_po (structure) ap_comm_po_id , po_num , status , status_date, country_id country (structure) country_id, country_name table: ap_comm_country ap_comm_po_country_id po_num , ap_comm_country_name Can some please help me I have data like this. ap_comm_po ap_comm_po_id po_num ber status status_date country 1111 2222 CAN 1/1/2001 100 1112 22223 APR 1/1/2002 101 1113 22223 APR 1/1/2003 101 1114 22224 EST 1/1/2004 300 1115 22225 EST 1/1/2005 400 country table country_id country_name 100 canada 101 us 300 malta 400 france I need to insert into ap_comm_po_country and ap_comm_po_mig table. here is the procedure CREATE OR REPLACE FUNCTION fn_acp_comm ( p_po_id IN NUMBER) RETURN PLS_INTEGER AS v_count NUMBER; curr_acp_rec acp_comm_po%ROWTYPE; curr_acp_dtl_rec acp_comm_po_dtl%ROWTYPE; TYPE _acp_inserts_tab IS TABLE OF .acp_comm_po%ROWTYPE INDEX BY PLS_INTEGER; TYPE ap_acp_cntry_inserts_tab IS TABLE OF .acp_comm_po_dtl%ROWTYPE-- INDEX BY PLS_INTEGER; acp_inserts acp_inserts_tab; acp_cntry_inserts acp_cntry_inserts_tab; CURSOR acp_csr IS SELECT ap_comm_po_uid, acp_inv_id, acp.comm_type, acp_dtl.status_date,, acp.application_type status_id, ap_eu_flg acp_dtl.cntry_flg acp.country FROM ap_comm_po_acp acp --, JOIN .ap_comm_po_dtl acp_dtl ON acp.ap_comm_po_uid = acp_dtl.ap_comm_po_uid AND acp.ap_status= 'CAN' WHERE acp.p_ap_comm_po_id = p_ap_comm_po_id; BEGIN FOR acp_rec IN acp_csr LOOP BEGIN SELECT dev3.seq_id.NEXTVAL INTO curr_acp_rec.acp_po_id FROM DUAL; curr_acp_rec.acp_inv_id := acp_rec.acp_inv_id; curr_acp_rec.status_id := acp_rec.status_id; curr_acp_rec.status_date := acp_rec.status_date; acp_inserts (curr_acp_rec.ap_comm_po_id) := curr_acp_rec; The problem here is the acp_csr cursor returns more than one record for same po number beacuse of different statuses. I need to insert into ap_comm_country table ONLY one record per ap_comm_po_uid. How do I get only one record SELECT sequence_id.NEXTVAL INTO acp_cntry_inserts .app_country_id FROM DUAL; acp_cntry_inserts.ap_comm_po_uid:= curr_app_rec.curr_acp_rec.ap_comm_po_id ; acp_cntry_inserts.country_id := acp_rec.country_name; ... .... END LOOP; -- Create acp data BEGIN FORALL acp_idx IN INDICES OF acp_inserts INSERT INTO ap_comm_po_mig VALUES acp_inserts (acp_idx); v_count := SQL%ROWCOUNT; EXCEPTION -- Create acp country data BEGIN FORALL acp_cntry_idx IN INDICES OF acp_cntry_inserts INSERT INTO ap_comm_country VALUES acp_cntry_inserts (acp_cntry_idx); v_count := SQL%ROWCOUNT; EXCEPTION END;
Next time, please provide CREATE TABLE and INSERT statements yourself. Here are the ones I did:
CREATE TABLE AP_COMM_PO (AP_COMM_PO_ID, PO_NUMBER, STATUS, STATUS_DATE, COUNTRY) AS SELECT '1111', 2222, 'CAN', TO_DATE('1/1/2001','mm/dd/yyyy'), 100 FROM DUAL UNION ALL SELECT '1112', 22223, 'APR', TO_DATE('1/1/2002','mm/dd/yyyy'), 101 FROM DUAL UNION ALL SELECT '1113', 22223, 'APR', TO_DATE('1/1/2003','mm/dd/yyyy'), 101 FROM DUAL UNION ALL SELECT '1114', 22224, 'EST', TO_DATE('1/1/2004','mm/dd/yyyy'), 300 FROM DUAL UNION ALL SELECT '1115', 22225, 'EST', TO_DATE('1/1/2005','mm/dd/yyyy'), 400 FROM DUAL; CREATE TABLE COUNTRY(COUNTRY_ID, COUNTRY_NAME) AS SELECT 100, 'CANADA' FROM DUAL UNION ALL SELECT 101, 'us' FROM DUAL UNION ALL SELECT 300, 'MALTA' FROM DUAL UNION ALL SELECT 400, 'france' FROM DUAL; CREATE TABLE AP_COMM_PO_MIG AS SELECT AP_COMM_PO_ID, PO_NUMBER, STATUS, STATUS_DATE FROM AP_COMM_PO WHERE 1=0; CREATE TABLE AP_COMM_COUNTRY AS SELECT COUNTRY_ID AP_COMM_PO_COUNTRY_ID, PO_NUMBER , COUNTRY_NAME AP_COMM_COUNTRY_NAME from COUNTRY, AP_COMM_PO_MIG where 1=0; CREATE SEQUENCE AP_SEQ; CREATE SEQUENCE COUNTRY_SEQ;
Now, I would just make two INSERT statements instead of all this code:
INSERT INTO AP_COMM_PO_MIG select ap_seq.nextval, po_number, status, status_date from ap_comm_po; INSERT INTO AP_COMM_COUNTRY WITH DATA AS (SELECT DISTINCT PO_NUMBER, COUNTRY FROM AP_COMM_PO) SELECT COUNTRY_SEQ.NEXTVAL, A.PO_NUMBER, B.COUNTRY_NAME from data a join country b on (a.country = b.country_id);
-
Hi all
I have a requirement in oracle forms 6i
I have a block of data that is in a table
There are 5 columns
1 column is only display and 4 others are normal text fields where we can insert update and delete these records
My requirement is when a user updates a record that should trigger an alert and the alert should ask if the user wants to update that particular record
The user presses Yes, then the record should be updated if the record should show as it has been shown previously
Similarly in case of delete an alert should fire where we have to ask confirmation if the user presses Yes, then the record must be deleted from the database
otherwise the registration should be visible on the form again as we
my 3rd requirement which is also
I have an element field which is the normal text and only display field is the description
When you enter a new record when I enter in the item field and press tab or navigate outside the scope of the element, then the description of the element must be pouplated in the decsription read only field
Please help me in the above 3 cases
I'm new to forms
I use an ID of friends that has a lot of messages
Thanks in advance1)
your first requirement I'd prior block UPDATE trigger:DECLARE v_alert_button NUMBER; BEGIN v_alert_button := SHOW_ALERT('your_alert'); -- "Do you want to update?" IF v_alert_button = ALERT_BUTTON1 -- assuming "No" THEN -- reset value: :YOUR_BLOCK.YOUR_ITEM1 := GET_ITEM_PROPERTY('YOUR_BLOCK.YOUR_ITEM1', DATABASE_VALUE); -- optionally set item to valid if you don't want validations to fire: SET_ITEM_PROPERTY('YOUR_BLOCK.YOUR_ITEM1', ITEM_IS_VALID, PROPERTY_TRUE); -- do this for every item: :YOUR_BLOCK.YOUR_ITEM2 := GET_ITEM_PROPERTY('YOUR_BLOCK.YOUR_ITEM2', DATABASE_VALUE); ... ... -- finally reset record status: SET_RECORD_STATUS(:SYSTEM.CURSOR_RECORD, STATUS, QUERY_STATUS); -- interrupt PRE-UPATE trigger: RAISE FORM_TRIGGER_FAILURE; END IF; END;
(not tested, please try for yourself)
2)
trigger the alert first remove the trigger.3)
You can do within the WHEN-VALIDATE-ITEM trigger or a list-of-value (LOV) that returns the values of description. -
Yet an another Insert Record problem
I have two tables
cities & menus
I have a registration form insert created from the wizard for each table that I'm inserting records in.
The first form, I am inserting a "name of the city. When I insert this record, it automatically gives the name of the city a CityID in the database. It works very well.
The second form, I'm inserting in the fields:
Restaurant name (this registration automatically creates a RestaurantID
Name of the city
Address
Phone
Bonnefin
Once I'm going to insert the record in the table of menus, I get the error saying that "cityID field does not have a default value".
"CityID" field isn't a default value
The error occurred in /Applications/ColdFusion8/wwwroot/ncmenus/admin/index.cfm: line 66
64:, < cfif IsDefined ("FORM.logoImg") AND #FORM.logoImg # NEQ "" > "".
65: cfqueryparam value = "" #FORM.logoImg # "cfsqltype ="cf_sql_clob"maxlength ="100">"
66: < cfelse >
67: "
68: < / cfif >
What can I do to fix this?I figured this out. I just needed to include a field for cityID and do fill a menu that extracts data from the database of the 'cities '.
-
Display the data in dimension without a recording made
To explain my requirement, lets say I have 3 tables
City (Dimension presents all the information of city)
Day (Date Dimension with all dates in recent years (past and future))
Sales (fact table showing all measures of sales, multiple records for a day and city)
An example query to retrieve the data I need
Select the amount of city.name, day.name, SUM (sales.amount)
day, city, sales
where city.code = sales.city_code
and day.date_value = sales.transaction_date
City.name group, day.name
Now if there is no transaction of sales for a particular day and the city, still I want to show day and the city with amount 0
The solution that I can think of is a Cartesian of the city and day tables use it as a point of view online and then perform a join with the sales table.
Is there a better way to do this, using a simple query logic or any advanced functionality?
All entries on the above would be a great help.
Thank you
Murielle
Published by: user12033529 on Sep 12, 2010 06:57Hi, Murielle,.
Welcome to the forum!
Whenever you have a proiblem, please post your version of Oracle (e.g. 10.2.0.3.0); Some examples of data in a form people can re-create the problem (for example
CREATE TABLE city ( city_id NUMBER (6) PRIMARY KEY , city_name VARCHAR2 (20) NOT NULL ); INSERT INTO CITY (city_id, city_name) VALUES (1, 'Asheville'); INSERT INTO CITY (city_id, city_name) VALUES (2, 'Bryson City'); INSERT INTO CITY (city_id, city_name) VALUES (3, 'Cherokee'); CREATE TABLE day ( dt DATE PRIMARY KEY ); INSERT INTO day (dt) SELECT DATE '2010-09-10' + LEVEL FROM dual CONNECT BY LEVEL <= 3; CREATE TABLE sales ( sales_id NUMBER (6) PRIMARY KEY , city_id NUMBER (6) , sales_dt DATE , amount NUMBER (9) ); INSERT INTO sales (sales_id, city_id, sales_dt, amount) VALUES (11, 1, DATE '2010-09-01', 10); INSERT INTO sales (sales_id, city_id, sales_dt, amount) VALUES (12, 1, DATE '2010-09-11', 20); INSERT INTO sales (sales_id, city_id, sales_dt, amount) VALUES (13, 1, DATE '2010-09-12', 40); INSERT INTO sales (sales_id, city_id, sales_dt, amount) VALUES (14, 1, DATE '2010-09-12', 80); INSERT INTO sales (sales_id, city_id, sales_dt, amount) VALUES (15, 2, DATE '2010-09-11', 160); INSERT INTO sales (sales_id, city_id, sales_dt, amount) VALUES (16, 2, DATE '2010-09-11', 320); COMMIT;
) and the expected results of these data (for example
CITY_NAME DT TOTAL_AMOUNT -------------------- ----------- ------------ Asheville 11-Sep-2010 20 Asheville 12-Sep-2010 120 Asheville 13-Sep-2010 0 Bryson City 11-Sep-2010 480 Bryson City 12-Sep-2010 0 Bryson City 13-Sep-2010 0 Cherokee 11-Sep-2010 0 Cherokee 12-Sep-2010 0 Cherokee 13-Sep-2010 0
).
user12033529 wrote:
... The solution that I can think of is a Cartesian of the city and day tables use it as a point of view online and then perform a join with the sales table.Is there a better way to do this, using a simple query logic or any advanced functionality?
For this particular problem, I think it is the best way.
There is another way: SELECT... PARTITION OF feature (also known as query interior partitions ).
For example:WITH all_cities AS ( SELECT c.city_name , s.sales_dt , s.amount FROM sales s PARTITION BY (city_id) RIGHT OUTER JOIN city c ON s.city_id = c.city_id ) SELECT a.city_name , d.dt , NVL ( SUM (a.amount) , 0 ) AS total_amount FROM all_cities a PARTITION BY (city_name, sales_dt) RIGHT OUTER JOIN day d ON a.sales_dt = d.dt GROUP BY a.city_name , d.dt ORDER BY a.city_name , d.dt ;
It seems that you should be able to do this without a subquery, but I don't know how.
Partitioning of the application is really useful when you want to include only a few dimensions that are actually present in the fact table. For example, if you want to show only the cities that actually took sale (in other words, in this example, if you do not want to include Cherokee), but you don't want that all the dates in the table of the day for each city.
Partitioning of the query was new in Oracle 10. If you have an older version, I think that a cross join, as you initially suggested, is the only reasonable way.
Published by: Frank Kulash, Sep 12, 2010 13:14
-
How to insert record empty in the table?
I guess I need to insert a blank record in my table to troubleshoot issues below, but don't know how to do.
I have a function below that is part of two selects the associated component. My first problem is if no data is passed to the argument, select field that is bound to the function is very small (I like to have a default width). Adding a 'width' will not work.
Second, if there is data passed to the argument (in Arguments.accountID, I would like to have a clean record inserted at the top of the results of the selection list. So in summary, if no data is transmitted to the argument, select the field is very weak. If the data are transmitted to the argument, the selection list is filled, but I need to have an empty folder (option) at the top of the selection list.
The code for the function shown below:
< cffunction = 'getUsers' access returnType = name 'remotely' 'array' = >
< name cfargument = "accountID" type = "string" required = "yes" >
<!--> set variables
< cfset var data = "" >
< cfset var result = ArrayNew (2) >
< cfset var i = 0 >
< cfset data1 = oSF.QueryObject("select_ID,_name,_Email,_ACCOUNTID__C_from_User").results >
< cfquery dbtype = "query" name = "data" >
SELECT ID, NAME, ACCOUNTID__C
OF DATA1
WHERE ACCOUNTID__C = ' #arguments.accountID # '.
< / cfquery >
<!--> results converting it into table
< cfloop index = "i" = "1" to = "#data.recordcount #" >
< cfset result [1] = data user.user>
< cfset result [2] = data .name>
< / cfloop >
<!- and return it - >
< cfreturn result >
< / cffunction >
< b > Code to select list: < /b >
< name cfselect = 'Contacts'
ToolTip bind = "SWC:getPartners.GetUsers({Mediaid})" = "select the partner Rep' onError =" ""
Width = "50" / >
Change this:
SELECT ID, NAME, ACCOUNTID__C
OF DATA1
WHERE ACCOUNTID__C = ' #arguments.accountID # '.for this
Select distinct "id,"name", from accountid_c
of some_small_table
Union
SELECT ID, NAME, ACCOUNTID__C
OF DATA1
WHERE ACCOUNTID__C = ' #arguments.accountID # '.
order by idIf one of these fields is not text, use any function db is appropriate convert to string in the bottom half of the application
-
Is this possible using php and insert record?
Hi I have a table to insert record named CV
If I leave the choice of the CV, for example temp, international, student etc., can I do some fields not available or available depending on the choice of the CV. Why I need is that if the choice is temp user chooses their rate of pay, the others won't. It is a single difference there will be a few other institutions. I wonder if I can use a conditional statement with the insert record or will I need to put in place a variety of tables of CV in the database?
Thanks I hope you can help I am new to this.jjjhbj111 wrote:
> Hi David
> Thank you for the great response. I'd put the code of adaptation before inserting registration data or after?The following code is from a real insert record server behavior:
If ((isset($_POST["MM_insert"])) & ($_POST ["MM_insert"] ==))
"insertAuthor')) {}
$insertSQL = sprintf ("INSERT INTO authors (name, family_name)
VALUES (%s, %s) ',)
GetSQLValueString ($_POST ['name'], "text").
GetSQLValueString ($_POST ['family_name'], "text"));The conditional statement must wrap the definition of $insertSQL. You
you will need to create your own definition for $insertSQL for each scenario. For
example, you might adapt this option to create different insert orders
If a middle name is supplied in function:If ((isset($_POST["MM_insert"])) & ($_POST ["MM_insert"] ==))
"insertAuthor')) {}
If ($_POST ["middle_name"]! = "") {}
$insertSQL = sprintf ("INSERT INTO authors (name, middle_name,
Family_name VALUES) (%s, %s, %s) ',)
GetSQLValueString ($_POST ['name'], "text").
GetSQLValueString ($_POST ['middle_name'], "text").
GetSQLValueString ($_POST ['family_name'], "text"));
}
else {}
$insertSQL = sprintf ("INSERT INTO authors (name, family_name)
VALUES (%s, %s) ',)
GetSQLValueString ($_POST ['name'], "text").
GetSQLValueString ($_POST ['family_name'], "text"));
}--
David powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/
Maybe you are looking for
-
I use Earlybird on my Win 7 64 bit laptop for about 18 months. I use EB because Thunderbird crashed whenever I tried to open it; EB gets unresponsive from time to time, but is otherwise stable. My research at the right time that EB was the only alter
-
How can I get bookmarks will automatically open in a new tab rather than the tab I am when I select the bookmark?
-
Some kind of an API for Skype? I want to build another Skype app, I'm serious.
To be simple, Skype for Android is crap, I use Skype frequently, slow opening, buggy GUI and all never makes the worst app on my phone Saying that, doesn't mean is my opinion, it is the opinion of others too. I do not pretend to fix all that, because
-
Toshiba NB205 - recovery media has been tampered
I have a Toshiba NB205. My netbook was also gently as when I first bought it, so I decided to do a cover on it. This netbook doesn't have a disk drive, so the recovery program gave the possibility of having the recovery media placed on a flash drive.
-
Re: Windows 7 will work on a Satellite L30-134?
I'll be upgrading the ram to 2 GB and install a new hard drive in my old satellite phone soon. I would like to upgrade to windows 7 32 bit if possible. Can someone tell me if it will run this OS? Thank you.