SQL & PL/SQL :: How To Get Data From Multiple Table In A Cursor
Jun 1, 2010is there any query using which i can fetch the data from multiple table in a cursor. i dont want to use separate cursor.
View 3 Repliesis there any query using which i can fetch the data from multiple table in a cursor. i dont want to use separate cursor.
View 3 RepliesI have a table with a BLOB column ;
I want read data from table and insert to another table with a cursor
My code is :
procedure read_data is
cursor get_data is
select id,image from picture1;
id1 number;
pic blob;
begin
open get_data;
[code]....
when I run form , error FRM-40734 occurred
error in line " fetch .... "
i need to enter multiple languages data into a table.
i did configuration assistant with nls_charecterset=AL32UTF8
but it didn't store other languages strings like hindi,french,japan...etc
I have a table where each record has a numerical x-coordinate value as one of its fields. I want to loop through a group of the records that have another field in common in a given order. In a nested loop, I would like to subtract the coordinate of the outer loop from the coordinate of the inner loop for all records in the inner loop that appear later in the sequence. The result is a list of the distances between all coordinates.
Example:
x-coordinate
3
4
6
7
It would look like this:
4-3, 6-3, 7-3,
6-4, 7-4,
7-6
I can do this using two nested cursors that select the same thing basically. But the table being selected from is pretty large and it takes forever to keep selecting from the huge table when the inner cursor could just copy the results of the other cursor and repeatedly iterate through them.
Is it possible to copy a cursor's results into another cursor or reset the cursor index back to the beginning so that it doesn't have to do the select statement every time?
I have a form with 2 datablocks, datablock 1 is the datablock in which I want to write data too that table within the database.
datablock 1(which i want to insert data too) is:
In forms layout this simply consist of a display box at the top of the screen which is populated by a LOV from another table within the database. The lov value selected will then be placed in the appropriate field of the table. For example the LOV contains a list of every single car make there is. i.e. Renault, Ford, Vauxhall etc
datablock 2 (in which i just want to read data from, and write the data to the table used in datablock1) is:
Below this is my second datablock, which on the trigger 'on-new-form-instance' reads data from an already existing table and displays a list of every single make of car ie, focus, clio, megane, astra etc (tabular layout displaying 12 records at a time). Beside these car models will be a checkbox which is a non database item, originally unticked.
What I want to do is the user selects a car type from the top LOV say Renault for example, then they will go down the list of car models checking each and every model of car Renault makes, i.e clio, megane, etc when these models are all checked, and the user clicks save, it will insert into my table (which is the top datablock) the car which was selected From the LOV at the top, plus each and every car model which has a checkbox checked. So for example, say the user selects Renault from the top LOV and checks models clio, megane, laguna. There should be 3 entries in the table consisting of:
Renault, clio
Renault, Megane
Renault, Laguna
Now I have got it to work partially, in the fact that if I load the screen, select my car type and then multiple models that it will add 1 car type and model to the database but not the others which I have checked. I think I need it to go down each row and check if the value is ticked or something like that? using row id or something?
Here is the code I have so far: Just so you know car_model is the name of my table used as my second datablock, contains all car models as u would expect.
BEGIN
if :model_chkbox = 'Y'THEN
v_model_id := :car_model.id;
INSERT INTO NOTE_ACCESS_DEFAULT (car_type, model_id)
VALUES (:car_type, v_model_id);
end if;
EXCEPTION
WHEN OTHERS THEN
MESSAGE('SQLERRM: ' || SQLERRM);
END;
Another option was to do a loop and go through each record and see if it is checked, not sure how I would implement this but it does seem like a very inefficient way to do such a task, perhaps it would be something to do with when a checkbox is ticked stamp it or something.
I need to write a script which copies 4 col data from one table to another table. there are three tables
cwat_curr_mst and cwat_assigned_customer and cwat_assignment_mst.
Cwat curr mst has PK curr_id and cwat_assigned_customer has PK assignment_id.
Also cwat_assigned_customer has customer_id.
In cwat_assignment_mst has Curr_id and Assignment_ID.
cwat_curr_mst and cwat_assigned_customer tables has 4 cols in common
they are
ASRT_SNM_NO, SNM_NO, FLORIDA_NO, CBRN_NO.
So from curr_mst all these 4 cols data needs to come/copy into cwat_assigned_customer.
can we delete multiples table through the single query?
suppose we have 2 table first one is emp and second is client
i want delete all data from emp and client through the single line query
i have two tables test1 and test2. i want to update the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.
I have a code written as follows :
DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
[code].......
The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].
It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
I am not sure what is the exact problem when we want to update multiple columns of different tables.
how to insert the data in multiple bases( Same table structure in different bases) using the multiple database links?
View 4 Replies View RelatedI am attempting to select back multiple values for a specific key on one row. See the example below. I have been able to use the sys_connect_by_path to combine the fields into one field but I am unable to assign them to fields of their own. See the example below
TABLE DETAILS:
Policy id plan name
111 A Plan
111 B Plan
111 Z Plan
112 A Plan
112 Z Plan
My desired result is to be able to show the output as follows
Policy ID Plan_1 Plan_2 Plan_3
111 A Plan B Plan Z PLan
112 A Plan Z PLan
when i run this code i get a invalid number error
create or replace
PROCEDURE BULK_REJECT(System_name VARCHAR2)
as
MDM_run_id VARCHAR2(14);
V_sql clob;
cursor Job_metric is
select rowid_job,system_name, table_display_name, run_status
[code]....
I want to fetch the data through the cursor and cursor is getting the value of group_code through the variable 'a'. but when i am writing the code like this it is not coming.
My code is like this :
declare
a varchar2(400):='';
cursor c1 is select ref_no,ref_code,company_id from stock_detail where company_id=:global.company_id
[Code]....
I have a table with more than 200 columns. I would like to declare a cursor to query all the columns for each record (if c1%found then ....). As the table has more than 200 columns is it a good practice to declare a cursor
View 7 Replies View Relatedi want to use cursor to get data from db to "control block "(db item =no ) this data had where clause depend on item on other block
this my code :
declare
cursor get_sol is
select SOL_STEP,PROB_ID
from MI_SOLUTION
where PROB_ID=:MI_FORM_PROB.PROB_ID;
begin
go_block('control');
[code]......
when am using when_validate_item trigger error raise :
FRM-40737:Illegal restricted procedure next_record in when_validate_item
that's the trigger ? or how to solve ? in case of execute query in what trigger i will write the same code to get data in case of execute query by user .
I'm needing to pull data into a cursor, then split this data into 3 different tables, each having the same number of rows and a select number of columns from the original. i can pull the data, but then i can only access it one row at a time via FETCH, then i can't load into the 3 new CURSORS one row at a time.
View 11 Replies View RelatedSELECT
contgrp_num,
cpgrp_desc,
strategy_id,
perftyp_cd,
stiertyp_id_calcbase,
stiertyp_id,
cpgrp_flg_aggr,
pgrptyp_cd
[Code]..
The above query is not returning any value. But, when I put this within a begin-end block, its fetching data.
why its not returning any data without the begin-end block.
The entire code has an outer begin-end block within which the cursor is also defined.
My cursor went to the exception when its got the error " ORA-01403: no data found"
But my cursor need to run even though it got the error " ORA-01403: no data found"...This is my exception part
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (c1rec);
DBMS_OUTPUT.put_line (SQLCODE);
DBMS_OUTPUT.put_line (SQLERRM);
-- RETURN NULL;
-- code change added as part of GCA642 -- END
END get_geo_test1;
have a cursor populating an array displaying data not found. As usual with these things, a few displays normally show the offending row but in this case, the display is showing data so I dont understand it. Ive inherited this and shortened it a bit to display whats going on.
declare
v_errno number;
cursor c1 is <really big sql statement>;
[Code]...
now we come to run it, I tried first to see was it data and then I outputted the iteration itself. the first iteration is fine, the second iteration shows the column in the array has data but Im still getting the 01403.
the error can be generated even displaying the array value. If the array wasnt populated I wouldnt expect the col value to display in the error.
exec my_proc;
iteration : 1, col1 value : 43
Error iteration : 2, col1 value : 43);
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "my_proc", line 34
ORA-06512: at line 1
We have to load 10 million rows in a table from another table based on the multiple joins. How much tablespace size we allocate to the table and for performance point of view how much should be the SGA size.
View 11 Replies View Relatedi am trying to fetch the cursor returned from a stored procedure and insert into a physical table. but i am unable to populate the table. below is how my code looks.
declare
p_out sysadm.CGF_PKG_REFCUR.rcDataCursor;
a table1.node%TYPE;
b table1.acct%TYPE;
c table1.descr%TYPE;
[code]......
In the above, stored_proc is the stored procedure from OLAP database. Above code i am executing is from EPM database.
p_out returns a result set of (select a,b,c from table2).
I am trying to get the result set from OLAP database and populate a table in the EPM database.
I am trying to merge into test table using a cursor. If the contract number in the test table matches with the contract number from the cursor then i need to update the creation_date else i need to insert values from the cursor into the test table.
MERGE INTO test
USING cursortest
ON (i.contract_number = test.contract_number)
WHEN MATCHED THEN
[code]......
I want pass the tablename to cursor. The tablename will be a dyanamic one, as we have the data in different sources tables[multiple systems - all systems will provide the data dump to oracle] with same set of columns.
I have inserted all the tablenames in a parameter table and based on conditions daat should be fethced from each system.
I need to pass the tablename to the cursor to fetech the coloumn list from the table(the table that is passed as parametr).
My objective is to select the table names from all_tables table where the number of rows is greater than zero. Use this table name and choose a single record from those tables. Below is the code i am trying. but it throws me an error as
Quote:
ERROR at line 9:
ORA-06550: line 9, column 24:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 9, column 2:
PL/SQL: SQL Statement ignored
DECLARE
CURSOR c1 IS
SELECT owner
||'.'
||table_name table_name
[code]........
I am working on a POC. The goal is to do a
select * from function('input')
where the function dynamically returns different tables.
I have gotten to the point where I can return the cursor but I cannot format it as a table to use in the query. It return's it as XML. This is my function:
create or replace
FUNCTION CAMS_FUN_GEN_REPORTS(PARAM1 IN VARCHAR2) RETURN SYS_refCURSOR AS
BEGIN
DECLARE
p_recordset SYS_refCURSOR;
begin
OPEN p_recordset FOR 'SELECT * from STATS_FLAGGED_TOTALS_ME';
RETURN p_recordset;
END;
END CAMS_FUN_GEN_REPORTS;
This is my query:
select * from CAMS_FUN_GEN_REPORTS('')
So normally you would do this
select * from TABLE(CAMS_FUN_GEN_REPORTS('') as tabletype)
But I will never know the end result table as it will be dynamic so I have to find a way to cast the result of the function into a new table I can select on.
I have looked into pipe lining also but from what I can tell you still need to know the table definition. Which I can't know from the client side. The server will control the 'routing' and thus the end result of the select.
While reading data from collection variable using ref cursor . I am getting the below two errors.
PLS-00382:Expression is of wrong type
ORA-22905 Cannot access rows from a non-nested table item.
CREATE OR REPLACE PACKAGE APPS_GLOBAL.GIIOMEGAORDERLIST
AS
TYPE BU_LIST_TYPE IS TABLE OF VARCHAR(50);
TYPE OFFER_DETAIL IS RECORD
(
GII_BU VARCHAR(50),
GII_OFFER NUMBER,
[code]........
I want to create table by using the ref cursor results which is returned by the function / procedure. We need achieve this simple query .
View 17 Replies View Relatedexample to use temp table in function with only ref cursor.
I need to use for the reporting purpose.
I have made changes in my form
1st step:-
for Inserting records created below cursor, records are inserted and I can see on my screen (form) also.
DECLARE
CURSOR InvestIS
select * from Tempinvest;
BEGIN
OPEN Invest;
GO_BLOCK('ReturnReport');
last_record;
[code]......
2nd step:-
Updating records
I wan to update some columns in this table so I created a 2nd cursor to update records but this cursor is not working accordingly. my requirement is: before Update first of all Find inv_co_code & inv_fnd_code when find then update column Redunits
2nd Cursor
DECLARE
ddate date; refdate date; co_code number; co_name varchar2(50); fnd_code number; fnd_name varchar2(50); units number; amount number; stat varchar2(1);
CURSOR bnr IS
select Ddate,refdate,co_code,co_name,fnd_code,fnd_name,units,amount,stat from (
select inv_date DDate,Vdate RefDate,inv_co_code Co_code,inv_co_name Co_name,inv_fnd_code Fnd_code,inv_fnd_name Fnd_name,
inv_nofu Units,inv_amount Amount,Status Stat from (
------------- Bonus -------------------
select inv_date,vdate,inv_co_code,inv_co_name,inv_fnd_code,inv_fnd_name,inv_nofu,Inv_amount,inv_uprice,'B' Status from investment
where code is null and inv_date <= :dd1
---------------- Redemption --------------
Union All
select red_date,null,red_co_code,red_co_name,red_fnd_code,red_fnd_name,red_nofu,red_amount,red_uprice,'R' Status from redemption
where red_date <= :dd1
))
where co_code = 13 and fnd_code = 1
order by co_code,fnd_code,ddate ;
------------------------------------------
vddateddate%type;
vrefdate refdate%type;
vco_codeco_code%type;
vco_nameco_name%type;
[code].......
We had an issue with a PL/SQL package taking hours to run as a concurrent program. Database version is 10.2.0.4.0, running on Linux x86 64-bit. A tkprof'd trace file revealed the problem SQL statement to be a cursor. This one SQL statement would run for 3+ hours. I copied the SQL statement and ran it in TOAD and it completed in seconds, returning the exact same result set. To resolve the issue in the PL/SQL package I created a global temp table and ran the exact same SQL statement as an INSERT into the global temp table.
Again, instead of hours, the SQL statement completes in seconds. If I revert the change, it goes back to taking hours. I've attached the relevant sections of the tkprof showing the two SQL statements (identical other than the insert in front of one) and the resulting explain plans and performance data. I've always been under the impression that a cursor was a better option than a temp table and I've never run into a situation where the same SQL statement runs so much longer when executed as a cursor.
Attached File(s)
SQL_As_Cursor.jpg ( 274.02K )
Number of downloads: 7
Explain_for_SQL_As_Cursor.jpg ( 189.43K )
Number of downloads: 4
SQL_as_Insert.jpg ( 277.38K )
Number of downloads: 4
Explain_for_SQL_As_Insert.jpg ( 180.66K )
Number of downloads: 2
I have strange problem when i try to return a ref cursor holding data from a select on a oracle global temporary table. If i iterate through the cursor , i can see the values but the function as such returns nothing through the ref cursor. I tried the temporary table as both delete on commit and preserve on commit
create or replace
PACKAGE BODY BILL AS
FUNCTION FILTERI RETURN BILL.refcursor IS
testcursor BILL.refcursor;
ttstatus INT;
iSuccess INT;
returns INT;
TruncatedSQL1 VARCHAR2(32767);
BEGIN
[code].........