Support for copying data using sql
HelloI want to fill the data in a table in a way
EID ENAME EADDRESS ESALARY EDEPARTMENT MANAGER_ID
101 Pankaj Saxena New Delhi 2000 IT
102 Sanjay Singh New Delhi 2000 IT 101
103 Dhiraj Tuteja Kanpur 3000 NONIT 101
104 Nitin Grover New Delhi 4000 IT 102
105 Juhi Agarwal Itawa 5000 NONIT 103
106 Siddharth Itawa 5000 NONIT 103
107 Kalyan Itawa 7000 IT 104
Now I want to fill the same data 10 times but the IDS must be incrementedWhat should I do?
I use oracle 9i
insert into demo_1
select eid,ename,eaddress,esalary,edepartment,manager_id from demo_1
I have eid necessary to increase sequencially
Create a sequence.
insert into demo_1
Select sq.nextval, ename, eaddress, esalary, edepartment, manager_id demo_1
Tags: Database
Similar Questions
-
Disks supported for local data banks?
Hello
What kind of discs are supported for local data stores that is IDE, SATA, SCSI, SAS...
Ide drives is not supported for use how VMFS.
If you have found this information useful, please consider awarding points to 'Correct' or 'Useful'*.
-
How to view clob data using sql
Hello
In our database we have a table that is to have a column of type CLOB but now I want to display the data using sql select query but it throws error: "unsupported data Type.
Could someone let me know how to view the clob data using the select query.
Oracle DB version: 10.2.0.3
Thank youuser562223 wrote:
HelloIn our database we have a table that is to have a column of type CLOB but now I want to display the data using sql select query but it throws error: "unsupported data Type.
Could someone let me know how to view the clob data using the select query.
Oracle DB version: 10.2.0.3
Thank you
Usually a to_char (CLOBDFIELD) circled
HTH,
FJFranken
-
Question to load data using sql loader in staging table, and then in the main tables!
Hello
I'm trying to load data into our main database table using SQL LOADER. data will be provided in separate pipes csv files.
I have develop a shell script to load the data and it works fine except one thing.
Here are the details of a data to re-create the problem.
Staging of the structure of the table in which data will be filled using sql loader
create table stg_cmts_data (cmts_token varchar2 (30), CMTS_IP varchar2 (20));
create table stg_link_data (dhcp_token varchar2 (30), cmts_to_add varchar2 (200));
create table stg_dhcp_data (dhcp_token varchar2 (30), DHCP_IP varchar2 (20));
DATA in the csv file-
for stg_cmts_data-
cmts_map_03092015_1.csv
WNLB-CMTS-01-1. 10.15.0.1
WNLB-CMTS-02-2 | 10.15.16.1
WNLB-CMTS-03-3. 10.15.48.1
WNLB-CMTS-04-4. 10.15.80.1
WNLB-CMTS-05-5. 10.15.96.1
for stg_dhcp_data-
dhcp_map_03092015_1.csv
DHCP-1-1-1. 10.25.23.10, 25.26.14.01
DHCP-1-1-2. 56.25.111.25, 100.25.2.01
DHCP-1-1-3. 25.255.3.01, 89.20.147.258
DHCP-1-1-4. 10.25.26.36, 200.32.58.69
DHCP-1-1-5 | 80.25.47.369, 60.258.14.10
for stg_link_data
cmts_dhcp_link_map_0309151623_1.csv
DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2
DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5
DHCP-1-1-3. WNLB-CMTS-01-1
DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3
DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7
WNLB-DHCP-1-13 | WNLB-CMTS-02-2
Now, after loading these data in the staging of table I have to fill the main database table
create table subntwk (subntwk_nm varchar2 (20), subntwk_ip varchar2 (30));
create table link (link_nm varchar2 (50));
SQL scripts that I created to load data is like.
coil load_cmts.log
Set serveroutput on
DECLARE
CURSOR c_stg_cmts IS SELECT *.
OF stg_cmts_data;
TYPE t_stg_cmts IS TABLE OF stg_cmts_data % ROWTYPE INDEX BY pls_integer;
l_stg_cmts t_stg_cmts;
l_cmts_cnt NUMBER;
l_cnt NUMBER;
NUMBER of l_cnt_1;
BEGIN
OPEN c_stg_cmts.
Get the c_stg_cmts COLLECT in BULK IN l_stg_cmts;
BECAUSE me IN l_stg_cmts. FIRST... l_stg_cmts. LAST
LOOP
SELECT COUNT (1)
IN l_cmts_cnt
OF subntwk
WHERE subntwk_nm = l_stg_cmts (i) .cmts_token;
IF l_cmts_cnt < 1 THEN
INSERT
IN SUBNTWK
(
subntwk_nm
)
VALUES
(
l_stg_cmts (i) .cmts_token
);
DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_cmts (i) .cmts_token);
ON THE OTHER
DBMS_OUTPUT. Put_line ("token is already present'");
END IF;
WHEN l_stg_cmts EXIT. COUNT = 0;
END LOOP;
commit;
EXCEPTION
WHILE OTHERS THEN
Dbms_output.put_line ('ERROR' |) SQLERRM);
END;
/
output
for dhcp
coil load_dhcp.log
Set serveroutput on
DECLARE
CURSOR c_stg_dhcp IS SELECT *.
OF stg_dhcp_data;
TYPE t_stg_dhcp IS TABLE OF stg_dhcp_data % ROWTYPE INDEX BY pls_integer;
l_stg_dhcp t_stg_dhcp;
l_dhcp_cnt NUMBER;
l_cnt NUMBER;
NUMBER of l_cnt_1;
BEGIN
OPEN c_stg_dhcp.
Get the c_stg_dhcp COLLECT in BULK IN l_stg_dhcp;
BECAUSE me IN l_stg_dhcp. FIRST... l_stg_dhcp. LAST
LOOP
SELECT COUNT (1)
IN l_dhcp_cnt
OF subntwk
WHERE subntwk_nm = l_stg_dhcp (i) .dhcp_token;
IF l_dhcp_cnt < 1 THEN
INSERT
IN SUBNTWK
(
subntwk_nm
)
VALUES
(
l_stg_dhcp (i) .dhcp_token
);
DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_dhcp (i) .dhcp_token);
ON THE OTHER
DBMS_OUTPUT. Put_line ("token is already present'");
END IF;
WHEN l_stg_dhcp EXIT. COUNT = 0;
END LOOP;
commit;
EXCEPTION
WHILE OTHERS THEN
Dbms_output.put_line ('ERROR' |) SQLERRM);
END;
/
output
for link -.
coil load_link.log
Set serveroutput on
DECLARE
l_cmts_1 VARCHAR2 (4000 CHAR);
l_cmts_add VARCHAR2 (200 CHAR);
l_dhcp_cnt NUMBER;
l_cmts_cnt NUMBER;
l_link_cnt NUMBER;
l_add_link_nm VARCHAR2 (200 CHAR);
BEGIN
FOR (IN) r
SELECT dhcp_token, cmts_to_add | ',' cmts_add
OF stg_link_data
)
LOOP
l_cmts_1: = r.cmts_add;
l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));
SELECT COUNT (1)
IN l_dhcp_cnt
OF subntwk
WHERE subntwk_nm = r.dhcp_token;
IF l_dhcp_cnt = 0 THEN
DBMS_OUTPUT. Put_line ("device not found: ' |") r.dhcp_token);
ON THE OTHER
While l_cmts_add IS NOT NULL
LOOP
l_add_link_nm: = r.dhcp_token |' _TO_' | l_cmts_add;
SELECT COUNT (1)
IN l_cmts_cnt
OF subntwk
WHERE subntwk_nm = TRIM (l_cmts_add);
SELECT COUNT (1)
IN l_link_cnt
LINK
WHERE link_nm = l_add_link_nm;
IF l_cmts_cnt > 0 AND l_link_cnt = 0 THEN
INSERT INTO link (link_nm)
VALUES (l_add_link_nm);
DBMS_OUTPUT. Put_line (l_add_link_nm |) » '||' Has been added. ") ;
ELSIF l_link_cnt > 0 THEN
DBMS_OUTPUT. Put_line (' link is already present: ' | l_add_link_nm);
ELSIF l_cmts_cnt = 0 then
DBMS_OUTPUT. Put_line (' no. CMTS FOUND for device to create the link: ' | l_cmts_add);
END IF;
l_cmts_1: = TRIM (SUBSTR (l_cmts_1, INSTR (l_cmts_1, ',') + 1));
l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));
END LOOP;
END IF;
END LOOP;
COMMIT;
EXCEPTION
WHILE OTHERS THEN
Dbms_output.put_line ('ERROR' |) SQLERRM);
END;
/
output
control files -
DOWNLOAD THE DATA
INFILE 'cmts_data.csv '.
ADD
IN THE STG_CMTS_DATA TABLE
When (cmts_token! = ") AND (cmts_token! = 'NULL') AND (cmts_token! = 'null')
and (cmts_ip! = ") AND (cmts_ip! = 'NULL') AND (cmts_ip! = 'null')
FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
('RTRIM (LTRIM (:cmts_token))' cmts_token,
cmts_ip ' RTRIM (LTRIM(:cmts_ip)) ")". "
for dhcp.
DOWNLOAD THE DATA
INFILE 'dhcp_data.csv '.
ADD
IN THE STG_DHCP_DATA TABLE
When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')
and (dhcp_ip! = ") AND (dhcp_ip! = 'NULL') AND (dhcp_ip! = 'null')
FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
('RTRIM (LTRIM (:dhcp_token))' dhcp_token,
dhcp_ip ' RTRIM (LTRIM(:dhcp_ip)) ")". "
for link -.
DOWNLOAD THE DATA
INFILE 'link_data.csv '.
ADD
IN THE STG_LINK_DATA TABLE
When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')
and (cmts_to_add! = ") AND (cmts_to_add! = 'NULL') AND (cmts_to_add! = 'null')
FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "
TRAILING NULLCOLS
('RTRIM (LTRIM (:dhcp_token))' dhcp_token,
cmts_to_add TANK (4000) RTRIM (LTRIM(:cmts_to_add)) ")" ""
SHELL SCRIPT-
If [!-d / log]
then
Mkdir log
FI
If [!-d / finished]
then
mkdir makes
FI
If [!-d / bad]
then
bad mkdir
FI
nohup time sqlldr username/password@SID CONTROL = load_cmts_data.ctl LOG = log/ldr_cmts_data.log = log/ldr_cmts_data.bad DISCARD log/ldr_cmts_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &
nohup time username/password@SID @load_cmts.sql
nohup time sqlldr username/password@SID CONTROL = load_dhcp_data.ctl LOG = log/ldr_dhcp_data.log = log/ldr_dhcp_data.bad DISCARD log/ldr_dhcp_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &
time nohup sqlplus username/password@SID @load_dhcp.sql
nohup time sqlldr username/password@SID CONTROL = load_link_data.ctl LOG = log/ldr_link_data.log = log/ldr_link_data.bad DISCARD log/ldr_link_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &
time nohup sqlplus username/password@SID @load_link.sql
MV *.log. / log
If the problem I encounter is here for loading data in the link table that I check if DHCP is present in the subntwk table, then continue to another mistake of the newspaper. If CMTS then left create link to another error in the newspaper.
Now that we can here multiple CMTS are associated with unique DHCP.
So here in the table links to create the link, but for the last iteration of the loop, where I get separated by commas separate CMTS table stg_link_data it gives me log as not found CMTS.
for example
DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2
Here, I guess to link the dhcp-1-1-1 with balancing-CMTS-01-1 and wnlb-CMTS-02-2
Theses all the data present in the subntwk table, but still it gives me journal wnlb-CMTS-02-2 could not be FOUND, but we have already loaded into the subntwk table.
same thing is happening with all the CMTS table stg_link_data who are in the last (I think here you got what I'm trying to explain).
But when I run the SQL scripts in the SQL Developer separately then it inserts all valid links in the table of links.
Here, she should create 9 lines in the table of links, whereas now he creates only 5 rows.
I use COMMIT in my script also but it only does not help me.
Run these scripts in your machine let me know if you also get the same behavior I get.
and please give me a solution I tried many thing from yesterday, but it's always the same.
It is the table of link log
link is already present: dhcp-1-1-1_TO_wnlb-cmts-01-1 NOT FOUND CMTS for device to create the link: wnlb-CMTS-02-2
link is already present: dhcp-1-1-2_TO_wnlb-cmts-03-3 link is already present: dhcp-1-1-2_TO_wnlb-cmts-04-4 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-5
NOT FOUND CMTS for device to create the link: wnlb-CMTS-01-1
NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-8 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-6 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-0 NOT FOUND CMTS for device to create the link: wnlb-CMTS-03-3
link is already present: dhcp-1-1-5_TO_wnlb-cmts-02-2 link is already present: dhcp-1-1-5_TO_wnlb-cmts-04-4 NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-7
Device not found: wnlb-dhcp-1-13 IF NEED MORE INFORMATION PLEASE LET ME KNOW
Thank you
I felt later in the night that during the loading in the staging table using UNIX machine he created the new line for each line. That is why the last CMTS is not found, for this I use the UNIX 2 BACK conversion and it starts to work perfectly.
It was the dos2unix error!
Thank you all for your interest and I may learn new things, as I have almost 10 months of experience in (PLSQL, SQL)
-
Logic to find particular weekdays after a given date, using SQL
Hello Experts,
Version: Oracle 11G
Could you please help me with logic to find a day of special week after a date in SQL
For example, I need to know the first Friday after today's date.
Thank you for your help.I hope that under query will be useful for you.
SELECT NEXT_DAY(SYSDATE,'FRIDAY') "NEXT DAY" FROM DUAL Output: NEXT DAY 2/24/2012 12:06:48 PM
-
Last week, and now on the longest phone conversation with me this morning, Mon, 22/07/13, phone swindler wants to CHECK the ID NUMBER OF YOUR COMPUTER. A 3rd call repeat 'husband' today, from "Steve Matthew," of "Zircon systems", where the staff is all "Microsoft Certified technicians". Said our PC has been disconnected from the server "universal routing" and needed to check the identification number. Said computer infected and disengaged, errors with malicious files. That 50% of Microsoft applications does not. Finally, after several questions polite but stupid me, as if to say but our computer works OK? the appellant was told that he is temporarily hung up a temporary server! but it must be reconnected... After having his name and telephone number - strongly Indian accented man "Steve Matthew" on the phone # 408-498-3608, and have patiently give me the 888DCA60 etc etc 32 numbers, he indicated that he understood my being suspicious, but it is a Microsoft Certified tech, calling for Windows, have we not Windows 7 or XP or Windows 8, etc.? And he said I could not find the computer ID number easily, it wasn't on our guaranteed purchase paperwork, etc, that I would need to go online with him, to find our location.
Knowing that registrations for computers, go directly to the manufacturer only if you send the information on your purchase, and that no known iin manufacturer sends the modern world 'Oops, you're disconnected' phone calls, it seemed a bit of fun to keep to provide information...
So I explained to Mr. Steve, when he repeated for the 4th time that it has been certified Microsoft Tech and trustworthy and kept warning me that our computer would break soon, that, by analogy, certified Subaru Techncians had simply taken a few classes to automotive Subaru training and were not necessarily qualified or guaranteed to work on my car the certification does not matter, you should still consult your dealer, the garage, make sure it's good reputation. Then, I asked him directly, so, on a phone call from me, a total unknown, he would be willing to send me or transfer to me $2 000,00. He actually misses, in dismay. So I repeated it-$ 2,000, say, in US dollars, would it send it to me, if I had called and told him his bank account had been disconnected from his bank, and I needed to reconnect it? He ate and asked me ' you mean $2,000! $? ' so I said yes, would he give me or transfer to me on this amount, based on a phone call? He said absolutely not. End of quote. I told him how we would check with some type IT geek friends we know, took his phone, name and said I would be back to him and please DON'T NOT CALL BACK IN AN HOUR, BUT PUT us WE HIS DO NOT CALL LIST.
At this point, I googled Zircon systems - and there is no such American society less than a jeweler or invest co. in Illinois), although I had a systems Zicom in India, which seems to be the sale of legitimate & electronic security systems and then I googled the identification number, find some great ads about what happen and asks what will be PayPal scam, if one agrees with the appellant and goes online and follow their directions.
(See mutation 2012 of a David Jacoby to http://www.securelist.com/en/blog/208193750/ , who described a telephone scam quite similar, with the technical information, copy requested screens, orders). Maybe giving a technical support genuine or scam to support people on your side, an idea of what was going on my caller to walk me through, if I had fallen for the Universal Server disconnected claim it does?
Hope this helps to update your information, files.
In any case, this is my first time ever having reported a telephone scam. Thought it would do, seems since then I received a call from update and more sophisticated scam. My husband simply hung up on the caller last week - he knows little re our PC, I ask more tech-savvy people to help if necessary. But then, the scammer called back, too. If something had to be done to put an end to the process?
Don't forget, if you get that kind of call, simply ask the crook to trust YOU, say that you are a certified technician to bankruptcy with years of training from the IRS. Ask if he is personally prepared to transfer $2 000,00 to you (via Paypal, do not give your bank account to him for any potential future direct deposit!), but preferably by cheque of... And it must be sent to the address of your worst enemy in life, as you need the alimony to a former spouse. Or to a mailbox in a different city than your... And then tell him you'll telephone him with the identification number of your computer, once you have verified that the money is in hand.
Done politely, in a pleasant soft voice, you would be surprised how unprepared the scammer or snow must be befriended as a simple employee, but itself for you send funds then asked? I'm looking seriously for the money from them here - I'm not asking in fact send me $2,000, but I said that I was trying to explain by analogy, with auto - trained technicians and requests for money, why I wanted to check with the best-known people before giving identification numbers. Analogies, it seems well understand what we hear - an example? I just him speechless when I wanted a large amount of course him sent me instead...
Uh, Mr. Steve Matthew, Zircon systems, technical support for Windows company, also clearly didn't "want to send me a few thousand, and he hung up, after I suggested that he does not call again, asked him to put us on the list of subscribers do not call... Clearly a new variant, although, in the wick on the Microsoft Certified Tech claims, the name of Zircon systems company and so I thought after that.
Hello
I had a similar call from Indian women (?) strongly accented called 'Janet' of 'Zedconnsystems', based in Floria, USA. She had called asking to speak with my roommate to tell her at the computer (which is mine) showed the error messages. She shook off the usual garbage and was unable to answer most of the questions I asked, but gave his phone number as 4084983608.
As far as scams go this one seems rather transparent, but mention on the off chance someone saves a load of hassle!
-
Error loading data using SQL loader
I get an error message like "SQL * Loader - 350 combination illegal syntax of non-alphanumeriques characters error during loading of a file using SQL loader in RHEL." The command used to run SQL * Loader is:
Sqlldr userid = < user name > / < password > control = data.ctl
The control file is data.ctl:
DOWNLOAD the data
INFILE ' / home/oraprod/data.txt'
Add in the table test
{
EmpID completed by «,»,
fname completed by «,»,
lname completed by «,»,
treatment is completed with a white space
}
The data.txt file is:
1, Kaushal, Hamad, 5000
2, Chetan, Hamad, 1000
Hopefully, my question is clear.
Please get back with the answer to my query.
Concerning
Replace "{" by "("dans votre fichier de contrôle) "
DOWNLOAD the data
INFILE 'c:\data.txt.
Add the emp_t table
(
EmpID completed by «,»,
fname completed by «,»,
lname completed by «,»,
treatment is completed with a white space
)
C:\>sqlldr user/pwd@database control = c.ctl
SQL * Loader: release 10.2.0.3.0 - Production on Wed Nov 13 10:10:24 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Commit the point reached - the number of logical records 1
Commit the point reached - the number of logical records 2
SQL > select * from emp_t;
EMPID, FNAME LNAME SALARY
---------- -------------------- -------------------- ----------
1 kone hamadi 5000
2 Chetan Hamad 1000
Best regards
Mohamed Houri
-
To change the way of afficherdans the data using SQL
I have data as follows:
Name age
Tom 24
Harry 45
Mona 30
I want to convert these data in the way below
Name1, name2 Age1 Age2 Name3 3
24 45 30 Mona Harry Tom
How can I do the same thing using SQL?Why not try to search this forum of 'PIVOT' to make this small change yourself?
SQL> set line 1000 SQL> WITH t AS (SELECT 101 empid,45 marks,8 rank FROM dual UNION ALL 2 SELECT 101 empid,62 marks,7 FROM dual UNION ALL 3 SELECT 101 empid,80 marks,2 FROM dual UNION ALL 4 SELECT 102 empid,67 marks,5 FROM dual UNION ALL 5 SELECT 102 empid,56 marks,6 FROM dual UNION ALL 6 SELECT 103 empid,87 marks,7 FROM dual UNION ALL 7 SELECT 103 empid,55 marks,9 FROM dual UNION ALL 8 SELECT 103 empid,60 marks,6 FROM dual UNION ALL 9 SELECT 103 empid,70 marks,3 FROM dual 10 ) 11 ---End of Sample Data 12 ---Now the original query. 13 SELECT empid, MAX(DECODE(rn1,1,marks)) Marks1,MAX(DECODE(rn1,1,rank)) Rank1 14 , MAX(DECODE(rn1,2,marks)) Marks2,MAX(DECODE(rn1,2,rank)) Rank2 15 , MAX(DECODE(rn1,3,marks)) Marks3,MAX(DECODE(rn1,3,rank)) Rank3 16 , MAX(DECODE(rn1,4,marks)) Marks4,MAX(DECODE(rn1,4,rank)) Rank4 17 FROM 18 (SELECT empid,marks,rank, 19 ROW_NUMBER() OVER(PARTITION BY empid ORDER BY marks) rn1 20 FROM t) 21 GROUP BY empid; EMPID MARKS1 RANK1 MARKS2 RANK2 MARKS3 RANK3 MARKS4 RANK4 ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- 101 45 8 62 7 80 2 102 56 6 67 5 103 55 9 60 6 70 3 87 7 SQL>
-
How to list data types and column for a given using SQL table names
I remember that it is possible to use a select statement to list the column names and the data types of the databaase tables but I forgot how its done. Help, please.You can select what you need from DBA_TAB_COLUMNS (or ALL_TAB_COLUMNS and USER_TAB_COLUMNS).
-
Select quarterly data using SQL
All-
The database version that I use is 10.2.0.4.0
This is probably simple, but for the life of me, I can't understand it. I have a table of approximately 200 Codes and a table that contains millions of records that are obliterated (data are from 1995 to sysdate). I need a query for a view to be used in a report that will show you the different codes used by the employee for specific areas based on a date parameter. If they have no data for this quarter I want to still show the quarter show 0 for the number.
I created this simple example. If I see someone how I can integrate this logic in what I do.
SQL for the test data:
create the table bunch_of_codes
(id_code number (12) primary key,)
Description varchar2 (10));
insert into bunch_of_codes
values (1, 'APPLE');
insert into bunch_of_codes
values (2, 'ORANGE');
insert into bunch_of_codes
values (3, 'GRAPE');
create the table bunch_of_data
(id_code, number (12),)
date of activity_date,
CONSTRAINT data_id_code
FOREIGN KEY (id_code) REFERENCES bunch_of_codes (id_code));
INSERT INTO bunch_of_data
VALUES (1, to_date('4/12/2011','MM/DD/YYYY'));
INSERT INTO bunch_of_data
VALUES (1, to_date('6/1/2011','MM/DD/YYYY'));
INSERT INTO bunch_of_data
VALUES (3, to_date('1/15/2011','MM/DD/YYYY'));
INSERT INTO bunch_of_data
VALUES (3, to_date('4/17/2011','MM/DD/YYYY'));
INSERT INTO bunch_of_data
VALUES (3, to_date('11/11/2011','MM/DD/YYYY'));
COMMIT;
What I see when I run the SQL statement is:
DESCRIPTION QUARTER COUNTY
----------- ------- -----
APPLE 1 0
2 2 APPLE
APPLE 3 0
APPLE 4 0
1 1 GRAPE
1 2 GRAPES
GRAPES 3 0
4 1 GRAPE
ORANGE 1 0
ORANGE 2-0
ORANGE 3 0
ORANGE 4 0
I need each printed code without worrying if it was not used. If it has not been used, I want to still see each quarter but show 0 for count.
For this example, I can run this SQL to join the data:
Select c.description,
to_char(d.activity_date,'Q') quarter,
Count County (d.id_code)
of bunch_of_codes c,.
bunch_of_data d
where c.id_code = d.id_code
C.description group, to_char(d.activity_date,'Q')
order of description, quarter
But if it is not no matter how much detail for the quarter then I don't get a row of data. I tried all sorts of things, but nothing seems to work.
Please help if you have any ideas.Hi MLBrown,
Here's a query that gives what you asked.
Note: My table bunch_of_data has three lines that you have published, more a fourth line (the activity_date of this row is April 12, 2010, in the format DD-MON-YYYY).
To account for the response you gave to the question of Etbin, a column Y (for data year) is included in the output. In this output, there is for the year, Q for the quarter and the total for the count.SQL> select * from bunch_of_codes; ID_CODE DESCRIPTION ---------- ----------- 1 APPLE 2 ORANGE 3 GRAPE SQL> select * from bunch_of_data; ID_CODE ACTIVITY_DATE ---------- --------------- 1 12-APR-2010 1 12-APR-2011 1 01-JUN-2011 3 15-JAN-2011 3 17-APR-2011 3 11-NOV-2011 6 rows selected. SQL> with a as(select mi + level - 1 as y 2 from (select min(extract(year from activity_date)) mi, 3 max(extract(year from activity_date)) ma 4 from bunch_of_data 5 ) 6 connect by level <= ma - mi + 1 7 ), 8 qt as(select '1' q from dual 9 union all 10 select '2' from dual 11 union all 12 select '3' from dual 13 union all 14 select '4' from dual), 15 allt as(select b.id_code,b.description,a.y, qt.q as q 16 from bunch_of_codes b,a,qt 17 ), 18 temp as(select id_code,y,q,count(1) co 19 from (select bd.id_code,extract(year from bd.activity_date) y, 20 to_char(bd.activity_date,'Q') q 21 from bunch_of_data bd) 22 group by id_code, y,q) 23 select allt.id_code,allt.description,allt.y,allt.q,nvl(co,0) total 24 from allt,temp 25 where allt.id_code =temp.id_code(+) 26 and allt.y=temp.y(+) 27 and allt.q=temp.q(+) 28 order by allt.id_code, allt.y, allt.q; ID_CODE DESCRIPTION Y Q TOTAL ---------- ----------- ---------- - ---------- 1 APPLE 2010 1 0 1 APPLE 2010 2 1 1 APPLE 2010 3 0 1 APPLE 2010 4 0 1 APPLE 2011 1 0 1 APPLE 2011 2 2 1 APPLE 2011 3 0 1 APPLE 2011 4 0 2 ORANGE 2010 1 0 2 ORANGE 2010 2 0 2 ORANGE 2010 3 0 ID_CODE DESCRIPTION Y Q TOTAL ---------- ----------- ---------- - ---------- 2 ORANGE 2010 4 0 2 ORANGE 2011 1 0 2 ORANGE 2011 2 0 2 ORANGE 2011 3 0 2 ORANGE 2011 4 0 3 GRAPE 2010 1 0 3 GRAPE 2010 2 0 3 GRAPE 2010 3 0 3 GRAPE 2010 4 0 3 GRAPE 2011 1 1 3 GRAPE 2011 2 1 ID_CODE DESCRIPTION Y Q TOTAL ---------- ----------- ---------- - ---------- 3 GRAPE 2011 3 0 3 GRAPE 2011 4 1 24 rows selected. SQL>
Edited by: Manguilibe Jan 28 KAO. 2012 01:06
-
Recovering data using SQL SERVER
Hello
We migrated an environment where Oracle has been store relational data, to one where it is SQLSERVER. I'm trying to load the relational source data into Essbase using rule files. (Nothing fancy) We are on 11.1.2.1
My rule file Essbase, which in SQL embedded in it, returns the numeric columns apparently valid, but rejects essbase each records as if the numerical value was a value of text, for example, he says "Member 12345.67890' not found.
View SQL SERVER sets the numeric columns (Numeric (38.5), null).
Someone at - he met before & can help?
Thank youYou must validate your definition of the rule of load, something pushed and charge State treats the data as members of a dimension column.
-
Copy data using the MDX query.
Hi all
I use the Version 11.1.2 Essbse now I want to copy my data from a component of other component based on their UDA and erase this component particularly in ASO Cube using the MDX query.
For example:
I have my data in 'Part No' now I want to copy the data to based on their UDA Component1.
Thank you
Mickayou will need to use a custom or "procedural" calculation You can find information about it at http://download.oracle.com/docs/cd/E17236_01/epm.1112/esb_tech_ref/maxl_excalc_as.html
-
Extract data using SQL Expression
Hello, I created an intermediate table and just realized that I need some new additional fields.
Should I create them in the scene or in the target table?
I want to use the SQL COUNT expression to fill these new data sources published, fields
but do not know exactly how do. I'm a little amateur.
Thank you.You should check the analytical functions:
http://www.orafaq.com/node/55
-
How to return the value 0 for no data using the County?
Hi all
I used this query to count the number of records for each month of the year:
SELECT DISTINCT COUNT (I.information_sid) COUNT, TO_DATE (TO_CHAR (INSERT_DATE, 'MM'), 'MM') MONTH
INFORMATION I
TO_DATE GROUP (TO_CHAR (INSERT_DATE, 'MM'), 'MM')
ORDER BY TO_DATE (TO_CHAR (INSERT_DATE, 'MM'), 'MM')
But this code returns no value for months without data
I want to return the value '0' for any month of data. How, please?
Note: I use reports 6i.Maybe this?
SELECT SUM(CNT_REC) CNT_REC, MONTH FROM ( SELECT COUNT(I.information_sid) CNT_REC, TO_DATE(TO_CHAR(INSERT_DATE,'MM'),'MM') MONTH FROM INFORMATIONS I GROUP BY TO_DATE(TO_CHAR(INSERT_DATE,'MM'),'MM') UNION ALL SELECT 0, LPAD(ROWNUM,2,0) FROM ALL_OBJECTS WHERE ROWNUM <= 12 ) GROUP BY MONTH ORDER BY MONTH
No need to SEPARATE during the use of GROUP BY.
-Clément
-
Importing data using SQL loader.
Hi all
I'm trying to import data from a txt file. I have created a CTL and the bat which I include below.
CTL file
DATALOAD DATA TRUNCATE INTO TABLE danint.VOIP FIELDS TERMINATED BY ',' TRAILING NULLCOLS ( destination INTEGER EXTERNAL destination_group INTEGER EXTERNAL country CHAR, description CHAR, off_peak_period INTEGER EXTERNAL first_interval INTEGER EXTERNAL next_interval FLOAT EXTERNAL, first_price DECIMAL EXTERNAL next_price DECIMAL EXTERNAL off_peak_first_interval DECIMAL EXTERNAL off_peak_next_interval DECIMAL EXTERNAL off_peak_first_price DECIMAL EXTERNAL payback_rate DECIMAL EXTERNAL forbidden INTEGER EXTERNAL hidden INTEGER EXTERNAL discontinued INTEGER EXTERNAL effective_from DATE 'DD/MM/YYYY', formula INTEGER EXTERNAL report_date DATE 'DD/MM/YYYY' )
BAT FILE995,,GEORGIA,Proper,,1,1,0.0795,0.0795,1,1,0.0795,0.0795 995122,,GEORGIA,Sukhumi proper,,1,1,0.0795,0.0795,1,1,0.0795,0.0795 9953,,GEORGIA,proper other,,1,1,0.0795,0.0795,1,1,0.0795,0.0795 99532,,GEORGIA,Tblisi,,1,1,0.0668,0.0668,1,1,0.0668,0.0668 9953226,,GEORGIA,Mobile Others,,1,1,0.0795,0.0795,1,1,0.0795,0.0795 9953297,,GEORGIA,Tbilisi city,,1,1,0.0795,0.0795,1,1,0.0795,0.0795 99544,,GEORGIA,Abkhazia,,1,1,0.3,0.3,1,1,0.3,0.3 99555,,GEORGIA,Mobile Geocell,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99557,,GEORGIA,Mobile Geocell,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99558,,GEORGIA,Mobile Geocell,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99571,,GEORGIA,Mobile Others,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99574,,GEORGIA,Mobile Others,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99577,,GEORGIA,Mobile,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99577,,GEORGIA,Mobile,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99579,,GEORGIA,Mobile Others,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 9959,,GEORGIA,Mobile,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99593,,GEORGIA,Mobile,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99597,,GEORGIA,Mobile,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 99599,,GEORGIA,Mobile,,1,1,0.1528,0.1528,1,1,0.1528,0.1528 30,,GREECE,Proper,,1,1,0.019,0.019,1,1,0.019,0.019
TABLEREM LOADING VOIP Prices sqlldr system/manager@test control=C:\Library\Control\VOIP.CTL data=C:\Library\Data\VOIP.txt log=C:\Library\Log\VOIP.log rows=10000 PAUSE
I get the following error message, but the message seems meaningless, as the comma are in fact. Any ideas?-- Create table create table VOIP ( destination NUMBER, destination_group NUMBER, country VARCHAR2(65), description VARCHAR2(60), off_peak_period NUMBER, first_interval NUMBER, next_interval NUMBER, first_price NUMBER, next_price NUMBER, off_peak_first_interval NUMBER, off_peak_next_interval NUMBER, off_peak_first_price NUMBER, off_peak_next_price NUMBER, payback_rate NUMBER, forbidden NUMBER, hidden NUMBER, discontinued NUMBER, effective_from DATE, formula NUMBER, report_date DATE ) tablespace TEST pctfree 10 initrans 1 maxtrans 255 storage ( initial 560M next 1M minextents 1 maxextents unlimited );
ORA-28002: the password will expire in 6 days
SQL * Loader-350: error of syntax in line 7.
Expected ', 'or') ', found 'destination_group '.
destination_group INTEGER EXTERNALYou are missing commas in the CTL file
HTH
Srini
Maybe you are looking for
-
My reminder of firefox does not appear in my status bar and I can not access
I have the point of firefox on my computer that opens to remind of scheduled events. It appears approximately every 30 minutes, but the small, I used to have at the bottom of my screen on the right toolbar icon not more and I can not access my calend
-
Will be copied files Windows Vista 32 bit Media collection if the upgrade to Windows 7 64 bit?
I currently have a Vista Home Premium 32, 6 Windows version and I'm looking to switch to Windows 7.__If I read, and buy the upgrade, will my Windows Media files from the collection copied to version 7 if I want to select the 64-bit? Questions about W
-
Why can't copy and paste pictures into folders "Images".
Any time that I try to copy an image for internet and paste them to my 'Images' folder, it won't let me paste
-
Event ID 5 to start when I start my computer
My product is not there... the only product of Kaspersky, I ran, is Kaspersky Virus Removal Tool, which is a standalone program.
-
need names of .dll files that contain icons
I have win7 Home premium. I'm looking to change an icon for one of my pieces of freeware. Philippe, when I go through the process of 'change icon' I get only one choice, which is the icon even in use. I used to have a couple of files .dll residues ma