|
|
Re: Please help in this problem [message #625846 is a reply to message #625840] |
Wed, 15 October 2014 00:53 |
|
mist598
Messages: 1195 Registered: February 2013 Location: Hyderabad
|
Senior Member |
|
|
Hi,
CREATE TABLE table_name ( empno NUMBER(5), ename VARCHAR(10), dname VARCHAR(10) );
DECLARE
CURSOR emp_cursor
IS
SELECT empno,
ename,
a.deptno,
dname
FROM emp a,
dept b
WHERE a.deptno = b.deptno
AND a.deptno = 10;
--FOR UPDATE OF salary NOWAIT;
BEGIN
FOR emp_rec IN emp_cursor LOOP
INSERT INTO table_name
VALUES (emp_rec.empno,
emp_rec.ename,
emp_rec.dname);
COMMIT;
END LOOP;
END;
|
|
|
Re: Please help in this problem [message #625847 is a reply to message #625840] |
Wed, 15 October 2014 00:54 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
praveen9728 wrote on Wed, 15 October 2014 11:10
NO DATA FOUND IN table_name why????
1. Welcome to the forum!
Please read and follow the OraFAQ Forum Guide and How to use [code] tags, to enable us to help you.
2. Why have posted the same question thrice?
3. It works for me,
SQL> set serveroutput on;
SQL> DROP TABLE table_name purge
2 /
Table dropped.
SQL>
SQL> CREATE TABLE table_name ( empno NUMBER(5), ename VARCHAR(10), deptno number(2))
2 /
Table created.
SQL>
SQL> DECLARE
2 CURSOR emp_cursor IS
3 SELECT e.empno,
4 e.ename,
5 e.deptno
6 FROM emp e,
7 dept d
8 WHERE e.deptno = d.deptno
9 AND e.deptno = 10;
10 --FOR UPDATE OF salary NOWAIT;
11 BEGIN
12 FOR table_name IN emp_cursor LOOP
13 INSERT INTO table_name
14 VALUES (table_name.empno,
15 table_name.ename,
16 table_name.deptno);
17 END LOOP;
18 END;
19 /
PL/SQL procedure successfully completed.
SQL>
SQL> select * from table_name
2 /
EMPNO ENAME DEPTNO
---------- ---------- ----------
7782 CLARK 10
7839 KING 10
7934 MILLER 10
SQL>
Because, the filter department = 10 returns result in my case. Did you check whether any rows exist for department = 80? First execute the select query and verify.
4. what is the purpose of the PL/SQL code? Isn't it just a simple SQL?
5. Topic name "Please help in this problem" is so meaningless. Please remember to provide an explicit topic name.
Regards,
Lalit
Edit : Removed dbms_output and added the insert statement.
[Updated on: Wed, 15 October 2014 01:02] Report message to a moderator
|
|
|
Re: Please help in this problem [message #625865 is a reply to message #625847] |
Wed, 15 October 2014 02:49 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Just to be absolutely clear the table_name in
FOR table_name IN emp_cursor LOOP
Is a record group created by the for loop and it only exists inside the for loop.
It has no relationship to an actual oracle table of the same name.
To insert data from the cursor to the table you need to write an insert statement as mist and lalit both did.
Or, as lalit suggested, you could just remove the cursor and write a single insert/select statement to do the same job.
|
|
|
|
Re: Please help in this problem [message #625870 is a reply to message #625869] |
Wed, 15 October 2014 03:10 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
And once the table is created?
Create table as select is only used in rare cases, not general code, and given the OPs level of knowledge that fact should be pointed out.
|
|
|
|