- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: PL/SQL Variables replacing table name
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2004 06:57 PM
тАО03-29-2004 06:57 PM
Re: PL/SQL Variables replacing table name
Just another question, that works ok for select statement, what if I have to declare a cursor referencing a table that way ?
Thanks !
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2004 07:03 PM
тАО03-29-2004 07:03 PM
Re: PL/SQL Variables replacing table name
For instance : http://www.unix.org.ua/orelly/oracle/bipack/ch02_01.htm
http://www.unix.org.ua/orelly/oracle/advprog/ch11_05.htm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-29-2004 07:26 PM
тАО03-29-2004 07:26 PM
Re: PL/SQL Variables replacing table name
find an example script that uses dynamic SQL
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 04:55 PM
тАО03-30-2004 04:55 PM
Re: PL/SQL Variables replacing table name
My dynamic SQL
declare
ojn varchar2(100);
dml_str VARCHAR2(200);
t_count number;
t_name varchar2(30);
CURSOR c1 IS
SELECT table_name FROM user_tables WHERE temporary <> 'Y';
BEGIN
open c1;
loop
fetch c1 into ojn;
exit when c1%NOTFOUND;
dml_str := 'select * from '||ojn ||' ';
execute immediate dml_str into t_count;
dbms_output.put_line(ojn || ' Have ' || t_count || ' records');
END LOOP;
end;
/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2004 05:42 PM
тАО03-30-2004 05:42 PM
Re: PL/SQL Variables replacing table name
it looks good, my only concern is that I need to define the initial cursor with a variable, so that I think the only way would be to use DBMS_SQL. In most of your examples the cursor driving the LOOP does not include any variable, but in my case that's the issue.
Thanks a lot folks, now I'm definitely in better shape.
Cheers,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2004 08:53 AM
тАО03-31-2004 08:53 AM
Re: PL/SQL Variables replacing table name
List out an idea of what you are looking for. Is the list of tables going to come from another table or view, and the variable is going to be used from there?
Give a quick outline of what you are looking for.
Thanks,
brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2004 09:34 AM
тАО03-31-2004 09:34 AM
Re: PL/SQL Variables replacing table name
my tablename is not known at runtime, so that I need to gather it from another table.
The tablename extracted will be driving a cursor.
Basically I need to define something like:
DECLARE
CURSOR myown_crs IS SELECT MYOWNFLD FROM &&TABLENAME;
BEGIN
<
LOOP
FETCH myown_crs INTO MYOWNFLDVAR;
...
END LOOP;
CLOSE myown_crs;
END;
/
I don't know the tablename. Could I execute immediate the FETCH statement ?
Thanks !
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2004 09:36 AM
тАО03-31-2004 09:36 AM
Re: PL/SQL Variables replacing table name
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2004 07:19 PM
тАО03-31-2004 07:19 PM
Re: PL/SQL Variables replacing table name
--------------------
create or replace procedure tmpproc(tblname varchar2) as
type tblcur_type is REF CURSOR;
tblcur tblcur_type;
tmpvar varchar2(100);
sqlstatement varchar2(100);
begin
sqlstatement:='select field from '||tblname;
open tblcur for sqlstatement;
loop
fetch tblcur into tmpvar;
exit when tblcur%notfound;
dbms_output.put_line(tmpvar);
end loop;
close tblcur;
end;
/
------------
Most likely, another procedure would be needed for this as well. One to output the table name into the procedure, and this one to do the extra work. Probably easier than trying to do two things in the same procedure.
Let me know if this helps.
Thanks,
Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2004 08:18 PM
тАО03-31-2004 08:18 PM
Re: PL/SQL Variables replacing table name
I've never used the OPEN FOR statement, it looks interesting. Let me play with it and let you know.
Thanks !
Mike