SQL & PL/SQL :: Ref Cursors For Passing Parameters?
Mar 20, 2013
declare
type ref_cur is ref cursor;
r ref_cur;
enam emp%rowtype;
dno dept.deptno%type;
begin
dbms_output.put_line('The Employee details are');
open r for select deptno from dept;
loop
fetch r into dno;
[code]....
Error at line 1
ORA-06550: line 12, column 28:
PLS-00103: Encountered the symbol "FOR" when expecting one of the following:
. ( % ;
if i need to use ref cursor to send parameters, is it possible? if yes how to use it?
Ex: Cursor C_employees(C_empid number, C_cityname varchar2) is select emp_name, office_name from employee where employees where empid = c_empid and city = c_city_name;
I know we can pass one parameter to the cursor but I do not know how to pass multiple parameters.
i trying to pass the char varible to the cursor but it is not taking ,,, if i hardcode the values to the cursor it is takinghere is the detailed program ... any body can tell why this is not taking and tell me how to pass the values through it..
declare v_name char(6) ; cursor c1(c_name char) is select name, parent,child,status from relation start with name='%'
i want to update a table passing the parameters and the updating the table according to it
i trired this
create or replace procedure move (z1 in game.item_id%type,g1 in game.item%type) as begin update game set postion= 'l' where item_id=z1 or item_id=g1; end move; /
I need to pass two parameters (STUD_ID) and (TERM) from Form A to Form B. I've read a lot but I'm not familiar with terms and oracle jargon yet! So I really need your straight forward clarification
From the Calling form I'm using when_button_pressed trigger...what shall i write in here?! In the Called form, I'm declaring the following under (When_new_form-instance):
declare p1_id paramlist; stud_id number(8); term number(5);
begin
p1_id := get_parameter_list(stud_id); p1_id := get_parameter_list(term); :TEST_STUD_CRSE_REG.stud_id :=:parameter.stud_id; :TEST_STUD_CRSE_REG.term :=:parameter.term; next_block; end; ----------------- on the calling form:when_button_pressed I am using:
DECLARE
p1_id paramlist; stud_id number(8); term number(5);
,I have a queryIn my query iam passing parameters using IN clause.The parameters contains in two tablesfor ex..select a.deptno, b.deptnofrom dept1 a, dept2 bwhere a.deptno = b.deptnoand NVL (a.deptno, b.deptno) in (10, 20, 30,.....) is this correct way to use NVL like this.i have a deptno consists in both the tables. How can i use this condition.
I have a Pro*C program, which uses a dynamic query. The dynamic query is opened using result of another static cursor( 5 fields say , :a, :b , :c, :c, :d).
I am modifying the dynamic query and adding UNION for some requirement , which makes this dynamic query exactly double in size. ( means 2 set of prev. queries are joined by UNION, with one extra condition though).
The question is , Do I need to pass 2 set of variable to open the dynamic query now?
Like earlier , program was passed with (:a, :b , :c, :c, :d) so now i should pass (:a, :b , :c, :c, :d , :a, :b , :c, :c, :d)?
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production PL/SQL Release 11.1.0.6.0 - Production "CORE 11.1.0.6.0 Production"
I have a form which has few textboxes, and few dropdown, and 3 links. Data is entered in few boxes, and then when a link is clicked, it goes to another page, but i want to pass the text in the text boxes, and the selected value from the dropdown also, to be passed as parameters to this link... But since these values are not yet saved, its not getting passed.. like it is something like this in the address bar add_new_event?&event_ id= &event_ name= & event_dt=
1. I m building a form in which students will file some data (name, address, etc) but i want to send a parameter on the URL i send them (their student ID number), which will be saved together with the data the end-users save.
e.g the form i m building is [URL]
can i add in the end of the URL the student_id of the end of the URL?
so it will be something like [URL]
So when student #10 will hit the URL on his browser, once he inputs hsi data and press SAVE button, on the database i can save STUDENT_ID=10 and the rest info he just entered?
2. Which is the login URL for end users? i have only the workspace login now..
I am trying to execute a STORE PROCEDURE from SQL*PLUS with no success:
SQL> execute PACKAGE.PROC(201011,'144792'); BEGIN PACKAGE.PROC(201011,'144792'); END;
* ERROR at line 1: ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'PROC' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
In fact, when i do: desc PACKAGENAME . I see that the procedure is waiting for 3 parameters and one of them is a REF CURSOR type:
SQL> desc PACKAGENAME PROCEDURE PROCEDURENAME
Argument Name Type In/Out Default? ------------------------------ ----------------------- ------ -------- PWEEK NUMBER IN PCLIENT VARCHAR2 IN CRESULTS REF CURSOR IN/OUT
I have two methods using pro*c to execute a query SQL and read the results. The query is a "select from" a view, this view is a union between two tables. The first method creates a cursor and fetches the results line by line. A second method creates a cursor and fetches the results in parts.
Method 1) CODEEXEC SQL FETCH Cursor1 INTO ...
Method 2) CODEEXEC SQL FOR :numLines FETCH Cursor1 USING DESCRIPTOR areaDescSQL;
I had executed this methods in my development enviroment, using Oracle 11g, Suse linux. As I expected, the method 2 spent much less time than the method 1. But, in the "customer enviroment", using another database, Oracle 11g and HP-UX, these methods spent almost the same time.
Is there some Oracle's configuration or parameter's settings that maybe explain that? What configuration can be differente between the two databases? What can I do to improve the time spent?
I'm currently looking for a way to declare a cursor in the 'declare' block using a previously defined variable that got its value from a query. For instance:
declare my_company_id INTEGER := 'select c.company_id from company_table c where company_name='Wal-Mart';
cursor employees is select e.employee_id from employees e where e.company_id = my_company_id;
an alternative to Oracle Cursors.My table has huge amount of data and is taking time in processing. I had thought of using BULK COLLECT but it can only be used to insert, delete or update data and will not allow me to select data.
i have created a stored procedure with a cursor in order to perform a function where the annual_sal from the employee_annual_sal table is refered and checked. The empno for all the records which satisfies the condition mentioned inside the loop should be displayed in an variable. My code is below
create or replace PROCEDURE sp_test_cursor(out_empno OUT number) IS v_get_data number; v_get_empno number; cursor c1 is select annual_salary from employee_annual_sal;
[Code]...
What should i do to return mulitple values in a single variable??
declare v1str varchar2(100):='select empno,ename from emp'; v2str varchar2(100):='select empno,ename,sal from emp'; type t_array is varray(2) of varchar2(100);
[Code]....
So my problem is while executing the different sql statements by passing it to the procedure,how can the procedure would behave dynamically.It must be able to process all the sql statements.
homework assignment using pl/sql based on 2 tables I have created below? I am not sure of how to use cursors, loops and proper syntax.
ASSIGNMENT:
1. Create a PL/SQL Procedure (cursor to loop through the records, check the LastName, then update the grade table where id=id on grade table)
Rule: A ‐ LastName ends with a character between A‐F B ‐ LastName ends with a character between G‐K C ‐ LastName ends with a character between L‐P D ‐ LastName ends with a character between Q‐T E ‐ LastName ends with a character between U‐Z
DB version: Oracle DB 10g Enterprise Edition 10.2.0.4.0
I have the following four tables:
tab_main- which lists main projects tab_sub_main - which lists sub projects tab_budget - amounts per projects/subprojects tab_total - I want to load the data here
The table script with data is attached.
I want to load data into tab_total fields for prj_type= 'J' as follows:
1. accn_no from tab_main table.
2. fy from tab_budget table
3. fy_total_amt which is the sum(amt) from tab_budget table by accn_no and fy
4. all_FY_amt which is the sum(amt) from tab_budget table by accn_no
5. all the audit fields- date/user inserted/updated will come tab_budget table
how to create this procedure with cursors.
CREATE OR REPLACE PROCEDURE LOAD_DATA_INTO_TAB_TOTAL_PROC IS CURSOR C IS select distinct m.accn_no, a.control_no,m.prj_type, b.fy, b.amt, b.user_created, b.date_created, b.user_last_mod, b.date_last_mod from tab_main m, tab_sub_main a,
[code]....
CREATE TABLE tab_main ( ACCN_NO NUMBER(7) NOT NULL, PRJ_TYPE VARCHAR2(1 BYTE) NOT NULL ) / Insert into TAB_MAIN (ACCN_NO, PRJ_TYPE)
I am trying to write which will return cursors to front end program.The logic which I got stuck is while exiting the procedure.I am having some cursors in teh procedures which are read by the front end script.I have one condition which when satisfied I have to exit from the procedure.But the constraint I am facing is if I exit at that logic, oracle closes all the cursor and front end script is not able to read teh cursor and hence throws an error.Is there any way to exit the procedure without closing the REF cursors.
I am stuck somewhere in my project, situation is that we are trying to display data gathered from 3 different tables, we used cursors for this, here is the cursor declaration.
DECLARE procedure DocInfoCur(myWhere IN varchar2) IS
init_dept_id number; init_dept_name varchar2(40);
rcvg_dept_id number; rcvg_dept_name varchar2(40);
CURSORCUR_DOCINFO IS SELECT DISTINCT I.CTN, I.DIARYNUMBER, I.INITIATINGDATE, T.TYPENAME, I.INITIATINGDEPT, I.DOCUMENTSUBJECT, I.DESTINATIONDEPT FROM DOCUMENTINFO I, DOCUMENTTYPE T, DEPARTMENT D
[code]...
This displays all the records out there.
Now, I have a search form where I need to filter the same data with different parameters, I have compiled the entered data in one string, now i need to join that string at the end of where clause of my cursor, how can I do that, i have tried concatenating both but received compile error, is there a way out in the current scenario???
I think this is the scariest error I've encountered in oracle. After some thime of developing/debuggin I've always reached this error. This leaves me no choice but to restart the java app server, in that case I'll be affecting all the other applications deployed on it which is a very bad thing for me.
Is there anyway I could solve this, I've made it sure that I've handled all errors so that I could always close the connection. Simply put, for every termination case of my program I've placed a closing statement just to be sure that no connections are left open. But even after this, I still experience the ORA 0100 error.
how to print cursors? I mean like columnname : value. of couse curosr.columnname gives what I want. but I want genrally used way.
CREATE OR REPLACE PROCEDURE PROC_TEMP IS BEGIN FOR C1 IN ( SELECT sbjct_id,sbjct_step FROM RND.SBJCT_ORDR M) LOOP DBMS_OUTPUT.PUT_LINE('c1 : '||c1); END LOOP; END;
Why exceptions does not raise in cursors declared by user like in the following program
create or replace function sal (p_id employees.department_id%Type) return number is ----sal1 employees.salary%type:=0; cursor cx is select * from employees where department_id=p_id; begin for i in cx
I loop through the 1st cursor (account_csr), while in the 1st csr loop, based on some conditions being true, I want to loop through a 2nd cursor (acctper_csr) but I only want to retrieve data/rows in the 2nd cursor where the account_id column in 1st cursor = account_id column in the 2nd cursor. This will enable me to pull all the account_periods for each account I loop through in the first cursor.
I have attempted several different ways and cannot make this work. Thought I could somehow define a variable and store the account_id from 1st cursor and use on the 'where' clause in the 2nd cursor definition. Have not been able to make this work successfully.
Following is the sample of my
--First cursor (accounts) CURSOR account_csr is SELECT * FROM s_dev_xref1.account A WHERE a.source = 1