Hi,
I have a table TARGET whose structure is
seq_no number -- should be populated with sequence SEQ_TAR
fsa varchar2(10)
Table SOURCE structure is
-------------------------
fsa varchar2(10)
my requirement is
i have to insert into the TARGET table the fsa value from
SOURCE table along with the sequence number using sequence SEQ_TAR.nextval.
3 20964
Hi,
I have a table TARGET whose structure is
seq_no number -- should be populated with sequence SEQ_TAR
fsa varchar2(10)
Table SOURCE structure is
-------------------------
fsa varchar2(10)
my requirement is
i have to insert into the TARGET table the fsa value from
SOURCE table along with the sequence number using sequence SEQ_TAR.nextval.
i fear this may be a school assignment and so i dont want to do your work for you as you will not learn anything that way.
it sounds like you just want to do an insert into a table rows from another table + the sequence. you have written the code to get the sequence value so just put the 2 together. insert into ... select .... If there are restrictions to which rows you want to insert then you will need to add a where clause to the select.
i fear this may be a school assignment and so i dont want to do your work for you as you will not learn anything that way.
it sounds like you just want to do an insert into a table rows from another table + the sequence. you have written the code to get the sequence value so just put the 2 together. insert into ... select .... If there are restrictions to which rows you want to insert then you will need to add a where clause to the select.
Sorry i missed out a major part
So i'm once again giving the scenario
I have a table TARGET whose structure is
seq_no number -- should be populated with sequence SEQ_TAR
fsa varchar2(10)
rec_ct number
Table SOURCE structure is
-------------------------
fsa varchar2(10)
sal number
my requirement is
i have to insert into the TARGET table the fsa value from
SOURCE table along with the sequence number using sequence SEQ_TAR.nextval.
like -
-
insert into
-
target(seq_no,fsa,rec_ct)
-
select
-
(SEQ_TAR.nextval,
-
fsa,
-
sum(sal)
-
from source
-
group by fsa
-
)
-
this is giving me a error.
Kindly help.
Sorry i missed out a major part
So i'm once again giving the scenario
I have a table TARGET whose structure is
seq_no number -- should be populated with sequence SEQ_TAR
fsa varchar2(10)
rec_ct number
Table SOURCE structure is
-------------------------
fsa varchar2(10)
sal number
my requirement is
i have to insert into the TARGET table the fsa value from
SOURCE table along with the sequence number using sequence SEQ_TAR.nextval.
like
insert into
target(seq_no,fsa,rec_ct)
select
(SEQ_TAR.nextval,
fsa,
sum(sal)
from source
group by fsa
)
this is giving me a error.
Kindly help.
yes, makes sense, invalid syntax. The opening bracket for the second set of brackets should be in front of the select (actually the second set isnt needed). -
Elapsed: 00:00:00.59
-
[159]SQL> create table t (col1 varchar2(100));
-
-
Table created.
-
-
[159]SQL> insert into t (col1) (select 1 from dual);
-
-
1 row created.
-
-
Elapsed: 00:00:00.18
-
[159]SQL> insert into t (col1) select 1 from dual;
-
-
1 row created.
-
-
further though, your select statement should be executable without the insert portion (its a good way to test that it returns what you want as well). In your case you cant group by one field and select 2. -
Elapsed: 00:00:00.01
-
[159]SQL> drop table t;
-
-
Table dropped.
-
-
Elapsed: 00:00:01.01
-
[159]SQL> create table t (col1 number, col2 varchar2(30), col3 varchar2 (30));
-
-
Table created.
-
-
Elapsed: 00:00:00.01
-
[159]SQL> create sequence t_seq;
-
-
Sequence created.
-
-
Elapsed: 00:00:00.04
-
[159]SQL> insert into t select t_seq.nextval,dummy,dummy from dual;
-
-
1 row created.
-
-
without using some sort of grouping function like max() or min() or sum() on the other columns you end up with this error -
[159]SQL> select col1,col2,col3 from t group by col2;
-
select col1,col2,col3 from t group by col2
-
*
-
ERROR at line 1:
-
ORA-00979: not a GROUP BY expression
-
based on your requirement i dont think you need to group by anything. just insert the sequence and fsa field into the target table.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: |
last post by:
Hello,
here is the code:
<?
$a=array(1,2,3,4,5,6,7,8,9,10);
$b=array(1,3,5,7,9);
$c=array(1,1,2,2,3,3);
$d=array_count_values($b);
$e=array_count_values($c);
|
by: grumfish |
last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code:
connection = MySQLdb.connect(host="localhost", user="root", passwd="pw",
db="japanese")
cursor = connection.cursor()...
|
by: brent.ryan |
last post by:
How do I get the next int value for a column before I do an insert in
MY SQL Server 2000? I'm currently using Oracle sequence and doing
something like:
select seq.nextval from dual;
Then I...
|
by: Joshua L. San Juan |
last post by:
Hi,
I had dumped data using the command:
pg_dump -U dbowner dbname -a -t table -f table-data.sql
two tables (e.g. table1, table2).
In the first table - the correct sequence was set as can...
|
by: trint |
last post by:
This:
string strSQL2 = "INSERT INTO tblTravelDetailMember(memberId, " +
" TravelDetailUplineId, " +
" rankId, " +
" TravelDetailId, " +
" CreatedDateTime, " +
" Operator) " +
"VALUES ('" +...
|
by: Jan |
last post by:
I have a table with autoincrement unique ID plus name (required not to
be blank) and other fields.
I have a list of names in another table and would like to do insert to
the name field of the...
|
by: fatjoez |
last post by:
Hi there.
I'm trying to create a Trigger for on insert, which will be triggered upon any attempted insert into a database table item. Basically want it to say, if the attempted insert value for...
|
by: yashumrhsn |
last post by:
hi....
its very urgent.... i have a 2 tables in table1 contains 2 fields-username(text) and points(number) and table2 contains points(number) and image(attachment)
fields.... what i want is, the...
|
by: JoeKid09 |
last post by:
Hi Guys,
Thanks in advance for your help. I unpivoted a table which I want to insert into another table. Below is my script. I got an error; anyone can see where my error is.
insert into...
|
by: Phil Gsy |
last post by:
Hi i would like to add a new table (TRADE_SEQ) to my document management database which would contain a squential number in the format currentyear#### so it would start at 20100001. The next sequence...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |