Need a help in pl/sql cursors
Hi,
wrong posted...if i have any clarifications i can mail to all.
thanks...
This is how formatted code looks like.
I have removed superflous BEGIN .. END (Which lead to code that would not compile)
This is your code, not mine
DECLARE
CURSOR stagingtablerecords IS
SELECT *
FROM mdat_lseveh_options;
r mdat_lseveh_options%ROWTYPE;
svar NUMBER;
BEGIN
FOR r IN stagingtablerecords LOOP
IF r.heading_sw = 'Y' THEN
INSERT INTO pref_accessory_category (acc_cat_id,
acc_cat_desc,
last_modified,
model_cd,
model_yr,
interior,
ext_accessory
VALUES (refcatidseq.NEXTVAL,
r.std_equip_txt,
SYSDATE,
r.model_cd,
r.model_year,
NULL,
NULL
svar := acc_cat_id; -- Problem here
ELSIF r.heading_sw = 'N' THEN
INSERT INTO pref_accessory (acc_id,
acc_desc,
acc_cat_id,
model_cd,
model_yr,
last_modified
VALUES (refaccidseql.NEXTVAL,
r.std_equip_txt,
svar,
r.model_cd,
r.model_year,
SYSDATE
END IF;
END LOOP;
COMMIT;
END;
/You have a problem with your staging table, since there is no information on which accessories belongs to which categories.
You seem to rely on some sort of order, but this order do not exist, unless expressed explicitly.
If data comes from a file and is sorted in there, then you could add a line number, or a sequential number or such as you load them into stage table.
This number should be used when reading from stage table to ensure lines are processed like
Y1
N1
N1
N1
Y2
N2
N2
Right now, you have no control over the stage table
Edit:
I would try with something like, (Not tested, or anything else - And never tried this with sequences, suspect it may not work)
INSERT ALL
WHEN heading_sw = 'Y' THEN
INTO pref_accessory_category (acc_cat_id,
acc_cat_desc,
last_modified,
model_cd,
model_yr,
interior,
ext_accessory
VALUES (refcatidseq.NEXTVAL,
std_equip_txt,
SYSDATE,
model_cd,
model_year,
NULL,
NULL
WHEN heading_sw = 'N' THEN
INTO pref_accessory (acc_id,
acc_desc,
acc_cat_id,
model_cd,
model_yr,
last_modified
VALUES (refaccidseql.NEXTVAL,
r.std_equip_txt,
refcatidseq.CURRVAL,
r.model_cd,
r.model_year,
SYSDATE
SELECT std_equip_txt,
model_cd,
model_year
FROM stagingtablerecords
ORDER BY your_new_column;Regards
Peter
Similar Messages
-
Need help on Dynamic SQL Cursor in Forms
Hi All,
I am trying to execute Dynamic SQL Cursor in forms using EXEC_SQL built in.
I have a cursor for example:
'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order
My code is
cur_num := Exec_SQL.Open_cursor;
sql_order := 'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order;
EXEC_SQL.PARSE(cursor_number, sql_order);
EXEC_SQL.DEFINE_COLUMN(cur_num ,1,ln_Supp_Id);
EXEC_SQL.DEFINE_COLUMN(cur_num ,2,ls_Suppl_Name,30);
EXEC_SQL.DEFINE_COLUMN(cur_num ,24,ls_exchange,20);
sql_count := EXEC_SQL.EXECUTE(cur_num );
While EXEC_SQL.FETCH_ROWS(cur_num ) > 0 Loop
EXEC_SQL.COLUMN_VALUE(cur_num ,1,ln_Supp_Id);
EXEC_SQL.COLUMN_VALUE(cur_num ,2,ls_Suppl_Name);
EXEC_SQL.COLUMN_VALUE(cur_num ,24,ls_exchange);
End Loop;
EXEC_SQL.CLOSE_CURSOR(cur_num );
In this case I have to write 24 Define Columns and 24 Column value. Is there any way to assign them to %rowtype at one time as I need all coulmn of the table.
I had similar case on multiple tables.
Please help me
Thanks,
MaddyI need this dynamic sql because p_supplier and p_order values changes at run time
I do not understand. Is this a simplified sample or the real thing? You do know that you can pass variables to cursors:
cursor test is
select * from supplier where supplier = p_supplier and processing_order = p_order;
or does e.g. p_supplier hold other parts of the query?
cheers -
Need Help on PL/SQL Cursor
Hi friends ,
I am getting 3 columns from one table thr cursor,
At the same time I am getting 7 columns from another one table.
Now I am comparing the 1st tables first_name with the 2nd tables firs_name
as
FOR I IN C_DS_OP_M_USER_MAP LOOP
V_COUNT := 0;
FOR J IN C_SI_OP_M_USER LOOP
IF (I.FIRST_NAME = J.FIRST_NAME) AND (I.LAST_NAME = J.LAST_NAME) AND (I.USER_CODE = J.USER_ID) THEN
DBMS_OUTPUT.PUT_LINE('MATCHES ' ||I.USER_CODE||' '||I.FIRST_NAME||' '||I.LAST_NAME);
V_COUNT := V_COUNT+1;
END IF;
END LOOP;
IF V_COUNT = 0 THEN
DBMS_OUTPUT.PUT_LINE('NOT MATCHES '|| I.USER_CODE ||' '|| I.FIRST_NAME ||' '|| I.LAST_NAME);
END IF;
But the problem is , I couldn't get the first record comparison only, all the other records are being displayed correctly.
Please help me to recover this problem.
Thank youWhere is the other END LOOP in the procedure?
Moreover, I think it is better if you achaive this using joins.
declare
cursor c1 as select a.col1, b.col2, a.col2
from a, b
where a.col1 = b.col1
and a.col2 = b.col2
and a.col3 = b.col3;
v_val number := 0;
begin
for r1 in c1 loop
dbms_output.put_line(col1||','col2||','||col3);
v_val := v_val +1;
end loop;
if v_val = 0 then
dbms_output.put_line('No matches');
end if;
end;Cheers
Sarma. -
Need Urgent Help Reports 6i : Ref Cursor
Hi,
I am creating required SQL for report in my Java program. I want to pass this SQL stmt to my Oracle Report.
For that , I am storing the SQL stmt in Oracle table and then I want to use that stmt with few additions to fetch data . Is there any good method other than Ref Cursor to do this? Somehow Ref cursor is not working in Reports 6i. Or may be I don't know how to use it.
Any help will be appreciated !!
VMJLexical parameters seem to be much more appropriate tool for this task. You can create entire query as single lexical parameter, and script it in the After Parameter Form trigger any way you need. Just make sure to supply some dummy query as initial value for the lexical parameter, so that the report could create proper data structure.
-
Need a help in PL/SQL array
Hi below is my requirement
I need to generate value AA to ZZ. I know we can do with this in squencer, But I want this in Array such that if the value passed is AD the return should be AE.. if value sent is AZ then it should return BA
Inner loop handles A to Z and Outer loop ahndles A-Z.. So if we pass AR the inner loop wijj go till R when it finds matching R then it should pick next value i.e S
and write AS.
Please help me in doing this with Array function in PL/SQL
Thanks in advance
Edited by: shrivatsa on Apr 28, 2009 2:40 PMNot sure why you need a plsql array for this. With above provided sql you could do it also like this:
SQL> var code varchar2(3)
SQL> exec :code := 'FFF'
PL/SQL procedure successfully completed.
SQL> with table1 as (
select '1FFFAA' str from dual union all
select '2FFFAB' from dual union all
select '3CCCAR' from dual union all
select '4CCCAS' from dual union all
select '5RRRAY' from dual union all
select '6RRRAZ' from dual
h as
select a||b ab, lead(a||b) over (order by a,b) next
from (select chr(64+level) a from dual connect by level <= 26),
(select chr(64+level) b from dual connect by level <= 26)
select max(:code || next) next
from table1, h
where substr(str,-5,3) = :code
and substr(str,-2,2) = ab
NEXT
FFFAC
1 row selected.
SQL> exec :code := 'RRR'
PL/SQL procedure successfully completed.
SQL> with table1 as (
select '1FFFAA' str from dual union all
select '2FFFAB' from dual union all
select '3CCCAR' from dual union all
select '4CCCAS' from dual union all
select '5RRRAY' from dual union all
select '6RRRAZ' from dual
h as
select a||b ab, lead(a||b) over (order by a,b) next
from (select chr(64+level) a from dual connect by level <= 26),
(select chr(64+level) b from dual connect by level <= 26)
select max(:code || next) next
from table1, h
where substr(str,-5,3) = :code
and substr(str,-2,2) = ab
NEXT
RRRBA
1 row selected. -
I need somebody to help me with sql cursors, in JSP.
This is my peace of code what is wrong with it?
Statement stmt = myConn.createStatement();
stmt.executeQuery("BEGIN WORK");
stmt.executeQuery("DECLARE item_cursor CURSOR FOR SELECT user_name FROM admin_info");
stmt.executeQuery("FETCH 10 FROM item_cursor");
ResultSet rs = stmt.getResultSet();
while(rs.next()){
if(rs.getString(1) != null){
user_name = rs.getString(1).trim();
%><P><%= user_name %></P><%
stmt.executeQuery("CLOSE item_cursor");
stmt.executeQuery("COMMIT WORK");
and this is the error that a get: No results where returned by the query
Please help anybody
thanx guysIf you are using ORACLE drivers and classes.
This sample program shows Oracle JDBC REF CURSOR functionality, creating a PL/SQL package that includes a stored function that returns a REF CURSOR type. The sample retrieves the REF CURSOR into a result set object.
* This sample shows how to call a PL/SQL function that opens
* a cursor and get the cursor back as a Java ResultSet.
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class RefCursorExample
public static void main (String args [])
throws SQLException
// Load the driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger");
// Create the stored procedure
init (conn);
// Prepare a PL/SQL call
CallableStatement call =
conn.prepareCall ("{ ? = call java_refcursor.job_listing (?)}");
// Find out all the SALES person
call.registerOutParameter (1, OracleTypes.CURSOR);
call.setString (2, "SALESMAN");
call.execute ();
ResultSet rset = (ResultSet)call.getObject (1);
// Dump the cursor
while (rset.next ())
System.out.println (rset.getString ("ENAME"));
// Close all the resources
rset.close();
call.close();
conn.close();
// Utility function to create the stored procedure
static void init (Connection conn)
throws SQLException
Statement stmt = conn.createStatement ();
stmt.execute ("create or replace package java_refcursor as " +
" type myrctype is ref cursor return EMP%ROWTYPE; " +
" function job_listing (j varchar2) return myrctype; " +
"end java_refcursor;");
stmt.execute ("create or replace package body java_refcursor as " +
" function job_listing (j varchar2) return myrctype is " +
" rc myrctype; " +
" begin " +
" open rc for select * from emp where job = j; " +
" return rc; " +
" end; " +
"end java_refcursor;");
stmt.close(); -
Help: APEX - PL/SQL Function
Hello,
i need some help with a SQL statement.
I have the follwing Table "TABF":
ID Number,
B_Number varchar2(10),
G_Type varchar2(10),
Site varchar2(50),
Event varchar2(50),
Date varchar(10),
Dataset varchar2(50),
Mode varchar2(50),
Topic varchar2(10),
Parameter varchar2(10),
Value varchar2(10)The table is filled with records which, like this:
B Number | G-Type |Site |Event |Date | Dataset | Mode | Topic | Parameter | Value
800257 | 4.2 | USA | Test |18.08.08 | Pre |MBA | Field | F_C | 73,9015
800257 | 4.2 | USA | Test |03.04.96 | BL |MBA | Field | F_C | 73,6951
800257 | 4.2 | USA | Test |03.04.96 | BL |MBA | Field | F_C | 73,71
800257 | 4.2 | USA | Test |18.08.08 | Post |MBA | Field | F_C | 73,7526
800257 | 4.2 | USA | Test |18.08.08 | Pre |MBA | Field | F_C | 4,5170
800257 | 4.2 | USA | Test |03.04.96 | BL |MBA | Field | F_H | 24,6074
800257 | 4.2 | England | Test |03.04.96 | BL |MBA | Field | F_H | 24,62
800257 | 4.2 | England | Test |18.08.08 | Post |MBA | Field | F_H | 24,4717 Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
And so on.....
The result should look like this for the example above:
B Number | G-Type | Site |Event |Date | Dataset | Mode | Topic |Parameter | Value | Topic2 | Parameter2 | Value2
800257 | 4.2 | USA | Test |18.08.08 | Pre | MBA | Field | F_C | 73,9015 | - | - | -
800257 | 4.2 | USA | Test |03.04.96 | BL | MBA | Field | F_C | 73,6951 | Field | F_H | 24,6074
800257 | 4.2 | USA | Test |03.04.96 | BL | MBA | Field | F_C | 73,71 | Field | F_H | 24,62
800257 | 4.2 | USA | Test |18.08.08 | Post | MBA | Field | F_C | 73,7526 | - | - | -
800257 | 4.2 | USA | Test |18.08.08 | Pre | MBA | Field | F_C | 4,5170 | - | - | -
800257 | 4.2 | England | Test |18.08.08 | Post | MBA | Field | F_H | 24,4717 | - | - | -Hope you understand my problem and some1 can help me.
Thank you
Regards
Chris
Edited by: user11369135 on 09.07.2009 00:50user11369135 wrote:
Hello,
i need some help with a SQL statement.
I have the follwing Table "TABF":
Now im looking for a SELECT statement or better a function that returns a SELECT under the following condition:
If B_Number and Event and Date and Dataset are equal, then add 3 additional columns (Topic2, Paramter2, Value2) at the first aquivalent entry.
Then the row can be delete/ignored. If there will be another record where B_Number,Event, Date are equal to a row above then Topic3, Paramter3 and Value 3 should be added as a new column at the first record where the conditions equals.
And so on.....
Edited by: user11369135 on 09.07.2009 00:50if I understand correctly then you want a simple GROUP BY on B_number, Event, Date and Dataset.
But you want additionaly show 3 columns from one of the rows that was grouped.
This can be done using the little known KEEP syntax.
Documentation: http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#sthref1389
Example from the docs
Aggregate Example
The following example returns, within each department of the sample table hr.employees, the minimum salary among the employees who make the lowest commission and the maximum salary among the employees who make the highest commission:
SELECT department_id,
MIN(salary) KEEP (DENSE_RANK FIRST ORDER BY commission_pct) "Worst",
MAX(salary) KEEP (DENSE_RANK LAST ORDER BY commission_pct) "Best"
FROM employees
GROUP BY department_id;
DEPARTMENT_ID Worst Best
10 4400 4400
20 6000 13000
30 2500 11000
40 6500 6500
50 2100 8200
60 4200 9000
70 10000 10000
80 6100 14000
90 17000 24000
100 6900 12000
110 8300 12000
7000 7000 -
Hi All,
I need little help in designing SQL. My input and output data is given below:
Input
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
4/25/2011 3:36:19 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
Output
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/25/2011 5:55:55 PM
Here out of 2nd and third record of input, output is 2nd record of output and 5th and 6th record of input would come out as 4th record of output. Basically, if we overlapping duration between Date_1 and Date_2, we need to take min of Date_1 and max of Date_2 for that overlapping records. In case of no overlapping, we would simply output input record like record 1 and 4 of input.
Out of
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
4/25/2011 3:36:19 PM
2/24/2011 1:48:07 PM was min of above 2 and 5/24/20114:50:16 was max of above 2.
Similarly in other overlapping scenario:
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
6/16/2011 3:25:42 PM was min of above 2 and 6/25/2011 5:55:55 PM was max of above 2.
Pls help.
Thanks.Hi Frank.,
The above logic with NVL is not working.
My input sample is:
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
5/24/2011 4:50:16 PM
Key1
2/24/2011 1:48:59 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/24/2011 1:33:13 PM
Key1
6/17/2011 1:12:54 PM
6/25/2011 5:55:55 PM
I am giving create and insert statement below for creation of above data. Please see if you can help me:
CREATE TABLE test1
KEY1 NUMBER ,
DATE_1 DATE ,
date_2 DATE
insert into test1
values(1, TO_TIMESTAMP ('2/14/2011 5:22:35 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('2/22/2011 3:05:13 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('2/24/2011 1:48:07 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('5/24/2011 4:50:16 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('2/24/2011 1:48:59 PM', 'MM/DD/YYYY HH:MI:SS AM'), '' ) ;
values(1, TO_TIMESTAMP ('5/24/2011 5:18:19 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/16/2011 3:17:40 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('6/16/2011 3:25:42 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/24/2011 1:33:13 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
values(1, TO_TIMESTAMP ('6/17/2011 1:12:54 PM', 'MM/DD/YYYY HH:MI:SS AM'),TO_TIMESTAMP ('6/25/2011 5:55:55 PM', 'MM/DD/YYYY HH:MI:SS AM') ) ;
commit;
Expected output would be:
Output
Key
Date_1
Date_2
Key1
2/14/2011 5:22:35 PM
2/22/2011 3:05:13 PM
Key1
2/24/2011 1:48:07 PM
Key1
5/24/2011 5:18:19 PM
6/16/2011 3:17:40 PM
Key1
6/16/2011 3:25:42 PM
6/25/2011 5:55:55 PM
Thanks.... -
Hi,
I need a help in writing an SQL query . I am actually confused how to write a query. Below is the scenario.
CREATE TABLE demand_tmp
( item_id NUMBER,
org_id NUMBER,
order_line_id NUMBER,
quantity NUMBER,
order_type NUMBER
CREATE TABLE order_tmp
( item_id NUMBER,
org_id NUMBER,
order_line_id NUMBER,
open_flag VARCHAR2(10)
INSERT INTO demand_tmp
SELECT 12438,82,821,100,30 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,849,350,30 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,NULL,150,29 FROM dual;
INSERT INTO demand_tmp
SELECT 12438,82,0,50,-1 FROM dual;
INSERT INTO order_tmp
SELECT 12438,82,821,'Y' FROM dual;
INSERT INTO order_tmp
SELECT 12438,82,849,'N' FROM dual;
Demand_tmp:
Item_id org_id order_line_id quantity order_type
12438 82 821 100 30
12438 82 849 350 30
12438 82 NULL 150 29
12438 82 0 50 -1
Order_tmp :
Item_id org_id order_line_id open_flag
12438 82 821 Y
12438 82 849 N I need to fetch the records from demand_tmp table whose order_line_id is present in order_tmp and having open_flag as 'Y' or if order_type in demand_tmp table is 29.
The below query will give the records whose order line id is present in order_tmp. But, If i need records which are having order_type=29 the below query wont return any records as order_line_id is NULL. If I place outer join I will get other records also (In this example order_type -1 records) . Please help me how can we write a query for this. Expected o/p is below.
Query :
Select item_id,org_id,order_line_id,quantity,order_type,open_flag
from demand_tmp dt , order_tmp ot
where dt.order_line_id = ot.order_line_id
AND dt.item_id=ot.item_id
AND dt.org_id = ot.org_id
AND ot.open_flag = 'Y';
Expected Output :
item_id org_id order_line_id quantity order_type open_flag
12438 82 821 100 30 Y
12438 82 NULL 150 29 NULL Thanks in advance,
Rakesh
Edited by: Venkat Rakesh on Oct 7, 2012 6:32 PM
Edited by: Venkat Rakesh on Oct 7, 2012 8:39 PMHi Rakesh,
the query is not working as you would like ( but IS working as expected ) since your trying to compare null to another value.
Comparing null always results in FALSE, also if you compare null to null. This is because null means undefined.
select 1 from dual where null=null results in no data found.
I would suggest using a non natural key to join the tables.
For example include a column ID in the master table which is filled with a sequence and include that field as a foreign key in the detail table.
This way you can easily join master and detail on ID = ID, and you don't have to worry about null values in this column since it's always filled with data.
Regards,
Bas
btw, using the INNER JOIN and OUTER JOIN syntax in your SQL makes it better readable, since you're separating join conditions from the where clause, just a tip ;) -
Need help: Form6i PL/SQL library not found!
New oracle user need your help:
I installed Form6i and PO8i on NT, and config the tnsnames.ora file, they both worked fine to connect. But when I try to look into the PL/SQL library, it said PL/SQL library can not found. I deleted the classpath because with it I can't run Java, and the Sun help menu told me I can delete classpath to let it use current directory, is this the reason that Oracle can't find the library?
One more question: when I connect to database from Form, Username, Password, then Databasename, for this last one, if I leave it blank, it will connect to the database, but if I type in my database name(the default DB name), it will again give me error message, said TNS can't resolve service. Does anybody have a clue? Thank you so much!The answer for on more question:
It's not db name but service name.
A sample in tnsname.ora:
DKORCL[the service name].world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = dlt_db_srv[host_name])(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = dkorcl[oracle service name])
You say,"u can leave it blank ",then u must work at the server.And the name u type in is not correct.
May this help u!
null -
Help with "ORA-06511: PL/SQL: cursor already open"
I've tried numerous variations on this piece of code and I always get the same result. I'm sure this is painfully obvious to an experienced PL/SQL person.
Any help will be appreciated!
Thank You!
1 DECLARE
2 CURSOR EMP_CURSOR IS SELECT last_name from employees;
3 current_last_name varchar2(25);
4 BEGIN
5 IF EMP_CURSOR%ISOPEN
6 THEN
7 dbms_output.put_line ('cursor is already open');
8 close EMP_CURSOR;
9 END IF;
10 dbms_output.put_line ('opening cursor');
11 OPEN EMP_CURSOR;
12 FOR item in EMP_CURSOR LOOP
13 FETCH EMP_CURSOR INTO current_last_name;
14 EXIT WHEN EMP_CURSOR%NOTFOUND;
15 dbms_output.put_line (item.last_name);
16 END LOOP;
17 CLOSE EMP_CURSOR;
18* END;
19 /
DECLARE
ERROR at line 1:
ORA-06511: PL/SQL: cursor already open
ORA-06512: at line 2
ORA-06512: at line 12Mathieu,
Log in as anotherSchema and grant select on 'IDsTable' to the current user.
SQL> r
1 create or replace function f1(theID varchar2) return mytype pipelined is
2 out varchar2(30);
3 cursor myCursor (x varchar2) is select * from scott.emp where job=x;
4 begin
5 for rec in myCursor(theID) loop
6 pipe row(rec.ename);
7 end loop;
8 return;
9* end;
Warning: Function created with compilation errors.
SQL> show errors
Errors for FUNCTION F1:
LINE/COL ERROR
3/33 PL/SQL: SQL Statement ignored
3/53 PL/SQL: ORA-00942: table or view does not exist
6/1 PL/SQL: Statement ignored
6/10 PLS-00364: loop index variable 'REC' use is invalid
SQL> connect scott
Enter password: *****
Connected.
SQL> grant select on emp to testuser;
Grant succeeded.
SQL> connect testuser
Enter password: ****
Connected.
SQL> create or replace function f1(theID varchar2) return mytype pipelined is
2 out varchar2(30);
3 cursor myCursor (x varchar2) is select * from scott.emp where job=x;
4 begin
5 for rec in myCursor(theID) loop
6 pipe row(rec.ename);
7 end loop;
8 return;
9 end;
10 /
Function created.
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.3.0 - Production
SQL> -
Need a column based off a PL/SQL cursor, how to do this?
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Real Application Testing option
JServer Release 9.2.0.8.0 - Production
Report Builder 10.1.2.2.0
ORACLE Server Release 10.1.0.5.0
Oracle Procedure Builder 10.1.2.2.0
Oracle ORACLE PL/SQL V10.1.0.5.0 - Production
Oracle CORE 10.1.0.5.0 Production
Hi,
I am trying to create a fairly basic report but in the initial data model query, I have one column that is built based off of a PL/SQL cursor. How do I add this into my report? I have tried to create a function under Program Units and reference the function in my select statement for the data model however it keeps saying it is an invalid identifier, and I assume its looking in our database and not the function I created inside the report.
This is what it looks like:
SELECT a.id,
b.name,
F_GET_GENERIC_NAME(b.code) "Generic Name",
c.strength...and the function i want it to use in my report:
FUNCTION F_GET_GENERIC_NAME (in_code varchar2) RETURN VARCHAR2 IS
BEGIN
DECLARE
generic_name table.column%TYPE;
CURSOR cs_get_generic_name IS
SELECT /*+ USE_HASH (AR) */ desc
FROM a_ref AR, ai_ic AC
WHERE AC.code = in_code
AND AC.code = AR.code
ORDER BY sort_nbr;
BEGIN
generic_name := '';
FOR v_get_generic_name IN cs_get_generic_name
LOOP
generic_name := generic_name || RTRIM(v_get_generic_name.desc)
|| '/' || ' ';
END LOOP;
generic_name := SUBSTR(generic_name, 1,(NVL(LENGTH(generic_name), 0) - 2));
RETURN generic_name;
END;
END;
Any suggestions? Should I just create the function in the database?I am trying to do it through a formula column but am encountering the following problem.
I've created a formula column in my data model where I want the column to be (inside the group).
Inside the PL/SQL for the column I reference the function that I had previously created with the following:
function CF_Generic_nameFormula return Char is
begin
F_GET_GENERIC_NAME(:code);
end;However it won't let me compile, giving the error that "F_GET_GENERIC_NAME is not a procedure or is undefined." Is there something else that I am missing?
EDIT: Nevermind, i missed something simple like putting a return in front of the function call.
Edited by: a small rabbit on Nov 3, 2009 10:43 AM
Edited by: a small rabbit on Nov 3, 2009 10:44 AM -
Need help to convert SQL MSSQL statement to work with PL in ORACLE
Hi All,
I have the trigger below and it worked on MSSQL server for windown and
I really need your help to convert this trigger to work on PL/ORACLE:
create trigger deleteLD
on tablea for delete
as
set nocount on
begin
declare @tablename varchar(100)
declare @dropSql varchar(50)
select @tablename= dataset from deleted
set @tablename = 'LD_' + @tablename
set @tablename = @tablename + 'UTMSTATS'
if exists (select * from sysobjects where name = @tablename)
begin
set @tablename = 'drop table ' + @tablename
EXEC (@tablename)
end
end
GO
Your help is greatly appreciated.
Thanks,
JPnot sure if this is something that you want:
Create Or Replace Trigger deleteLD
Before Delete on tablea
Declare
vCtr number := 0;
Begin
select count(*)
into vCtr
from all_tables
where table_name = :new.tablename;
if vCtr > 0 then
dbms_utility.exec_ddl_statement('drop table '||:new.table_name);
end if;
End;note: not tested -
Hello experts,
I need to write a dynamic sql statement which will enable users to pick the date and the BI system will take them 3 months back. I tried 3 months variables I kept getting SQL error then I tried 90 days. Now it keep showing that there is no data which for sure I know its not trure.
This is my statement: +"GL Calendar"."Fiscal Date" >=timestampadd(SQL_TSI_DAY,-90, timestamp'@{ABCcost}{2013-05-16 00:00:00}')AND("GL Calendar"."Fiscal Date">=timestamp'@{ABCcost}{2013-05-16 00:00:00}')+
Anything that Im missing..Rayan,
I am not sure if I am following you, cause we want to enable the user to pick whatever date and then from there they will get 3 months back and the rest of their info. I tried it didn't work, may be I placed at wrong place
Can you probably copy my statement above and insert in-between.
thanks,
Edited by: 994621 on May 17, 2013 11:28 AM -
CR+LF Code at the end of each record selected in sql cursor
i am selecting some data records in a sql cursor and writing it into a file using UTL_FILE.puT in a plsql procedure.
at the end of select statement if i add ||chr(13||chr(10) iam getting CR+CR+LF code
if i add only || chr(10) i am getting LF code.
What i need is only CR+LF code. Kindly help to use any other commands.
Thanks,
Shivaji.
Edited by: Shivaji M on Apr 22, 2010 12:11 AM
Edited by: Shivaji M on Apr 22, 2010 12:36 AMIt's in the book!
"PUT_LINE terminates the line with the platform-specific line terminator character or characters."
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10577/u_file.htm#i997640
Maybe you are looking for
-
Unable to SMPTE LOCK automation
i am still struggling here with this locking issue!! the regions are locking fine, but the automation is NOT locking on any of my projects... After SMPTE locking automation, by accessing the automation event list, selecting all, and then locking ever
-
Accounts getting disabled after enabling password expiration on BOXI R2 SP2
Hi All, We have a strange issue with our production environment.After enabling password expiration on the enterprise some accounts got disabled,on further investigation I found that these users were either trying to log on to Designer or 2 tier Deski
-
How to use LIKE operator in plsql
Hi I wanted to select certain rows using like operator in plsql(Input should be given by the user). I have given my experiment here .I couldn't get any result. As per sql syntax while using LIKE operator we should give search criteria within single q
-
Hi SAP experts, I am new to SAP support project . I got issue regarding material creation through MM01 while creating a material it gives the message like "Impossible to use S price for plant". Pls help me in this regard and give me some directions
-
Change batch level from plant to material
Hi, is there any possibility to change the batch level from Plant to Material level. system has now changed the table in material master from MARA to MARC. Regards, Ali