oracle 10g and define instruction - plsql

I want to compile this PL/SQL program in the SQL window that belongs to the Database Home page:
DEFINE p_annual_sal=60000
DECLARE
v_sal NUMBER(9,2):=&p_annual_sal;
BEGIN
v_sal:=v_sal/12;
DBMS_OUTPUT.PUT_LINE('The monthly salary is '|| TO_CHAR(v_sal));
END;
When I hit run I got the following message:
ORA-00900: invalid SQL statement
Even though it works under SQL*Plus of the command line, what it could be the issue?

It works in SQL*Plus because DEFINE is a SQL*Plus command.
When you refer to the "database home page" I believe you're referring to Oracle Apex's SQL Commands window, which can run SQL and PL/SQL code, but not SQL*Plus commands.
You can do this instead - Apex will prompt you for the input bind variables, if any:
DECLARE
v_sal NUMBER(9,2):= :p_annual_sal;
BEGIN
v_sal:=v_sal/12;
dbms_output.put_line('The monthly salary is '|| TO_CHAR(v_sal));
END;

Related

How to run pl/sql statements in Control M for database job/task(execution type :- Embedded Query)

I have pl/sql statement something like mentioned below, which executes successfully in oracle sql developer but same when am trying to execute through control M database task (execution type :- Embedded Query) am getting error "Invalid SQL statements"
SQL statements :-
TRUNCATE TABLE TEST;
COMMIT;
EXECUTE USP_LOADTESTTables;
COMMIT;
create a query file named plsql_query.ql then use it to execute from controlM as command line job.
Sqlcmd -E -server\instance_name -Q "EXEC plsql_query.ql"

Cannot use default Oracle 11G package utl_file

I'm using PLSQL Developer client to access my 11G Oracle database. My understanding is that these are the default packages that come with this version. However, if I try to declare a utl_file.file_type variable, I get the following error:
PLS-00201: identifier 'UTL_FILE' must be declared
My program:
declare
l utl_file.file_type;
begin
NULL;
end;
I've tried to declare, for instance, a DBMS_LOB.BFILE, and it compiled succesfully, that prooves that some other packages are imported in my block.
Aren't all Oracle default packages automatically imported?
My assumption that if it's yours database, you have got pass for user SYS. If it is, you should check if package utl_file is installed. You can connect by SYS and execute this statement
SELECT * FROM dba_objects WHERE object_name = 'UTL_FILE'
You should see if that package exists. Also you should see object type 'SYNONYM' with owner 'PUBLIC'. If package present in DB, but there is no synonym for it, you can create it using this statement
CREATE PUBLIC SYNONYM OF UTL_FILE FOR SYS.UTL_FILE
If there is no such package - you should install it, by executing script, which is located in
{ORACLE_HOME}/rdbms/admin/utlfile.sql

Oracle trigger error, 10g to 11g export

i am trying to export a 10g database to 11g and receieving error(execution completed with warning) at the row that tries to create the trigger.
--------------------------------------------------------
-- DDL for Trigger TR_INS_DATACARD
--------------------------------------------------------
CREATE OR REPLACE TRIGGER "AFTARSIV"."TR_INS_DATACARD" BEFORE INSERT ON fichas REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW BEGIN SELECT fichas_seq.NEXTVAL INTO :NEW.clave FROM DUAL; END;
/
ALTER TRIGGER "AFTARSIV"."TR_INS_DATACARD" ENABLE;
SQL command works fine with 10g, it even creates the trigger at 11g but the trigger has this error:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: ;

NOHUP Command In Linux

I am issuing a command
$nohup sqlplus "/ as sysdba" #script.sql &
And on executing this nohup.out file contains this error:
Error 45 initializing SQL*Plus
How to resolve it?
Check the command terminators. If you have anonymous plsql blocks, typically they would look like
DECLARE
some stuff
BEGIN
sql statements;
END;
You have to add another line with a lone "/" after it, or you will get this error.

ALTER SESSION SET NLS_TERRITORY=ITALY throws ORA-00911

If I try to execute the statement ALTER SESSION SET NLS_TERRITORY=ITALY in SQL Developer, I get no errors. But if I run it through a Win Forms application of mine, connecting through the System.Data.OracleClient provider, I get the "ORA-0911: invalid character" error. Why? My version of Oracle is 10.2.0.1.0
Solved it. I was executing
ALTER SESSION SET NLS_TERRITORY=ITALY;
pl/sql block: DECLARE ... BEGIN ... END;
/
I removed the semicolon and replaced it with
ALTER SESSION SET NLS_TERRITORY=ITALY
/
pl/sql block: DECLARE ... BEGIN ... END;
/
and it works now
Try to wrap it in execute immediate:
execute immediate 'ALTER SESSION SET NLS_TERRITORY=ITALY';

Resources