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

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"

Related

\copy statement in PostgreSQL using R

I want to execute the following statement on postgresql sending it from R:
tname = 'foo'
con = some_connection_to_postgresql
q = paste("\\COPY", tname, "FROM 'foo.csv';")
dbGetQuery(con, q)
However, when I execute it, I get the following error:
Error: <SQL> '\COPY foo FROM 'foo.csv''
nanodbc/nanodbc.cpp:1587: 42601: ERROR: syntax error at or near "\";
Error while executing the query
However, the same script written from the terminal works perfectly fine.
\copy is not a postgresql statement. the psql CLI converts \copy...from filename into copy ... from stdin; and then pipes the file's contents over the postgres connection.
you'll have to do the same if you want to use copy.

Why am I getting: database is locked, in an SQLite3 script?

I'm getting an error when running an SQLite script.
--drop use table before replacing it
DROP TABLE IF EXISTS db.use;
--Create the use table in the saved database
CREATE TABLE db.use AS SELECT * FROM use2; -- this is the line that generates the error: Error: near line 145: database is locked
Are these two statements run asynchronously or something? I don't understand what's causing the error, but I'm wondering if it has to do with that.
Might there be a way to run the script in a lock-step manner, i.e. non-asynchronously?
This is how I was running the command: sqlite3 --init script_name.sql dbname.db, and elsewhere in the script I had an ATTACH statement reading the same database dbname.db. Essentially reading the same file twice.
The way I solved this was by executing the script in the sqlite3 shell:
sqlite3> .read script_name.sql
Have you tried to add a commit statement after the drop statement?
I think that would make sure the create table statement run after the drop statement is totally done.

how to include new line in scipt log which is calling sql file and that sql file is giving lot of errors

I have written a shell script which is calling another sql file, which is disabling triggers in oracle.
but this sql file is generating lot of oracle errors and in log file of script, I am getting response like
ORA-21021 -- oracle errros ORA-20111 -- oracle errors
I would like to add a new line getting the oracle errors something like
ORA-21021 --** oracle errors**
ORA-20111 --** oracle errors**
How this can be done?
sql file code:
alter trigger trigger_name1 disable;
alter trigger trigger_name2 disable;
alter trigger trigger_name3 disable;
alter trigger trigger_name4 disable;
alter trigger trigger_name4 disable;
A solution with perl
perl -pe 's/ORA-\d/\n$&/g' <oldfile >newfile
to add a newline before sequences ORA- followed by a number (\d)
I was able to achieve this by below method:
SQL=$(echo "$SQL" | sed -e 's/ERROR/\\n\rERROR/g')
echo $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: ;

oracle 10g and define instruction

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;

Resources