How insert data in table randomly by using for loop. ORA-06550 - for-loop

I have a table (base-info) with some columnslike(name, family ,gen, city ,age, job, id) that have data; Now I want to build a new table by base-info data's randomly and Ofcourse I want to use for loop & insert into valuse sysntax; I wrote the commands but I faced ora_06550 error;
Declare
c1 number(3):=0;
c2 number(3):=0;
begin
for c1 in 1..200 loop
for c2 in 1..200 loop
insert into person p
(
id,
name,
family,
gen,
job,
city,
age
)
values
(
seq_person_id,
(select b.name from base_info b where b.id=c1) ,
( SELECT * FROM (SELECT b.family FROM base_info b ORDER BY DBMS_RANDOM.RANDOM) WHERE rownum=1;) ,
(select b.gen from base_info b where b.id=c1) ,
(SELECT * FROM (SELECT b.job FROM base_info b ORDER BY DBMS_RANDOM.RANDOM) WHERE rownum=1;) ,
(SELECT * FROM (SELECT b.city FROM base_info b ORDER BY DBMS_RANDOM.RANDOM) WHERE rownum=1;) ,
(SELECT * FROM (SELECT b.age FROM base_info b ORDER BY DBMS_RANDOM.RANDOM) WHERE rownum=1;)
);
end loop;
end loop;
end;
select t.*, t.rowid from PERSON t ;
I want to run it in PL/SQL .
it is error :
ORA-06550: line 7, column 6:
PL/SQL: ORA-00921: unexpected end of SQL command
ORA-06550: line 7, column 6:
PL/SQL: SQL Statement ignored
ORA-06550: line 18, column 112:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
( begin case declare end exit for goto if loop mod null
pragma raise return select update while with
<<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
json_exists json_value json_query json_object json_array
ORA-06550: line 20, column 106:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
) * & - + / at mod remainder rem with <an exponent (**)> and
or group having intersect minus order start union where
connect || multiset
The symbol ";" was ignored.
ORA-06550: line 21, column 107:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
) * & - + / at mod remainder rem with <an exponent (**)> and
or group having intersect minus order start union where
connect || multiset
The symbol ";" was ignored.
ORA-06550: line 22, column 106:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
) * & - + / at mod remainder rem with <an exponent (**)> and
or group having intersect minus order start union where
connect || multiset

Related

How to get the number of rows affected by an UPDATE statement

I am trying to get the number of rows affected by an UPDATE statement, however I am getting the following error:
ORA-06550: line 2, column 9:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table columns long
double ref char time timestamp interval date binary national
character nchar
The symbol "exception" was substituted for ";" to continue.
The query that I am executing is the following:
DECLARE
var_rows;
BEGIN
var_rows:=SQL%ROWCOUNT;
UPDATE {Product} SET {Product}.[Name] = concat({Product}.[Name], ' - test') WHERE {Product}.[ProductTypeId] = 2;
SELECT var_rows FROM DUAL;
END;
Use SQL%rowcount properly. i.e. immediately after the update
Example
create table tab1 as
select 1 id, 'a' col from dual union all
select 1, 'b' from dual;
set serveroutput on;
declare
rn int;
begin
update tab1
set col = 'z';
rn := SQL%rowcount;
dbms_output.put_line(rn);
end;
/
2
PL/SQL procedure successfully completed.

ORA-06550: Encountered "end-of-file" when expecting the following: . ( % ; The query runs fine, but is giving errors in the block

create or replace procedure personWithGivenCity(city1 in varchar) as
cursor c1 is select p.name
from person p
join address ad
on p.name=ad.name
where ad.city=city1;
c c1%rowtype;
begin
open c1;
loop
fetch c1 into c;
exit when c1%notfound;
dbms_output.put_line(c.name);
end loop;
close c1;
end;
/
-- Block which class the procedure
declare
city varchar2(10):='Vasco';
begin
personWithGivenCity(city);
end;
/
The query works fine without the block. But I'm getting end-of-file error at line 3 column 11.
Table structures
Person
name varchar2(10) primary key,
gender varchar2(10),
age number
Address
name varchar2(10) references person(name),
hno number,
laneno number,
city varchar2(10),
state varchar2(10)
The error
ORA-06550: line 3, column 11: PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: . ( % ; for

PLS-00103: Encountered the symbol "(" when expecting one of the following: <an identifier> <a double-quoted delimited-identifier> LONG_

When I try to run the below query I get the following error:
ERROR at line 6:
ORA-06550: line 6, column 30:
PLS-00103: Encountered the symbol "(" when expecting one of the following:
LONG_
double ref char time timestamp interval date binary national
character nchar
DECLARE
thisdb int;
maxDB int;
execStatement VARCHAR2 (120);
execStatement2 VARCHAR2 (120);
TYPE databaseIDs IS TABLE OF (EXECUTION_ID RAW (32));
BEGIN
INSERT INTO databaseIDs (EXECUTION_ID)
SELECT distinct jhist.EXECUTION_ID
FROM sysman.MGMT_JOB_HISTORY jhist, sysman.MGMT_JOB job
WHERE jhist.job_id=job.job_id and
job.job_owner='admin'
and jhist.step_status not in (1,5,17)
and start_time > (sysdate -1);
INSERT INTO databaseIDs (EXECUTION_ID)
SELECT distinct log_ID
FROM all_scheduler_job_log
WHERE owner = 'admin'
AND status <> 'SUCCEEDED'
AND log_date > (sysdate -1);
maxDB := select max(EXECUTION_ID) from databaseIDs;
thisdb := select min(EXECUTION_ID) from databaseIDs;
WHILE thisdb <= maxDB
LOOP
maxDB >= thisdb
END LOOP;
BEGIN
execStatement := (Select '
INSERT INTO TEST.JOB_FAILURES
SELECT distinct jhist.EXECUTION_ID,job_owner,job_name,
DECODE(step_status,
1, ''SCHEDULED'',
2, ''RUNNING'',
3, ''FAILED INIT'',
4, ''FAILED'',
5, ''SUCCEEDED'',
6, ''SUSPENDED'',
7, ''AGENT DOWN'',
8, ''STOPPED'',
9, ''SUSPENDED/LOCK'',
10, ''SUSPENDED/EVENT'',
11, ''SUSPENDED/BLACKOUT'',
12, ''STOP PENDING'',
13, ''SUSPEND PENDING'',
14, ''INACTIVE'',
15, ''QUEUED'',
16, ''FAILED/RETRIED'',
17, ''WAITING'',
18, ''SKIPPED'', step_status) AS STATUS,
cast(end_time AS timestamp) AS RUNDATE
FROM sysman.MGMT_JOB_HISTORY jhist, sysman.MGMT_JOB job
WHERE jhist.job_id=job.job_id and
job.job_owner='admin'
and jhist.step_status not in (1,5,17)
and start_time > (sysdate -1)
and jhist.EXECUTION_ID = '' + EXECUTION_ID + ''
WHERE NOT EXISTS ( SELECT distinct jhist.EXECUTION_ID
FROM sysman.MGMT_JOB_HISTORY jhist, sysman.MGMT_JOB job
WHERE jhist.job_id=job.job_id and
job.job_owner='DBadmin'
and jhist.step_status not in (1,5,17)
and start_time > (sysdate -1)
and jhist.EXECUTION_ID = '' + EXECUTION_ID + '';'from databaseIDs where EXECUTION_ID = thisdb);
--print execStatement
exec(execStatement)
execStatement2 := (Select '
INSERT INTO TEST.JOB_FAILURES
SELECT distinct owner,job_name,status, cast(log_date AS timestamp) as column1
FROM all_scheduler_job_log
WHERE
owner = 'admin' and
status <> 'SUCCEEDED'
and log_date > (sysdate -1)
and log_ID = '' + EXECUTION_ID + ''
WHERE NOT EXISTS ( SELECT distinct log_ID
FROM all_scheduler_job_log
WHERE
owner = 'admin' and
status <> 'SUCCEEDED'
and log_date > (sysdate -1)
and log_ID = '' + EXECUTION_ID + '';'from databaseIDs where EXECUTION_ID = thisdb);
--print execStatement
exec(execStatement2)
thisdb := (select min(EXECUTION_ID) from databaseIDs where EXECUTION_ID > thisdb)
END;
/
What am I missing?
You are trying to run code for SQL Server, or some other RDBMS, in Oracle. The syntaxes are not the same. For instance, the use of # to prefix variable names is not part of Oracle PL/SQL syntax. There are other issues as well, such as that individual commands should be terminated with semicolons.

plsql comparing table and view

I need to get comparison of columns between table and a view i choose to see if there are matching columns.(in PLSQL)
The columns that don't match need to be outputed as: column1 in view1 is missing in table1 etc.
This is so far i have done, but it gives me an error:
DECLARE
CURSOR c_col
IS
SELECT T.TABLE_NAME,
T.COLUMN_NAME,
V.TABLE_NAME,
V.COLUMN_NAME
FROM ALL_TAB_COLUMNS T
FULL JOIN ALL_TAB_COLUMNS V
ON T.column_name=V.column_NAME
AND v.table_name='EMP_V'
AND v.owner ='HR'
WHERE T. OWNER ='HR'
and T.TABLE_NAME='EMPLOYEES';
v_table c_col%rowtype;
begin
OPEN C_col;
LOOP
FETCH C_col into V_TABLe;
EXIT when C_col%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (v_table.table_name||' '||V_table.column_name);
end LOOP;
close c_col;
end;
this is the error i keep getting:
Error report -
ORA-06550: line 16, column 13:
PLS-00402: alias required in SELECT list of cursor to avoid duplicate column names
ORA-06550: line 16, column 13:
PL/SQL: Item ignored
ORA-06550: line 20, column 22:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 20, column 5:
PL/SQL: SQL Statement ignored
ORA-06550: line 22, column 27:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 22, column 5:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
Try this, for the error cause see the #Multisync comment
declare
cursor c_col is
select T.TABLE_NAME, T.COLUMN_NAME, V.TABLE_NAME VIEW_NAME,
V.COLUMN_NAME VIEW_COLUMN_NAME
from (select *
from ALL_TAB_COLUMNS T
where OWNER = 'HR'
and TABLE_NAME = 'EMPLOYEES') T
full outer join (select *
from ALL_TAB_COLUMNS
where owner = 'HR'
and table_name = 'EMP_V') V on T.column_name =
V.column_NAME
order by t.column_name, v.column_name;
v_table c_col%rowtype;
begin
open C_col;
loop
fetch C_col
into V_TABLe;
exit when C_col%notfound;
DBMS_OUTPUT.PUT_LINE(rpad(v_table.table_name || ' ' ||
V_table.column_name, 30, ' ') || '| ' ||
v_table.VIEW_NAME || ' ' ||
V_table.VIEW_COLUMN_NAME);
end loop;
close c_col;
end;

Cant figure out the error and resolution in PL SQL code

I have provided this code for fetching out all the table descriptions of all schemas in one database. I searched online and came up with the code below. I can't figure out the error.
Anyone who can either help with this error OR provide me an alternative to the problem
SQL> Begin
2 For q in (select distinct owner from dba_objects)
3 loop
4 for r in (select table_name, owner from all_tables where owner = 'q.owner')
5 loop
6 dbms_output.put_Line('table '||r.table_name);
7 execute immediate 'desc ' || r.table_name
8 end loop;
9 end loop;
10 end;
11 /
end loop;
*
ERROR at line 8:
ORA-06550: line 8, column 3:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
. ( * # % & = - + ; < / > at in is mod remainder not rem
return returning <an exponent (**)> <> or != or ~= >= <= <>
and or like like2 like4 likec between into using || bulk
member submultiset
The symbol ";" was substituted for "END" to continue.
Try:
select *
from all_tab_columns
where owner = 'MY_OWNER_NAME'
order by owner,
table_name,
column_id;
Use the reference here to select the column of interest to you. You can add other predicates if you're only interested in character data types, for example.
Line 7: execute immediate 'desc ' || r.table_name
You forgot to put ;

Resources