Select into from 2 tables
Thanks in advance
Is it possible do a SELECT INTO from 2 tables, that is (like in Informix)
declare
rg_table1 table1%ROWTYPE;
rg_table2 table2%ROWTYPE;
BEGIN
SELECT A.*, B.* INTO rg_table1 , rg_table2
FROM table1 a, table2 B
WHERE ....
no, I don't think so....
SQL> declare
2 t1 t%rowtype;
3 s1 s%rowtype;
4 begin
5 select t.*
6 , s.*
7 into t1
8 , s1
9 from t, s
10 where rownum = 1;
11 end;
12 /
select t.*
ERROR at line 5:
ORA-06550: line 5, column 4:
PLS-00494: coercion into multiple record targets not supported
ORA-06550: line 9, column 3:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 5, column 4:
PL/SQL: SQL Statement ignored
Similar Messages
-
Select values from table%ROWTYPE variable into a cursor
I have a stored procedure which has an OUT parameter of table1%ROWTYPE.
In future we might have to add more OUT parameters of table2%ROWTYPE etc. But at any point of time only one will have values.
So instead of having table%ROWTYPE as OUT parameter, can I send these single row ( with variable values) in a cursor, so that declaration part atleast will not change.
Is it possible to select values from table%ROWTYPE variable into a cursor.
cursorOUT IS
SELECT * FROM varREC;
where varREC is table.ROWTYPE variable.
Or which is the better solution in this situation.
Thanks.SQL> var a refcursor
SQL> declare
2 bb emp%ROWTYPE;
3 begin
4 select * into bb from emp where rownum = 1;
5 open :a for select bb.ename ename, bb.empno empno from dual;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> print a
ENAME EMPNO
SMITH 7369Rgds. -
Select count(*) from table in oracle 11g with direct path read takes time
select count(*) from table takes long time, even more than couple of hours..
direct path read is the wait event which is almost is at 99%..
can u someone provide some info on this.. on solution.. thankxknowledgespring wrote:
table has millions of records... 130 millions..
select count(*) from BIG_SIZE_TABLE; --- executed in sql plus command prompt.
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 SORT (AGGREGATE)
0 TABLE ACCESS MODE: ANALYZED (FULL) OF 'BIG_SIZE_TABLE' (TABLE)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1 0.00 0.00
enq: KO - fast object checkpoint 1 0.01 0.01
Disk file operations I/O 18 0.00 0.00
direct path read 58921 0.34 418.54direct path read time waited is : 58921 total time waited: 418.54
That 418 seconds - not the hours you reported earlier. Is it possible that your connection to the database broke ?
On a typical system, by the way, you can usually turn one direct read for tablescan into 1MB, so your scan seems to have covered about 59 GB, which seems to be in the right sort of ballpark for 130M rows.
we have another query and when we test the query execution using v$sql, is_bind_sensitive =N, how to make is_bind_sensitive=Y all the time.. There is a hint /*+ bind_aware */ - I'd have to check whether or not it's documented at present. It might help.
I would be interested in hearing why you think the hint should be bind sensitive when the optimizer doesn't.
Regards
Jonathan Lewis -
Use variables in a SELECT INTO FROM command
Hi,
How do I use variables within a select into from command? I want to loop through SYS.DBA_TABLES using a cursor and count the number of rows in a
selection of tables an then insert into a cardinality table.
The count of rows will be stored in a variable called CNT, that bit is easy however I need a variable in the FROM clause because that
value changes with every iteration of the cursor.
e.g.
CNT := 0;
TN := "MyTable";
select count(*) into CNT FROM TN;
insert into cardinality (table_name, row_count) values (TN, CNT);
This is Oracle 9i and I need the row counts in a separate table as they are shipped over to a different environment for analysis purposes.
Any ideas?
Regards
Dave
Edited by: Yorky001 on Sep 15, 2010 10:32 AMHi,
Thanks for the info, unfortunately I can get neither example to work on this 9i system, could well be pilot error as I only ever get
to do any Oracle about once per year. In the first query I have tried both "user_tables" and SYS.DBA_TABLES, same result.
set serveroutput on size 1000000;
DECLARE
row_count INTEGER;
vstr VARCHAR2(500);
vstr1 VARCHAR2(500);
BEGIN
vstr := 'SELECT count(*) FROM ';
dbms_output.put_line(vstr);
FOR i IN (SELECT table_name FROM user_tables WHERE rownum < 10) LOOP
vstr1 := vstr || i.table_name;
EXECUTE IMMEDIATE vstr1
INTO row_count;
dbms_output.put_line(i.table_name || ':' || row_count);
END LOOP;
END;
This one complains about the execute immediate line.
Error report:
ORA-00933: SQL command not properly ended
ORA-06512: at line 12
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
BEGIN
FOR i IN (select
table_name,
to_number(
extractvalue(
xmltype(
dbms_xmlgen.getxml('select count(*) c from '||table_name))
,'/ROWSET/ROW/C')) count
from user_tables
where rownum<6) LOOP
dbms_output.put_line(i.table_name || ':' || i.count);
END LOOP;
END;
ORA-19206: Invalid value for query or REF CURSOR parameter
ORA-06512: at "SYS.DBMS_XMLGEN", line 121
ORA-06512: at line 1
ORA-06512: at line 2
19206. 00000 - "Invalid value for query or REF CURSOR parameter"
*Cause: The queryString argument passed to DBMS_XMLGEN.newContext was not a valid query, or REF CURSOR.
*Action: Rewrite the query so that the queryString argument is a valid query or REF CURSOR. -
How do I execute "Select count(*) from table " in OCI
Hi,
I am new to OCI and so this question may seem stupid. I would like to know how to execute the query "select count(*) from <table>" using OCI V8 functionality? Also after how do I get the result into a integer datatype? I have gone through most of the demo programs but is is of little help to me.
Thanks in advance...
Regards,
Shubhayan.Hi,
Here is sample code to give you some idea how to do it. If you want some more info let me know.
Pankaj
ub4 count;
// Prepare the statement.
char szQry = "SELECT count() FROM T1";
if(OCI_ERROR == OCIStmtPrepare(pStmthp, pErrhp, (unsigned char*)szQry, strlen(szQry), OCI_NTV_SYNTAX , OCI_DEFAULT) )
cout << "Error in OCIStmtPrepare" << endl;
exit(1);
// Bind the output parameter.
OCIDefine *pDefnpp;
if(OCI_ERROR == OCIDefineByPos ( pStmthp, &pDefnpp, pErrhp, 1,
&count, sizeof(ub4), SQLT_INT,
(dvoid *) 0, (ub2 *) 0, (ub2 *) 0,
OCI_DEFAULT) )
cout << "Error in OCIDefineByPos" << endl;
exit(1);
if(OCI_ERROR == OCIStmtExecute(pSvchp, pStmthp, pErrhp, 1, 0, NULL, NULL, OCI_DEFAULT) )
cout << "Error in OCIStmtExecute" << endl;
exit(1); -
Probel while selecting data from table
Hi,
As per my below code i want to select data from table AFKO where PLNBEZ = it_mat-matnr, and GETRI IS BLANK , but data is not comingin IT_AFKO
**********************CODE
select AUFNR RSNUM GAMNG PLNBEZ From AFKO into table it_afko for all entries in it_mat
where PLNBEZ = it_mat-matnr
and GETRI = ' '.
regards,
zafarHi,
Try below code
select AUFNR RSNUM GAMNG PLNBEZ From AFKO into table it_afko for all entries in it_mat
where PLNBEZ = it_mat-matnr
and GETRI = '00000000'.
Hope you need the records for which GETRI is not updated.
Regards
Vinod -
Select data from table not in another table
Hi,
I want to select data from table A which is not in table B.
Currently I am doing:
select
snoA,
nameA,
dobA
from A
where snoA not in
(select snoB from A, B
where snoA = snoB
and nameA = nameB)
But above is very slow.
Can I do something like:
select
snoA,
nameA,
dobA
from A, B
where
EXCLUDE ( snoA = snoB and nameA = nameB)
Please note that I need the where condition on both the columns.
any help will be appreciated.
-- HarveyWhat are the approximate data volumes in A and B?
What is "very slow"?
What version of Oracle?
What is the query plan?
Without knowing anything about your system, my first thought would be to see if a NOT EXISTS happened to be faster for your data
SELECT snoA,
nameA,
dobA
FROM a
WHERE NOT EXISTS (
SELECT 1
FROM b
WHERE a.snoA = b.snoB
AND a.nameA = b.nameB )Of course, I'm not sure why you are joining A & B in your NOT IN subquery. It would seem like you would just need a correlated subquery, i.e.
SELECT snoA,
nameA,
dobA
FROM a
WHERE snoA NOT IN (
SELECT snoB
FROM b
WHERE a.snoA = b.snoB
AND a.nameA = b.nameB )That should be more efficient than the original query. The NOT EXISTS version may or may not be more efficient than the NOT IN depending on data volumes.
Justin -
Can a procedure select data from tables on other schemas?
Can a procedure select data from tables on other schemas?
If it is posible, which syntax should I use to identify the tables and schemas on the SELECT query?Yes , it is possible..unless the current user has the right privileges on others' db objects schema.
Now , as regards the syntax....
1) The more descriptive way is to use the format ... <owner_schema>.<obj_name>.
2) If you have declared public synonyms of other schema's objects then you can refer to them as just <obj.name>.... but the <owner_schema>.<obj_name> is not wrong.
3) If the db objects reside on another database you must have declared a db link.... then the syntax is <owner_schema>.<obj_name>@<db_link_name>.
Regards,
Simon -
Select aentries from table Z-Table for all sales order line items
Hi friends,
can anyone please explain me about the "Select entries from table Z-Table for all sales order line items".
Thanks.Moderator message - Welcome to SCN.
But
Moderator message - Please search before asking. Press F1 on SELECT and look at the FOR ALL ENTRIES addition. - post locked
Rob -
I AM TRYING TO IMPORT CHARACTERS FROM A TAB DELIMITED FILE INTO A TABLE ON LABVIEW. ONCE THE DATA IS IN THE TABLE I WANT TO BE ABLE TO SELECT INDIVIDUAL STRINGS FROM THE TABLE AND PLACE IT IN A NEW TABLE. WHEN I CLICK ON A STRING I WOULD LIKE THE SELECTED STRING TO SHOW IN A TEXT BOX LABELED 'SELECTED STEP' AFTER ALL THE SELECTED STRINGS IS IN THE TABLE I WOULD LIKE TO SAVE THE NEW TABLE AS ANOTHER SPREADSHEET -- TAB DELIMITED -- FILE, MAKING IT ACCESSIBLE TO OPEN. HERE IS WHAT I HAVE SO FAR. I CAN INPUT DATA INTO THE TABLE, BUT I CAN ONLY TRANSFER ONE STRING INTO THE TABLE I WOULD LIKE TO BE TO INPUT MULTIPLE STRINGS. ALSO WHENEVER I TRY SAVING THE FILE, IT ALWAYS SAVES A UNKNOWN FILE, HOW CAN I GET IT TO SAVE AS A SPREADSHEET FILE. THANKING ALL OF YOU IN ADVANCE FOR YOUR HELP!!!!!!
Attachments:
Selector.zip 30 KBPondered,
The question you are asking is the same one that you asked in: http://forums.ni.com/ni/board/message?board.id=170&message.id=132508#M132508, to which I supplied a revised version of the original vi you used (which was modified from the original one I supplied to an earlier thread). A couple of questions: 1) What does my latest not do that is in your question, 2) Why are you starting yet another thread about the same problem? We are here trying to help, it makes it a lot easier if you keep the same problem in the same thread, it reduces duplication of effort from those that might not have been following the previous thread(s). Those of us that don't have our "names in blue" are just doing this "for fun" (the blue names are NI employees, who may still be doing it "for fun"), and it makes it more fun if it doesn't seem (correctly or not) that our attempts are ignored. If an answer doesn't help, or seems incomplete, post a little more detail to the same thread so that the original respondent, or someone new, can provide more information, or understand your problem better.
P.M.
Message Edited by LV_Pro on 07-20-2005 01:20 PM
Putnam
Certified LabVIEW Developer
Senior Test Engineer
Currently using LV 6.1-LabVIEW 2012, RT8.5
LabVIEW Champion -
Selecting date from table of type c.
hi,
i have a field in table type c.......the field contain date in fallowing format 02.07.2007 ,if i have to write a select query for that table ,for selecting all entrie between two dates ...how can i do.....
note : date in the table is of type char.i cant change the table type it is standard.i now the lenght process.please suggest me the short formatCheck if below code can give you some lead:
PARAMETERS: p_date1 TYPE datum,
p_date2 TYPE datum.
DATA: l_date1 TYPE char10,
l_date2 TYPE char10.
START-OF-SELECTION.
CONCATENATE: p_date1+6(2) p_date1+4(2) p_date(4) INTO l_date1
SEPARATED BY '.',
p_date2+6(2) p_date2+4(2) p_date(4) INTO l_date2
SEPARATED BY '.'.
SELECT <fld1> <fld2> ...
INTO <itab>
FROM <table>
WHERE date bt (l_date1, l_date2)
AND... -
Hello abap-gurus,
I have a small problem when doing a select into an internal table. As i select and append into an internal table, the program dumps as there is not enough memory for the internal table. The SAP-table i'm selecting from is simply too big. So I'm wondering if there is a way to stop or set the max lines in the internal table to say 10000 rows? I would appreciate any example.. the statement looks like this:
SELECT * INTO l_bdcpv
FROM bdcpv
WHERE not process = 'X'
AND mestype = 'ISM_MATMAS'.
APPEND l_bdcpv TO i_bdcpv.
ENDSELECT.
Best regards BalloHI,
DATA: I_BDPCV LIKE BDPCV OCCURS 0 WITH HEADER LINE.
SELECT * FROM BDPCV INTO I_BDPCV UP TO 100 ROWS WHERE PROCESS NE 'X' AND MESTYPE = 'ISM_MATMAS'.
APPEND I_BDPCV.
ENDSELECT.
Regards
CNU -
Select statement from tables which have now been split
I used to select from 3 tables:
user, login, location
I would do:
select distinct user.id, login.computer_id, location.id as location_id
from user, login, location
where user.id = login.user_id
and login.location_id = location.id
and user.id = "manny"
but user has now been split into user1, and user2
I want to pull data where it exists from user1 or user2.
Much of the data in user1 is duplicated in user2 and vice versa, but I want to pull only one instance where it appears so that I can still get single row results of:
ID COMPUTER_ID LOCATION_ID
mannyd redstar_1 Bronx, NY
Any ideas on the query?Why would you split a single table into multiple tables with the same structure and much of the same data? That seems rather counterproductive.
I suppose you could do something like
select user.id, login.computer_id, location.id as location_id
from user1 user, login, location
where user.id = login.user_id
and login.location_id = location.id
and user.id = 'manny'
UNION
select user.id, login.computer_id, location.id as location_id
from user2 user, login, location
where user.id = login.user_id
and login.location_id = location.id
and user.id = 'manny'but that's obviously going to be much more expensive than the single-table approach...
Justin -
Select data from table where field is initial
I have table that has 10 million records.
I want to select data from this table where certain date field is blank.
*SELECT * FROM table*
INTO TABLE internal table
WHERE PSTNG_DATE = BLANK.
Does anybody know how to select data from data base table when certain field is blank.
I cont select all data once and delete which i dont want, the table is big, it will blow up app server.
thanks in advance,
Sachin
Moderator: Pls do not lock the posting instead provide me the link, its disrespecting.Respect the forum rules and common sense, and you will be respected.
"how to select data from a database table when the field is blank" is very basic, and basic questions will be locked, because they have been asked many times and you can find the answer yourself with a little effort. There is nothing disrespectful about it.
Thread locked.
Thomas -
Select LONG_RAW from table.
I've got a table with a column of long_raw datatype.
Whenever I'm selecting data from that table it displays (blob)
I need to get the data out of the column through pl/SQL
1. why is it saying (blob) when the column is of long_raw datatype?
2.Can I select the content from a long_raw column and display it?
Regards,
Satrajityou need to use the oracle built-in package UTL_RAW. here are some examples:
SQL> create table sample_long_raw
2 (long_msg long raw);
Table created.
SQL> describe sample_long_raw;
Name Null? Type
LONG_MSG LONG RAW
SQL> insert into sample_long_raw
2 values ('hello');
values ('hello')
ERROR at line 2:
ORA-01465: invalid hex number
SQL> insert into sample_long_raw
2 values (utl_raw.cast_to_raw('hello'));
1 row created.
SQL> select * from sample_long_raw;
L
6
SQL> create or replace function get_long_raw (row in rowid) return varchar2 is
2 longhold varchar2(4000);
3 begin
4 for r in (select LONG_MSG from sample_long_raw where rowid = row) loop
5 longhold := utl_raw.cast_to_varchar2(r.long_msg);
6 end loop;
7 return longhold;
8 end;
9 /
Function created.
SQL> select get_long_raw (rowid) from sample_long_raw;
GET_LONG(ROWID)
hello
SQL> hope this helps.
Maybe you are looking for
-
Manage BOBJ folder authorization with Solution Manager
Hi Expert, At first I'll speak about our landscape, it include SAP BW as DWH, BO 4.1 for WEBI reporting (it is a migration project, the universes are connected to the infocube BW) and solution manager as central system for the monitoring and authoriz
-
Export format for clips to be used in larger project.
Back in the PE2 days, I used to capture and trim a clip and "export movie" which resulted in a "DV-AVI" file. This is what I understood PE "liked" and the best format to use for import to a larger project (and it worked nicely every time). Now, in
-
More Newbie help needed please.
Hello, I am attempting to sort an array which is defined in the main method, but the array must be sorted through the use of another method. From my understanding, this is tricky, because as I found out last night, you cannot use another method from
-
Buttons stopped working! Help?!
My iPod mini completly died one day in the car. When I got home, I fooled around with it and the only button that works is the center one, which will turn it on (each time it shows the Apple logo as if it had been reset) but once it is on none of the
-
Cant open itunes says dont have apple application support
cant open itunes help