Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
i'm doing the follwing question
Managing Locked Accounts – The utility should be able to identify each locked
account that was locked because of invalid login attempts. The utility should further
unlock accounts that have been locked for more than a week.
----------------------------------------my code------------------------------------------
procedure Managing_Locked
is
num int;
V_SQL varchar(50);
begin
for x in (select USERNAME,LOCK_DATE,ACCOUNT_STATUS,PROFILE from DBA_USERS where ACCOUNT_STATUS ='LOCKED(TIMED)')
loop
dbms_output.put_line('USERNAME: '|| x.USERNAME);
dbms_output.put_line('LOCK_DATE: '|| x.LOCK_DATE );
dbms_output.put_line('ACCOUNT_STATUS: '||x.ACCOUNT_STATUS);
dbms_output.put_line('PROFILE: ' ||x.PROFILE);
dbms_output.put_line('*********************');
select ((sysdate - x.LOCK_DATE)) into num from dual;
if(num>7)
then
V_SQL := 'ALTER USER'|| x.USERNAME ||'ACCOUNT UNLOCK';
dbms_output.put_line(x.USERNAME||' UNLOCK');
Execute immediate(V_SQL);
end if;
end loop;
end;
error 00940. 00000 - "invalid ALTER command"
i getting that error and i don't see anything wrong with the alter command
Just in order to catch each possible status the where clause should be this one:
WHERE ACCOUNT_STATUS IN (
'LOCKED(TIMED)',
'EXPIRED & LOCKED(TIMED)',
'EXPIRED(GRACE) & LOCKED(TIMED)')
or
WHERE ACCOUNT_STATUS LIKE '%LOCKED(TIMED)'
add a space before the word account.
The user name is missing with the word "account", so the command you issue is "alter user usernameaccount unlock" ...
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
DECLARE
CURSOR c_CUR IS
SELECT id, table_name, is_deleted FROM truncate_table WHERE IS_DELETED=1
ORDER BY id DESC;
BEGIN
FOR C IN c_CUR LOOP
EXECUTE IMMEDIATE 'TRUNCATE TABLE'|| C.table_name;
END LOOP;
END;
I HAVE AN ERROR TABLE OR CLUSTER KEYWORD IS MISSING
It is very clear that you are not creating a dynamic query properly. Space is missing between TABLE'|| C.table_name
It must be something like this:
EXECUTE IMMEDIATE 'TRUNCATE TABLE '|| C.table_name; -- see space after TABLE
Cheers!!
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I create a trigger
create or replace TRIGGER trj2
BEFORE INSERT OR UPDATE OF
customer_ID ON Reserve
FOR EACH ROW
DECLARE
new_fk1_NR VARCHAR2(7);
BEGIN
SELECT NR
INTO new_fk1_NR
FROM customers
WHERE :NEW.customer_ID= customers.ID;
:NEW.NR_K := new_fk1_NR;
END;
It is working fine for update statements, but for insert it give this error
ORA-01403: no data found ORA-06512: at "SYSTEM.WRITERESPROT", line 76
ORA-06512: at "SYSTEM.LRES_PROTOKOLL", line 38
ORA-04088: error during execution of trigger 'SYSTEM.LRES_PROTOKOLL'
I couldn't find links or explanations about what does this mean,
any help please?
The problem is when no rows are returned. A simple way to ensure that exactly one row is returned is to use aggregation:
SELECT MAX(NR)
INTO new_fk1_NR
FROM customers
WHERE :NEW.customer_ID = customers.ID;
An aggregation query with no GROUP BY returns exactly one row, even when no rows match. If no rows match, the result is NULL.
This error is raised becaue your SELECT ... INTO ... query returned no record. You would need to either ensure that the query always returns one record, or to handle that exception.
Something like this will handle exceptions:
create or replace trigger trj2
before insert or update of customer_id on reserve
for each row
declare
new_fk1_nr varchar2(7);
begin
select nr into new_fk1_nr from customers where :new.customer_id= customers.id;
:new.nr_k := new_fk1_nr;
exception
when NO_DATA_FOUND
then raise_application_error(
-20010,
'this could not happen since customer does not exist'
);
when others
then raise_application_error(-20011,'Unknown Exception');
end;
/
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
i am trying to create a table using below code.
set serveroutput on;
DECLARE
cursor c1 is select '''create table demo1 (demo varchar2(100))''' c2 from dual;
testvar c1%rowtype;
BEGIN
open c1;
fetch c1 into testvar;
close c1;
execute immediate testvar.c2;
END;
but it is giving
ORA-00900: invalid SQL statement
ORA-06512: at line 8
00900. 00000 - "invalid SQL statement"
What is wrong in this code.
You need nothing more than except these 3 lines of code if you really want to do it dynamically using a PLSQL block. No need for selecting from dual .
declare
vsql varchar2 (100) := 'create table demo1 (demo varchar2(100))';
begin
execute immediate vsql;
end;
Note: It does not makes any sense selecting create table statement from a select. If you have any other specific requirement, please mention so that people can help you here.
Btw, you block will work simplly once you remove the extra ' as mentioned by William
set serveroutput on;
DECLARE
cursor c1 is select 'create table demo1 (demo varchar2(100))' c2 from dual;
testvar c1%rowtype;
BEGIN
open c1;
fetch c1 into testvar;
close c1;
execute immediate testvar.c2;
END
;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
DROP TABLE a CASCADE CONSTRAINTS;
CREATE TABLE a(
cyear VARCHAR2(4));
CREATE TRIGGER current_year
BEFORE INSERT ON cyear
FOR EACH ROW SET NEW.year = year(NOW());
EDIT:
I tried this,
CREATE TRIGGER current_year
BEFORE INSERT ON a
FOR EACH ROW
BEGIN
:NEW.cyear = TO_CHAR(SYSDATE, 'YYYY');
END current_year;
I keep getting the PLS-00103 error.
Trigger created on tables, not on columns
In Oracle variables are not assigned with SET
There is no build-in function called NOW in Oracle
NEW and OLD are accessible only in WHEN clause; in other places they should be preceded by colon (:NEW, :OLD)
END keyword is missed at the end (and BEGIN in the beginning of the trigger body)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Whats wrong with the following procedure?? I have checked the code for syntax errors but I m unable to find one.
CREATE OR REPLACE Edit_premium_amt
(
policy_number IN number(4),
new_premium_type IN varchar2(4)
)
IS
discount_amount number(6,2);
premium_amts number(11,2);
policy_amts number(11);
dur number(5);
prem_type varchar2(4);
disc_weigh varchar2(2);
disc_perc number(2);
prem_type_int number(2,1);
BEGIN
prem_type:=new_premium_type;
UPDATE policy SET premium_type=new_premium_type WHERE policy_id=policy_number;
SELECT policy_amt,duration INTO policy_amts,dur WHERE policy_id=policy_number;
SELECT disc_weightage INTO disc_weigh FROM disc_details WHERE duration=dur;
SELECT percent INTO disc_perc FROM disc_calculation WHERE premium_type=prem_type AND
weightage=disc_weigh;
CASE prem_type
WHEN 'HY' THEN prem_type_int:=2.0;
WHEN 'Y' THEN prem_type_int:=1.0;
ELSE prem_type_int:=0.5;
END CASE;
discount_amount:= ((policy_amts)/dur)/prem_type_int))*disc_perc;
premium_amts:=policy_amts-discount_amount;
UPDATE policy SET premium_amt=premium_amts
WHERE policy_id=policy_number;
END Edit_premium_amt;
You must say what you are creating or replacing
In this case CREATE OR REPLACE PROCEDURE Edit_premium_amt............