- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: PL/SQL EXECUTE IMMEDIATE question
Operating System - HP-UX
1754186
Members
4435
Online
108811
Solutions
Forums
Categories
Company
Local Language
юдл
back
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
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО06-13-2003 07:04 AM
тАО06-13-2003 07:04 AM
Hi all.
I am quite new in PL/SQL and I need to run the following statment in a PL/SQL procedure :
EXECUTE IMMEDIATE "INSERT INTO H21ADMIN.H21_RC_WATCH_DAT ( SELECT '"|| mnew_seq ||"', '"|| mytable ||"', COUNT(*) FROM "|| mytable || ")";
mnew_seq and mytable are PL/SQL variables and not columns. These columns don't exist in the table.
I need to find the equivalent to :
INSERT INTO H21ADMIN.H21_RC_WATCH_DAT ( SELECT '1', 'H21ADMIN.THISISATABLE', COUNT(*) FROM H21ADMIN.THISISATABLE);
Could someone help ?
Cheers,
Christophe.
I am quite new in PL/SQL and I need to run the following statment in a PL/SQL procedure :
EXECUTE IMMEDIATE "INSERT INTO H21ADMIN.H21_RC_WATCH_DAT ( SELECT '"|| mnew_seq ||"', '"|| mytable ||"', COUNT(*) FROM "|| mytable || ")";
mnew_seq and mytable are PL/SQL variables and not columns. These columns don't exist in the table.
I need to find the equivalent to :
INSERT INTO H21ADMIN.H21_RC_WATCH_DAT ( SELECT '1', 'H21ADMIN.THISISATABLE', COUNT(*) FROM H21ADMIN.THISISATABLE);
Could someone help ?
Cheers,
Christophe.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2003 09:22 PM
тАО06-13-2003 09:22 PM
Solution
hi Christophe,
play with the single quotes.
anyway, below an example:
===============================================
yd@MYDB.MU> create table h21_rc_watch_dat(
2 mseq number(5),
3 tabname varchar2(100),
4 tabcount number(5)
5 );
Table created.
Elapsed: 00:00:00.03
yd@MYDB.MU> declare
2 l_str1 varchar2(200) ;
3 begin
4 for r1 in (select rownum rnum, table_name tb from user_tables where rownum < 4) loop
5 l_str1 := ''''||r1.rnum||''','''||r1.tb||''', count(*) from '||r1.tb;
6 execute immediate 'insert into h21_rc_watch_dat (select '||l_str1||')';
7 dbms_output.put_line( l_str1 );
8 end loop;
9* end;
'1','CMTSTORESTATS', count(*) from CMTSTORESTATS
'2','DEMO', count(*) from DEMO
'3','DEPT', count(*) from DEPT
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
yd@MYDB.MU> select count(*) from h21_rc_watch_dat;
COUNT(*)
__________
3
Elapsed: 00:00:00.01
yd@MYDB.MU>
===============================================
hope this helps!
regards
Yogeeraj
play with the single quotes.
anyway, below an example:
===============================================
yd@MYDB.MU> create table h21_rc_watch_dat(
2 mseq number(5),
3 tabname varchar2(100),
4 tabcount number(5)
5 );
Table created.
Elapsed: 00:00:00.03
yd@MYDB.MU> declare
2 l_str1 varchar2(200) ;
3 begin
4 for r1 in (select rownum rnum, table_name tb from user_tables where rownum < 4) loop
5 l_str1 := ''''||r1.rnum||''','''||r1.tb||''', count(*) from '||r1.tb;
6 execute immediate 'insert into h21_rc_watch_dat (select '||l_str1||')';
7 dbms_output.put_line( l_str1 );
8 end loop;
9* end;
'1','CMTSTORESTATS', count(*) from CMTSTORESTATS
'2','DEMO', count(*) from DEMO
'3','DEPT', count(*) from DEPT
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
yd@MYDB.MU> select count(*) from h21_rc_watch_dat;
COUNT(*)
__________
3
Elapsed: 00:00:00.01
yd@MYDB.MU>
===============================================
hope this helps!
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2003 09:27 PM
тАО06-13-2003 09:27 PM
Re: PL/SQL EXECUTE IMMEDIATE question
hi again,
sorry for the garbled output,
please find attached the above example.
regards
Yogeeraj
sorry for the garbled output,
please find attached the above example.
regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-16-2003 03:28 AM
тАО06-16-2003 03:28 AM
Re: PL/SQL EXECUTE IMMEDIATE question
Hi Yogeeraj.
Thanks for your help !
Here is the script I have implemented :
FOR tables_to_watch_rec IN tables_to_watch_cursor LOOP
mytable := tables_to_watch_rec.TABLE_NAME;
sql_stmt := 'INSERT INTO H21ADMIN.H21_RC_WATCH_DAT '
|| ' (SELECT ''' || mnew_seq || ''', ''' || mytable || ''', '
|| ' COUNT(*) FROM '|| mytable ||' )';
EXECUTE IMMEDIATE sql_stmt;
END LOOP;
Christophe.
Thanks for your help !
Here is the script I have implemented :
FOR tables_to_watch_rec IN tables_to_watch_cursor LOOP
mytable := tables_to_watch_rec.TABLE_NAME;
sql_stmt := 'INSERT INTO H21ADMIN.H21_RC_WATCH_DAT '
|| ' (SELECT ''' || mnew_seq || ''', ''' || mytable || ''', '
|| ' COUNT(*) FROM '|| mytable ||' )';
EXECUTE IMMEDIATE sql_stmt;
END LOOP;
Christophe.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP