using table() cursor
I created a table type in SQL by using the following code:
CREATE OR REPLACE TYPE t_number AS TABLE OF number;
Now I'm trying to refer to a procedure of this type parameter, as follows:
CREATE OR REPLACE PROCEDURE invoice_maintenance ( pt_invoice_id_in IN t_number DEFAULT t_number(0) ) IS CURSOR c_data IS SELECT * FROM TABLE WHERE id IN table(pt_invoice_id_in); BEGIN ...
but when I try to compile, I get ORA-00936: lack of expression. I also tried:
CURSOR c_data IS SELECT * FROM TABLE WHERE id IN table(cast(pt_invoice_id_in AS t_number));
But that did not help. What I'm doing wrong here? I use 11.2.0.4.
... ID WHERE IN (SELECT COLUMN_VALUE FROM table (pt_invoice_id_in));
Tags: Database
Similar Questions
-
Hi all
I would be grateful someone right me if I'm wrong. I ask the question below just for my purpose of learning.
Question - Why do we use the cursor?
Response Cursor is used to treat several lines in PL/SQL.
Or
Is used to treat a set of records from one or more tables, you can write a cursor on the table using select statement and then you can browse through all these a Recordset, and perform your required operations.
Post edited by: Muzz, I'll open another discussion to my other question. Thank you
Hello
Muzz says:
Hi all
I would be grateful someone right me if I'm wrong. I ask the question below just for my purpose of learning.
Question - When we use Procedure and Function when?
Response
When you want to run a series of DML statements then do like us and when we want to return a single value, then we use the function.
Much has been written on this subject. Start by finding some of them:
https://www.Google.com/#q=when+use+procedure+function+Oracle
read some of them and then ask a more specific question
Procedures are not just for the DML; There are a lot of things in addition to DML you can do in the procedures. For example, you can send e-mail messages, or can read and write files.
The second half of your response, 'when we want to return a single value, then we use the function', is the right of bascally. In particular, when you want to return a value that will be used in a SQL statement, you use a function.
Functions in the pipeline are a special case. A lot of what you read or you say about 'functions' means implicitly 'no Pipeline functions.
Question - Why do we use the cursor?
Response Cursor is used to treat several lines in PL/SQL.
Or
Is used to treat a set of records from one or more tables, you can write a cursor on the table using select statement and then you can browse through all these a Recordset, and perform your required operations.
You'll have best results if you start a separate thread for each separate issue. This issue is completely separate from the question on procedures
You're right that the sliders are a way to process the rowsets, which can contain 1 line or several lines.
Yes, you can use a slider to manage the rows one at a time. Do not forget that it will be less effective than the manipulation of all at once, so don't use a cursor to do something that can be done in a single SQL statement.
-
How to modify a statement "select into" how to use a cursor
The following code fails with an exception too many lines. How can I modify statement Select Into the procedure to use a cursor?
CREATE OR REPLACE PROCEDURE Track_Asset( business_date IN NUMBER DEFAULT NULL, missing_table_name OUT VARCHAR2) IS ln_business_date NUMBER; incorrectdateformat EXCEPTION; BEGIN IF business_date < 0 THEN RAISE incorrectdateformat; ELSE DECLARE ln_business_date NUMBER; BEGIN SELECT MAX(business_date) INTO ln_business_date FROM sproof ; EXCEPTION WHEN NO_DATA_FOUND THEN dbms_output.put_line('NO MATCH FOUND'); WHEN OTHERS THEN dbms_output.put_line('ORACLE ERROR :' || SQLERRM); END; DECLARE missedfeedfnd EXCEPTION; BEGIN SELECT 'Missing Value : ' || table_name INTO missing_table_name FROM ( SELECT UPPER(table_name) table_name FROM filespec WHERE data_table_name IN ('TABLE1','TABLE2','TABLE3') MINUS ( SELECT DISTINCT UPPER(first_table_name) FROM dpca WHERE business_date = ln_business_date AND first_table_name IN ('TABLE1','TABLE2','TABLE3') GROUP BY UPPER(first_table_name) UNION SELECT UPPER(first_table_name) FROM dpca WHERE business_dt_num = TO_NUMBER( SUBSTR('201111', 1, 6) || '01' ) AND first_table_name = 'TABLE4' GROUP BY UPPER(first_table_name) )); IF missing_table_name IS NOT NULL THEN dbms_output.put_line('Missing Value : '|| missing_table_name); RAISE missedfeedfnd; ELSE NULL; END IF; EXCEPTION WHEN TOO_MANY_ROWS THEN DBMS_OUTPUT.PUT_LINE (' SELECT INTO statement retrieved multiple rows'); WHEN missedfeedfnd THEN raise_application_error ( - 20003, 'Missed Feed'); END; END IF; EXCEPTION WHEN incorrectdatevalue THEN raise_application_error ( - 20001, 'Incorrect/Bad Date Entered'); END;
OK, try this - OUT param will be filled with the table names comma-separated list:
PROCEDURE Track_Asset( business_date IN NUMBER DEFAULT NULL, missing_table_name OUT VARCHAR2) ... ... cursor c_table_names is select datatablename from ( select upper(datatablename) datatablename from filespec where data_table_name in ('TABLE1','TABLE2','TABLE3' ) MINUS ( select upper(first_table_name) from dpca where business_dt_num = [-- this date is retrieved by getting the MAX(business_date) from sproof table] and fus_data_table_name in ('TABLE1','TABLE2','TABLE3' ) group by upper(first_table_name) UNION select upper(first_table_name) from dpca where business_dt_num = to_number( substr('201111',1,6) || '01' ) and first_table_name = 'TABLE4' group by upper(first_table_name) )); ... ... begin ... for rec in c_table_names loop missing_table_name := missing_table_name || rec.datatablename ||','; end loop; missing_table_name := rtim(missing_table_name , ','); ... ... end ;
HTH
Published by: user130038 on December 28, 2011 08:46
-
Hello
How to use a cursor inside a stored procedure?... does anyone know a good site that helps me learn
I make a connection where the users are created and autehnticated request
I am trying to write a stored procedure that will actually get the feedback of the page and it should check the
accountno (entry) in a table of the employer, if it exists, then it must run insert, otherwise it should be to send a number that will let me know at the end before this user is invalid and cannot register...
can someone help me get started... I'm new to oracele
Thank you
JessicaHere is a good starting point:
http://www.techonthenet.com/Oracle/cursors/declare.php
-
Using a cursor to refresh a linear ball screw in directions opposite
Hello
I have a screw linear ball run by a motor/controller configuration. I would use a cursor to essentially "shaking" the platform mounted on the screw forward or backward a certain distance. However, the controller has its own language to control the movement of the engine. For example, /1P10000R would move the engine sent 10000 steps in the positive direction and /1D10000R as a '1' would move the engine 10000 steps in the negative sense. My question is this: if I put the cursor in the range from-100 to 100 mm, how do I get the output to have a 'P' in the front for the numbers from 0 to 100 and a "D" frontfor numbers ranging from-100 to 0? I guess, basically, how the slider handle negatives? I have a vi to convert mm numbers to the steps.
Thank you.
Hi manchmal2,
using string formatting functions?
-
Hi all, I am designing a 1 page template and goes well but a bit with a problem. I am using tables and trying to put an image directly into a topic. It looks perfect in Design view, but when I go to live mode view there is a little gap/spacing. I need directly under the heading. I'll also put another image directly under the first image.
< / tbody >
< /table >
< table width = "805" border = "0" align = "center" cellpadding = "0" cellspacing = "0" >
< tbody >
< b >
< td width = "15" bgcolor = "#FBF5F6" > < table >
"< td width ="775"bgcolor ="#FBF5F6"> < shipping h1 > < img src="Our_template/images/blue-bar.jpg "width ="775"height ="10"alt =" "/ > < / h1 > < table >
< td width = "15" bgcolor = "#FBF5F6" > < table >
< /tr >
< b >
< td bgcolor = "#FBF5F6" > < table >
< td bgcolor = "#FBF5F6" > < table >
< td bgcolor = "#FBF5F6" > < table >
< /tr >
< b >
< td bgcolor = "#FBF5F6" > < table >
< td bgcolor = "#FBF5F6" > < table >
< td bgcolor = "#FBF5F6" > < table >
< /tr >
< b >
< td bgcolor = "#FBF5F6" > < table >
< td bgcolor = "#FBF5F6" > < table >
< td bgcolor = "#FBF5F6" > < table >
< /tr >
< / tbody >
< /table >
< / body >
< / html >
Rather than using the sledgehammer that Ben and mages have recommended why not use a scalpel?
Try to change this-
Expedition to the France
on this subject.
Expedition to the France
-
When to use the cursor for loop and the cursor (open, fetch, close)
Hello world
I have a small doubt about when to use the cursor for loop and when to use the cursor for loop and the cursor (open, fetch, close).
Well, I'm not the difference between implicit and explicit cursor. So please tell me how I got to know, what to use and when?
Kind regards
BS2012
Published by: BS2012 on January 29, 2013 12:15All SQLs are analyzed, stored and executed as cursors. Thus, you will always use a cursor.
The problem is that languages, such as PL/SQL, provide different interfaces to interact with the SQL cursor. As the ref, the slider interface, the interface DBMS_SQL slider interface and so on.
Each of these interfaces offers different features. For example, using the interface DBMS_SQL allows binding dynamics and dynamic recovery. The Ref Cursor interface allows your code PL/SQL pass a handle to a reference pointing to the SQL cursor, to an external client. Etc.
The fundamental reason for the use of an explicit cursor interface is mainly that you own and manage bulk made extraction output provided by PL/SQL cursor.
With a cursor FOR , the motor loop of PL/SQL optimize the loop by extracting block a 100 lines both. However, you cannot access this collection in bulk directly inside the loop.
With an explicit cursor interface, you specify the size of the extraction in bulk via the clause LIMIT , and you set the variable of collection to use. This allows you to use the collection directly variable inside the loop.
However, the need to do - code manually in bulk collection - rarely occur in the daily programs in PL/SQL. A line of treatment is both slow and not well fits. And even if your bulk code collects lines, these lines must still be processed one at a time in your code. It is much more efficient and scalable rather write SQL code, and make the engine SQL the line of treatment for you.
-
CURRENT OF refuses to use my cursor - why?
On Oracle 11.2
Gives this error:create or replace procedure example is row TABLE1%ROWTYPE; c1 sys_refcursor; BEGIN open c1 for SELECT * from TABLE1 where foo = 1 order by prim_key FOR UPDATE SKIP LOCKED; LOOP FETCH c1 INTO row; EXIT WHEN c1%NOTFOUND; UPDATE TABLE1 SET bar = 2 WHERE CURRENT OF c1; END LOOP; CLOSE c1; END; /
What's wrong? I guess it's something minor that I neglected.LINE/COL ERROR -------- ----------------------------------------------------------------- 11/4 PL/SQL: SQL Statement ignored 13/21 PL/SQL: ORA-00904: : invalid identifier 13/21 PLS-00413: identifier in CURRENT OF clause is not a cursor name
Kind regards
Davidxerces8 wrote:
If I use a slider like this explicit:
Is it in terms of the order of execution as if with aYes, and I see no reason to use ref cursor.
SY.
-
Selection of data with or without the use of cursors in procedures
Hello
If we are able to access the data without using a cursor as shown below in a way:
CREATE OR REPLACE PROCEDURE tmr_exception
IS
x LINK_STATUS. COUNTRY_CODE % TYPE;
BEGIN
SELECT COUNTRY_CODE LINK_STATUS x;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
dbms_output.put_line (' too many lines).
WHILE OTHERS THEN
dbms_output.put_line ("' another problem");
END tmr_exception;
*/*
So what is useful in the use of explicit cursors?(1) SELECT... Return exactly 1 row. If you try to deal with several rows of data, you will need another construction.
(2) A SELECT... INTO opens a cursor. He has simply done implicitly. Just like
BEGIN FOR emp_cur IN (SELECT * FROM emp) LOOP <
> END LOOP; END; Opens an implicit cursor.
(3) no implicit and explicit cursors these days are generally useful when you do treatment in bulk and you want to extract the data in a local collection.
Justin
Published by: Justin Cave on October 9, 2010 20:17
(4) oh and you would never have in real code catch an exception and do nothing else than calling DBMS_OUTPUT. It's a quick way to produce a totally unmanageable code.
-
Using a cursor to reference in a loop for.
I have a procedure with a few loops for nested that finds consecutive intervals with different ranges of entry into force. It looks something like this.
.. .cursor for loops are nice and clean, do not have to worry about pick... works perfectly.declare cursor c1 (p1 in date, p2 in date, p3 in date) select col1,col2,col3,col4 from a_table where col1 = p1 and p2 between col2 and col3..(more conditions)..; cursor c2 (p1 in date, p2 in date, p3 in date) select col1,col2,col3,col4 from a_table where col1 = p1 and p2 between col2 and col3..(more conditions)..; cursor c3 (p1 in date, p2 in date, p3 in date) select col1,col2,col3,col4 from a_table where col1 = p1 and p2 between col2 and col3..(more conditions)..; begin for x1 in c1(start1, start2, start3) loop --print stuff from x1.col1 x1.col2 x1.col3 x1.col4 for x2 in c2(x1.col4, x1.col2, x1.col3) loop --print stuff from x2.col1 x2.col2 x2.col3 x2.col4 for x3 in c3(x2.col4, x2.col2, x2.col3) loop --print stuff from x3.col1 x3.col2 x3.col3 x3.col4 end loop; end loop; end loop; end; /
But I don't like that I have 3 sliders with the same exact query. I would rather define it only once if possible. I tried to do it with the ref Cursor, but it looks like I can't use ref Cursor in a for loop in the same way you can with a plain ol' slider.
Is there a way to get what I'm doing? A single cursor definition reused within nested for loops without worrying about opening/extraction/closing anything?DylanB123 wrote:
For some reason any I Although pl/sql did not support recursion. Maybe it's the ticket.
>For some reason any I Although pl/sql did not support recursion. Maybe it's the ticket. PL/SQL doesn't support recursion, but it is allowed. You can do it, but you're on your own to make it work :)
-
Difference between USR and that uses tables from UPA_USR
Hello
I just want to know something about USR and uses tables of UPA_USR. It seems that these two table stores the same data. What is the purpose od UPA_USR table?
Thank you
MK
Published by: user601746 on November 27, 2009 02:20Hi MK.
UPA stands for verification of the user profile. All UPA * tables store audit data associated with the user rights, the group memberships. UPA_USR is one that stored audit of user profile data. It's the parent table, and he has a child table called UPA_FIELDS. For each user profile update there will be a single line in UPA_USR and for each field has changed there will be an entry in table UPA_FIELDS for the UPA_USR_KEY in the UPA_USR table. Also at any time there is a line in the table UPA_USR with UPA_USR_EFF_TO_DATE with a NULL value, indicating that it represents the current user profile.
UPA is the table that stores the snapshot of the data for the user that includes the user profile, resource, and group memberships. It also features a column called DELTA, which is indeed a delta of changes that happened.
Concerning
YMI -
Problems using trigger cursor query and post.
Hello
I use a block non-base of data/model to query records in a database block. My form has a point text 'report No.' that will be used to enter a valid number of reports. Based on the number of this report, I hit a button to search (also from the same block of data non-base) to view records that have this "report No.' in the database block. I think I need to use a cursor in a post for this request but I am not able to operate :( Help, please! I really need this point that nobody is helping me to work:(la figure)
My search button - button the trigger:
DECLARE
NUMBER OF CHOICES;
BEGIN
IF: DUMMY_BLK. NWTFR IS NULL THEN
ALERTS. STOP_ALERT ("Start Date is required", choice);
RAISE FORM_TRIGGER_FAILURE;
END IF;
go_block ('T_VESSEL_BLK');
execute_query;
END;
My post_query:
DECLARE
cursor vessel_cur is
SELECT VES_RPTNO, VES_SENDER, VES_SENDER_MBOX, VES_INTCTRL_REF, VES_NAME, VES_VOYNO, VES_ARRDT
SHIP
WHERE VES_RPTNO =: DUMMY_BLK. NWTFR;
var_mot vessel_cur % ROWTYPE;
BEGIN
Open vessel_cur;
LOOP
extract the vessel_cur in var_mot;
EXIT WHEN vessel_cur % NOTFOUND;
END LOOP;
close vessel_cur;
END;instead of execute_query you do now
Why do you offer me something like that? Replacing the standard behavior that you use forms must be well thought out, because you have to manage a large number of possible problems. You can easily get the desired using the standard logic behavior:
-Create an item number IT_COUNT in a control block, assign 'calculation mode' to 'Summary', 'Synthesis function' to 'Count' "Down block" and your DB-bloc and "just point' a null-element not contained in this block. Last series the block 'Interrogate all folders' to 'Yes' in your databaseblock. Now, in your code, you can just checkl the value of this element of count, as
... EXECUTE_QUERY; IF :BL_CONTROL.IT_COUNT=0 THEN error END IF;
-
How to choose the maximum value in a column of a table by using the cursor and iteration
Hello everyone
I have a table loan_detail
and a column inside loan_amount
now I want to take the values in this table with the cursor, then using iteration that I want to take a max value of him using this slider
Here is my table
I could make using the concepts of single loop, but when I tried to do by using the slider I wasn't able to do.LOAN_AMOUNT 100 200 300 400 500 5600 700
Concerning
ProstYou can get the maximum value for a particular column in SQL, PLSQL needn't; Always avoid PLSQL so you can do it in SQL. But always as an example:
declare
number of Temp: = 0;
Start
for news in some loan_amt of loan_detail
loop
If (temp
end if;
end loop;
dbms_output.put_line (temp);
end;Edited by: Mahanam January 5, 2011 03:11
-
How to use a cursor to turn on or turn off the lights
Hi guys. I'm quite familiar with Labview now, but can't seen to get my head around this problem. I have a slider that is numbered from 1 to 10. under the cursor, I inserted 10 LED lights. My sister in order to use the slider to turn off the lights and. for an example, when I set the cursor to one, at the far left light should go. When I put the cursor at 2, the first witness should go second light next to him, and the model continues. I thought to use the number of table boolean, but it doesn't seem to do the trick. could you please help me. I join the basic layout how I wanted things to be arranged
Kind regards
Joe
Maybe something like that?
-
Irregular data loss - function from PL/SQL returning data using Ref Cursor
Database Version: 10.2.0.4.0 (node 2 CARS)
The high-level process flow is as below:
(1) insert records in a few tables & commit the same
(2) call the pl/sql function to extract files (on certain conditions with joins with other tables) of the tables which are filled in step 1.
-> It uses the ORDER BY clause to queries inline & line number 5000 records return for each call.
Sense - if inline query is supposed to return 1,00,000 records then 20 calls to the same function. This, because the application cannot contain records beyond number.
(3) the data returned by the ref cursor is then processed by application (Tibco BW) to generate the flat file.
We are facing the problem of data loss in the file and there is no fixed model. It happens once between 200-300 calls process.
Resolution: When the problem occurs, triggering the process and in almost every time re-outbreak of the process provides required data.
Guidance on what could be the reason?
* Examples of Code for the function:
CREATE OR REPLACE FUNCTION FUNC_GET_HRCH_TOTAL_DATA)
outinstrid in NUMBERS
outinstrkey in NUMBERS
rownumberstart in NUMBERS
rownumbereend in NUMBERS
err_code OUT VARCHAR2,
err_msg OUT VARCHAR2)
RETURN PACK_TYPES. HRCH_TOTAL_CURSOR
IS
REF_HRCH_TOTAL_CURSOR PACK_TYPES. HRCH_TOTAL_CURSOR;
BEGIN
OPEN FOR REF_HRCH_TOTAL_CURSOR
SELECT *.
FROM (SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order, ROWNUM ROWNUMBER
OF AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
WHERE A.outputid = B.outputid
AND A.outputid = C.outputid AND A.outputkey = B.outputkey
AND A.outputkey = C.outputkey AND A.outputid = outinstrid
AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
WHERE ROWNUMBER < rownumbereend
AND ROWNUMBER > = rownumberstart;
RETURN REF_HRCH_TOTAL_CURSOR;
EXCEPTION
WHILE OTHERS
THEN
err_code: = x_progress | ' - ' || SQLCODE;
err_msg: = SUBSTR (SQLERRM, 1, 500);
END FUNC_GET_HRCH_TOTAL_DATA;
/
Published by: meet_sanc on February 16, 2013 10:42Your SELECT statement is almost certainly incorrect
SELECT * FROM ( SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order,ROWNUM ROWNUMBER FROM AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C WHERE A.outputid = B.outputid AND A.outputid = C.outputid AND A.outputkey = B.outputkey AND A.outputkey = C.outputkey AND A.outputid = outinstrid AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER ORDER BY A.HIERARCHY_LEVEL_ORDER DESC) WHERE ROWNUMBER < rownumbereend AND ROWNUMBER >= rownumberstart;
Since the ORDER BY is applied after the ROWNUM is assigned in this case, your query is requested for a period of 5000 lines any arbitrariness. It would be perfectly valid for a single line to return in each of your 200 different calls or for a line to return in any of them.
You definitely want to do something in the sense of the canonical askTom wire
select * from ( select a.*, rownum rnum from ( YOUR_QUERY_GOES_HERE -- including the order by ) a where rownum <= MAX_ROWS ) where rnum >= MIN_ROWS
That said, it seems inconceivable that Tibco is unable to manage a cursor that returns more than a certain number of lines. You do a ton of work to return the data pages that are certainly not necessary. Unless you're saying that you somehow paralyzed your installation of Tibco giving him a ridiculously small amount of memory to process, something doesn't look good. A slider is just a pointer - it holds that no data - so the number of lines that you can extract a slider should have no impact on the amount of memory on the client application needs.
As others have already pointed out, your exception handler is almost certainly do more harm than good. Return the error codes and error messages as from the OUT parameters, instead of simply allowing the exception to propagate deletes a ton of useful information (such as the mistake of the stack) and makes your process much less robust.
Justin
Maybe you are looking for
-
TouchSmart HP Envy 15-j078ca - sound card problems
Hello! I have a HP Envy 15-j078ca running windows 8.1 touchsmart and, recently, I noticed that my audio is static/crackling noises. A test, I plugged my head phones to see if it was a speaker problem or a problem of sound card and audio in my headpho
-
Satellite L30-105 will not boot after memory expansion
Hello I have a Toshiba Satellite L30-105, with 1 GB of memory (2 X 512 MB modules).I bought 2 X 1 GB-compatible modules to extend the memory to its max. When I install the two new modules the laptop won't boot. I tried to install one at the time and
-
HP TC4400 on-screen keyboard does not not (XP SP3 Tablet)
Just bought a refurbished HPTC4400. New installation of XP... I have the disks. Tablet PC keyboard mode input panel does not work. On the left is the stack of three buttons... The three keys to select mode are functional, but the key
-
change the orientation of the screen?
How can I change the orientation of the screen?
-
Vista and bluetooth motorola s9 headphones
I have a motorola s9 bluetooth headset and they do not work with my vista, the computer tells me I need a driver, I downloaded the broadcom software, but it does not detect my device when I run? What can I do to fix that?