Problem executing SQL scripts
Hi,
I am unable to execute any SQL script in my APEX application.
I uploaded a SQL Script using the SQL Workshop->SQL Scripts->Upload option.
this is the script tat i uploaded :
SELECT COUNT(*),'PROJECT_TEAM' FROM PROJECT_TEAM
SELECT COUNT(*),'PROJECTS' FROM PROJECTS
SELECT COUNT(*),'PROJECT_TASK_DETAILS' FROM PROJECT_TASK_DETAILS
But when I click on the Run button, the script doesn't execute and also I am unable to edit the script tat i uploaded.
Any thoughts on whr I am goin wrong or any solutions??
Thanks,
Janani
Hi Janani,
You can exec one select statement each time.
Best,
Othman
Similar Messages
-
Execute SQL scripts in Oracle DB
Hi ,
Can someone give stepbystep flow to execute sql scripts(patches) in oracle db on unix server.SQL scripts and patches are generally two completely different things.
Assuming you are referring to patches that you download from My Oracle Support (MOS), each patch and patchset comes with a README. That README has specific instructions for installing that particular patch in whatever version of Oracle you have running on whatever operating system you have with whatever database options you have in use. It wouldn't make sense to try to summarize that document here-- we would undoubtedly leave something out that may be important to you and there may be patch-specific instructions.
Justin -
Hi Folks,
I used expdp utility to export all Oracle scheduler jobs and chains with below method, after that generate sql script by impdp, later on executing sql script encountered some errors.
Only chain step and chain rule for executing script. Does anyone bright me some light? Thanks!
My env: Oracle 11g + Oracle Linux 5.5
My steps as below:
1. export(expdp) oracle scheduler job(chain)
2. generate sql script by impdp.
3. remove orginal scheduler job(chain)
4. execute sql script
5. job with no chain well but job with chain failed
[oracle@linux1 ~]$ expdp scott/tiger directory=db_dump_dir dumpfile=scott_job.dmp include=procobj:\" in \(select \
> name from sys.obj$ where type\# in \(46,59,66,67,68,69,72,74,79\)\)\" schemas=scott
Export: Release 11.2.0.1.0 - Production on Tue Dec 3 17:42:31 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_SCHEMA_01": scott/******** directory=db_dump_dir dumpfile=scott_job.dmp include=procobj:" in (select name from sys.obj$ where type# in (46,59,66,67,68,69,72,74,79))" schemas=scott
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 0 KB
Processing object type SCHEMA_EXPORT/POST_SCHEMA/PROCOBJ
Master table "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
Dump file set for SCOTT.SYS_EXPORT_SCHEMA_01 is:
/u03/database/usbo/BNR/dump/scott_job.dmp
Job "SCOTT"."SYS_EXPORT_SCHEMA_01" successfully completed at 17:42:54
[oracle@linux1 ~]$ impdp scott/tiger sqlfile=scott_job.sql directory=db_dump_dir dumpfile=scott_job.dmp logfile=imp_scott_job.log
Import: Release 11.2.0.1.0 - Production on Tue Dec 3 17:43:04 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Master table "SCOTT"."SYS_SQL_FILE_FULL_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_SQL_FILE_FULL_01": scott/******** sqlfile=scott_job.sql directory=db_dump_dir dumpfile=scott_job.dmp logfile=imp_scott_job.log
Processing object type SCHEMA_EXPORT/POST_SCHEMA/PROCOBJ
Job "SCOTT"."SYS_SQL_FILE_FULL_01" successfully completed at 17:43:07
[oracle@linux1 ~]$ more /u03/database/usbo/BNR/dump/scott_job.
scott_job.dmp scott_job.sql
[oracle@linux1 ~]$ more /u03/database/usbo/BNR/dump/scott_job.sql
-- CONNECT SCOTT
ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
-- new object type path: SCHEMA_EXPORT/POST_SCHEMA/PROCOBJ
BEGIN
BEGIN
dbms_rule_imp_obj.import_rule('"SCOTT"','"CHAIN_RULE_1"','1=1',NULL, 'First link in the chain.',0,NULL);
END;
COMMIT;
END;
BEGIN
BEGIN
dbms_rule_imp_obj.import_rule('"SCOTT"','"CHAIN_RULE_2"',':"CHAIN_STEP_1".COMPLETED = ''TRUE''',NULL, 'Second link in the chain.',0,NULL);
END;
COMMIT;
END;
BEGIN
BEGIN
dbms_rule_imp_obj.import_rule('"SCOTT"','"CHAIN_RULE_3"',':"CHAIN_STEP_2".COMPLETED = ''TRUE''',NULL, 'Third link in the chain.',0,NULL);
END;
COMMIT;
END;
BEGIN
BEGIN
dbms_rule_imp_obj.import_rule('"SCOTT"','"CHAIN_RULE_4"',':"CHAIN_STEP_3".COMPLETED = ''TRUE''',NULL, 'End of the chain.',0,NULL);
END;
COMMIT;
END;
BEGIN
BEGIN
dbms_rule_imp_obj.import_rule_set('"SCHED_RULESET$1"','"SCHED_EV_CTX$1"',NULL, 0);
END;
COMMIT;
END;
BEGIN
dbms_scheduler.create_program('"TEST_PROC_1"','PLSQL_BLOCK',
'BEGIN
INSERT INTO tb_schduler (id, descr, cr_date)
VALUES (tb_schduler_seq.NEXTVAL, ''test_proc_1'', SYSDATE);
COMMIT;
END;'
,0, TRUE,
'Program for first link in the chain.'
COMMIT;
END;
BEGIN
dbms_scheduler.create_program('"TEST_PROC_3"','PLSQL_BLOCK',
'BEGIN
INSERT INTO tb_schduler (id, descr, cr_date)
VALUES (tb_schduler_seq.NEXTVAL, ''test_proc_3'', SYSDATE);
COMMIT;
END;'
,0, TRUE,
'Program for last link in the chain.'
COMMIT;
END;
BEGIN
dbms_scheduler.create_program('"TEST_PROC_2"','PLSQL_BLOCK',
'BEGIN
INSERT INTO tb_schduler (id, descr, cr_date)
VALUES (tb_schduler_seq.NEXTVAL, ''test_proc_2'', SYSDATE);
COMMIT;
END;'
,0, TRUE,
'Program for second link in the chain.'
COMMIT;
END;
BEGIN
dbms_scheduler.create_chain('"TEST_CHAIN_1"', evaluation_interval=>NULL, comments=>'A test chain.'
, rule_set_name=>'"SCHED_RULESET$1" '
dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_1"', program_name=>'"TEST_PROC_1"');
dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_2"', program_name=>'"TEST_PROC_2"');
dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_3"', program_name=>'"TEST_PROC_3"');
COMMIT;
END;
BEGIN
dbms_scheduler.create_job('"TEST_CHAIN_1_JOB"',
job_type=>'CHAIN', job_action=>
'test_chain_1'
, number_of_arguments=>0,
start_date=>TO_TIMESTAMP_TZ('03-DEC-2013 05.38.56.718161000 PM +08:00','DD-MON-RRRR HH.MI.SSXFF AM TZR','NLS_DATE_LANGUAGE=english'), repeat_interval=>
'freq=minutely; interval=2'
, end_date=>TO_TIMESTAMP_TZ('03-DEC-2013 06.08.56.000000000 PM +08:00','DD-MON-RRRR HH.MI.SSXFF AM TZR','NLS_DATE_LANGUAGE=english'),
job_class=>'"DEFAULT_JOB_CLASS"', enabled=>FALSE, auto_drop=>TRUE,comments=>
NULL
COMMIT;
END;
[oracle@linux1 ~]$ export ORACLE_SID=usbo
[oracle@linux1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Tue Dec 3 17:44:43 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
sys@USBO> show parameter db_name
NAME TYPE VALUE
db_name string usbo
sys@USBO> conn scott/tiger;
Connected.
--remove job and chain.
scott@USBO> EXEC DBMS_SCHEDULER.drop_job(job_name => 'test_chain_1_job');
EXEC DBMS_SCHEDULER.drop_chain (chain_name => 'test_chain_1');
EXEC DBMS_SCHEDULER.drop_program (program_name => 'test_proc_1');
EXEC DBMS_SCHEDULER.drop_program (program_name => 'test_proc_2');
EXEC DBMS_SCHEDULER.drop_program (program_name => 'test_proc_3');
PL/SQL procedure successfully completed.
scott@USBO> @/u03/database/usbo/BNR/dump/scott_job.sql
Session altered.
Session altered.
Session altered.
Session altered.
Session altered.
Session altered.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
BEGIN
ERROR at line 1:
ORA-24150: evaluation context SCOTT.SCHED_EV_CTX$1 does not exist
ORA-06512: at "SYS.DBMS_RULEADM_INTERNAL", line 28
ORA-06512: at "SYS.DBMS_RULE_IMP_OBJ", line 40
ORA-06512: at line 3
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
PL/SQL procedure successfully completed.
BEGIN
ERROR at line 1:
ORA-24141: rule set SCOTT.SCHED_RULESET$1 does not exist
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.DBMS_ISCHED", line 1694
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1638
ORA-06512: at line 5
PL/SQL procedure successfully completed.Thanks all of you!
Hi DK2010,
I took some test that the data dict(dba_rule_sets/dba_evaluation_contexts) no any data returned after I had removed the job.
So I tried to create evaluation context and re-executed script(only exception setion.) the first error has gone. For the second still have some issue.
---->no any returned
scott@USBO> select * from dba_rule_sets where rule_set_owner='SCOTT';
no rows selected
scott@USBO> select * from dba_evaluation_contexts WHERE evaluation_context_owner='SCOTT';
no rows selected
-->add new EVALUATION CONTEXT
scott@USBO> exec DBMS_RULE_ADM.CREATE_EVALUATION_CONTEXT('SCOTT.SCHED_EV_CTX$1');
PL/SQL procedure successfully completed.
--->now it looks fine
scott@USBO> BEGIN
2 BEGIN
3 dbms_rule_imp_obj.import_rule_set('"SCHED_RULESET$1"','"SCHED_EV_CTX$1"',NULL, 0);
4 END;
5
6 COMMIT;
7 END;
8 /
PL/SQL procedure successfully completed.
--->add new rule set, it prompt aleady exists
scott@USBO> exec DBMS_RULE_ADM.CREATE_RULE_SET('SCOTT.SCHED_RULESET$1')
BEGIN DBMS_RULE_ADM.CREATE_RULE_SET('SCOTT.SCHED_RULESET$1'); END;
ERROR at line 1:
ORA-24153: rule set SCOTT.SCHED_RULESET$1 already exists
ORA-06512: at "SYS.DBMS_RULEADM_INTERNAL", line 28
ORA-06512: at "SYS.DBMS_RULE_ADM", line 138
ORA-06512: at line 1
-->chain rule still could not find.
scott@USBO> @job_chain_rules.sql
no rows selected
-->rerun
scott@USBO> BEGIN
2 dbms_scheduler.create_chain('"TEST_CHAIN_1"', evaluation_interval=>NULL, comments=>'A test chain.'
3 , rule_set_name=>'"SCHED_RULESET$1" '
4 );
5 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_1"', program_name=>'"TEST_PROC_1"');
6 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_2"', program_name=>'"TEST_PROC_2"');
7 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_3"', program_name=>'"TEST_PROC_3"');
8 COMMIT;
9 END;
10 /
BEGIN
ERROR at line 1:
ORA-27477: "SCOTT.TEST_CHAIN_1" already exists
ORA-06512: at "SYS.DBMS_ISCHED", line 1148
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1598
ORA-06512: at line 2
-->drop chain
scott@USBO> exec dbms_scheduler.drop_chain('TEST_CHAIN_1');
BEGIN dbms_scheduler.drop_chain('TEST_CHAIN_1'); END;
ERROR at line 1:
ORA-27479: Cannot drop "SCOTT.TEST_CHAIN_1" because other objects depend on it
ORA-06512: at "SYS.DBMS_ISCHED", line 1319
ORA-06512: at "SYS.DBMS_ISCHED", line 1222
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1854
ORA-06512: at line 1
scott@USBO> exec dbms_scheduler.drop_chain('TEST_CHAIN_1',force=>TRUE);
PL/SQL procedure successfully completed.
scott@USBO> BEGIN
2 dbms_scheduler.create_chain('"TEST_CHAIN_1"', evaluation_interval=>NULL, comments=>'A test chain.'
3 , rule_set_name=>'"SCHED_RULESET$1" '
4 );
5 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_1"', program_name=>'"TEST_PROC_1"');
6 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_2"', program_name=>'"TEST_PROC_2"');
7 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_3"', program_name=>'"TEST_PROC_3"');
8 COMMIT;
9 END;
10 /
BEGIN
ERROR at line 1:
ORA-24141: rule set SCOTT.SCHED_RULESET$1 does not exist --->still returned no rule set
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.DBMS_ISCHED", line 1694
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1638
ORA-06512: at line 5
scott@USBO> exec DBMS_RULE_ADM.CREATE_RULE_SET('SCOTT.SCHED_RULESET$1')
PL/SQL procedure successfully completed.
scott@USBO> BEGIN
2 dbms_scheduler.create_chain('"TEST_CHAIN_1"', evaluation_interval=>NULL, comments=>'A test chain.'
3 , rule_set_name=>'"SCHED_RULESET$1" '
4 );
5 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_1"', program_name=>'"TEST_PROC_1"');
6 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_2"', program_name=>'"TEST_PROC_2"');
7 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_3"', program_name=>'"TEST_PROC_3"');
8 COMMIT;
9 END;
10 /
BEGIN
ERROR at line 1:
ORA-27477: "SCOTT.TEST_CHAIN_1" already exists
ORA-06512: at "SYS.DBMS_ISCHED", line 1148
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1598
ORA-06512: at line 2
scott@USBO> exec dbms_scheduler.drop_chain('TEST_CHAIN_1',force=>TRUE);
PL/SQL procedure successfully completed.
scott@USBO> BEGIN
2 dbms_scheduler.create_chain('"TEST_CHAIN_1"', evaluation_interval=>NULL, comments=>'A test chain.'
3 , rule_set_name=>'"SCHED_RULESET$1" '
4 );
5 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_1"', program_name=>'"TEST_PROC_1"');
6 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_2"', program_name=>'"TEST_PROC_2"');
7 dbms_scheduler.define_chain_step('"TEST_CHAIN_1"', step_name=>'"CHAIN_STEP_3"', program_name=>'"TEST_PROC_3"');
8 COMMIT;
9 END;
10 /
BEGIN
ERROR at line 1:
ORA-24141: rule set SCOTT.SCHED_RULESET$1 does not exist
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95
ORA-06512: at "SYS.DBMS_ISCHED", line 1694
ORA-01403: no data found
ORA-06512: at "SYS.DBMS_SCHEDULER", line 1638
ORA-06512: at line 5
Would you like to give me more clue?
Thanks again. -
How to execute sql scripts from Powershell across multiple databases
Re: How to execute sql scripts from Powershell across multiple databases
I have an tsql script that I want to run across a list of databases. How is the best way to do this in Powershell? Thanks.My example below, using just the SMO and not breaking up the batches, the ExecuteWithResults give the following error when the .sql file contains a GO. My script files are as simple as a DECLARE and then a GO.
WARNING: SQL Script Failed
The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence. This is likely caused by a user-specified "format-list" comm
and which is conflicting with the default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
Also, when executing from the ISE, is there a way to force the ISE to release the files. I am having to close the ISE and reopen my script every time I want to make a testing change to the .sql file.
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
$scriptspath = "C:\temp\psExecuteSQLScripts\scripts"
$SQLServer = "fidevc10"
$SQLDB = "Bank03"
# Create SMO Server Object
$Server = New-Object ('Microsoft.SQLServer.Management.Smo.Server') $SQLServer
# Get SMO DB Object
$db = $Server.Databases[$SQLDB]
# Load All SQL Scripts in Directory
$scripts = Get-ChildItem -Path (Join-Path $scriptspath "*") -Include "*.sql" -Recurse
# Loop through each script and execute
foreach ($SQLScript in $scripts)
$fullpath = $SQLScript.FullName
# Read the Script File into Powershell Memory
$reader = New-Object System.IO.StreamReader($fullpath)
$script = $reader.ReadToEnd()
# Execute SQL
Write-Host "Executing $SQLScript on $SQLDB...."
try
$ds = $db.ExecuteWithResults($script)
Foreach ($t in $ds.Tables)
Foreach ($r in $t.Rows)
Foreach ($c in $t.Columns)
Write-Host $c.ColumnName "=" $r.Item($c)
Write-Host "Complete"
catch [Exception]
Write-Warning "SQL Script Failed"
echo $_.Exception|format-list -force
Write-Host " " -BackgroundColor DarkCyan -
How to execute SQL Script using windows powershell(using invoke-sqlcmd or any if)
OS : Windows server 2008
SQL Server : SQL Server 2012
Script: Test.sql (T-SQL) example : "select name from sys.databases"
Batch script: windows MyBatchscript.bat ( here connects to sql server using sqlcmd and output c:\Testput.txt)
(sqlcmd.exe -S DBserverName -U username -P p@ssword -i C:\test.sql -o "c:\Testoutput.txt) ---it working without any issues.....
This can execute if i double click MyBatchscript.bat file and can see the output in c:\testput.txt.
Powershell: Similarly, How can i do in powershell 2.0 or higher versions? can any one give full details with each step?
I found some of them online, but nowhere seen clear details or examples and it not executing through cmd line (or batch script).
example: invoke-sqlcmd -Servernameinstance Servername -inputfile "c:\test.sql" | out-File -filepath "c:\psOutput.txt" --(call this file name MyTest.ps1)
(The above script working if i run manually. I want to run automatic like double click (or schedule with 3rd party tool/scheduler ) in Batch file and see the output in C drive(c:\psOutput.txt))
Can anyone Powershell experts give/suggest full details/steps for this. How to proceed? Is there any configurations required to run automatic?
Thanks in advance.Testeted the following code and it's working.....thanks all.
Execute sql script using invoke-sqlcmd with batch script and without batch script.
Option1: using Import sqlps
1.Save sql script as "C:\scripts\Test.sql" script in side Test.sql: select name from sys.databases
2.Save Batch script as "C:\scripts\MyTest.bat" Script inside Batch script:
powershell.exe C:\scripts\mypowershell.ps1
3.Save powershell script as "C:\scripts\mypowershell.ps1"
import-module "sqlps" -DisableNameChecking
invoke-sqlcmd -Servername ServerName -inputFile "C:\scripts\Test.sql" | out-File -filepath "C:\scripts\TestOutput.txt"
4.Run the Batch script commandline or double click then can able to see the output "C:\scripts\TestOutput.txt" file.
5.Connect to current scripts location cd C:\scripts (enter)
C:\scripts\dir (enter )
C:\scripts\MyTest.bat (enter)
Note: can able to see the output in "C:\scripts" location as file name "TestOutput.txt".
Option2: Otherway, import sqlps and execution
1.Save sql script as "C:\scripts\Test.sql" script in side Test.sql: select name from sys.databases
2.Save powershell script as "C:\scripts\mypowershell.ps1"
# import-module "sqlps" -DisableNameChecking #...Here it not required.
invoke-sqlcmd -Servername ServerName -inputFile "C:\scripts\Test.sql" | out-File -filepath "C:\scripts\TestOutput.txt"
3.Connect to current scripts location
cd C:\scripts (enter)
C:\scripts\dir (enter )
C:\scripts\powershell.exe sqlps C:\scripts\mypowershell.ps1 (enter)
Note: can able to see the output in "C:\scripts" location as file name "TestOutput.txt". -
ORA-27369 Exit-Code: 255 when executing sql script as job
Dear all
I'd like to find and compile all invalid objects in an instance. This should be done every day as a scheduled job with the use of DBMS_SCHEDULER.
For this, I set up the following sql-script:
---------start script--------------
set heading off;
set feedback off;
set echo off;
Set lines 999;
Spool /tmp/run_invalid.sql
select
'ALTER ' || OBJECT_TYPE || ' ' ||
OWNER || '.' || OBJECT_NAME || ' COMPILE;'
from
dba_objects
where
status = 'INVALID'
spool off;
set heading on;
set feedback on;
set echo on;
@/tmp/run_invalid.sql
exit
------ end script ----
The script ist working well when executed manualy via sqlplus. As you can see, it spools the commands to a second file (run_invalid.sql) which is the beeing executed to compile the invalid objects found.
I now want to schedule this script via DBMS_SCHEDULER (running the job every day at 7AM). Creation of the job:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'compile_invalid_objects',
job_type => 'EXECUTABLE',
job_action => '/home/oracle/scripts/sql/compile_invalid_objects.sql',
start_date => trunc(sysdate)+1+7/24,
repeat_interval => 'trunc(sysdate)+1+7/24',
enabled => TRUE,
comments => 'SQL-Script, und invalid objects zu finden und zu kompilieren'
END;
Manualy execute and error message:
BEGIN
DBMS_SCHEDULER.RUN_JOB (job_name => 'compile_invalid_objects',
use_current_session => true);
END;
FEHLER in Zeile 1:
ORA-27369: Job vom Typ EXECUTABLE nicht erfolgreich mit Exit-Code: 255
ORA-06512: in "SYS.DBMS_ISCHED", Zeile 150
ORA-06512: in "SYS.DBMS_SCHEDULER", Zeile 441
ORA-06512: in Zeile 2
--> Sorry for this, I'm using german localized oracle.
Unfortunately, it seems that only Shell-Scripts can be scheduled when using job_type='EXECUTABLE'. Can you confirm this?
BTW: The script is chmoded to 777, therefore it can't be a permission problem.
Is there maybe another solution with one single script using dbms_output functionality and run the script in a loop?
To complete my post, here are the commands used to create and test the job:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'compile_invalid_objects',
job_type => 'EXECUTABLE',
job_action => '/tmp/compile_invalid_objects.sql',
start_date => trunc(sysdate)+1+7/24,
repeat_interval => 'trunc(sysdate)+1+7/24',
enabled => TRUE,
comments => 'SQL-Script, und invalid objects zu finden und kompilieren'
END;
Thanks for your help
CasiYou could more simply use $ORACLE_HOME/dbms/admin/utlrp.sql
-
File Ownership while executing sql script from stored procedure
We have a test_command.sql script which is spooling the result into a file. From database we have one Store Procedure(run_sql) which is
calling and executing the .sql script.
When we are calling the sql script directly from the database, i e SQL > @/dccops/test_command.sql it is creating the
file under the Ownership of OS user which is connected to the system.
The problem we are facing is when we are executing the stored procedure i e exec run_sql(), the file is creating under
Oracle User.
Could u please suggest me a solution inorder to create the output file under the user who is logged to the OS.First of all, your usage of IM speak is NOT appreciated. Please do not address anyone as if they were a 12-year old.
'Our Applcation is in C. So we have to call the procedure to run the sql script.'
This is just utter nonsense!
Oracle has Pro*C which allows Embedded SQL in C. There is also OCI (Oracle Call Interface) to call Oracle directly in C, and there is OCCI, to do the same in C++.
Apart from that, Oracle has Ole DB for Windows platforms, to allow for a .NET compatible interface to Oracle.
There is NO NEED AT ALL to call PL/SQL to run a SQL script.
Sybrand Bakker
Senior Oracle DBA -
Executing sql script from file, with multiple queries
Hello,
I am trying to load an SQL script from a file, parse the script into separate SQL statements, and execute each of them. The final statement will always be a query, and thus will return a result.
Three problems arise:
1. I don't know what TYPE of statement each one is (i.e. whether it is an UPDATE or a QUERY), which seems to be required in order to execute it in java (via executeQuery and executeUpdate).
2. I am not sure of the best way to execute a series of statements (the Statement object has some "batch" functionality, but I'm not sure if there is a better way, or even of the proper way to use this).
3. I need to be able to make sure the final statement is a QUERY, and thus will return a ResultSet. Otherwise I need to be able to throw an exception.
This has been causing me a lot of trouble. Any help would be much appreciated.
Thanks,
KevinHi Kevin,
Have you got any solution for your mentioned problem????
I am facing almost the same kind of problem like I have some sql files containg simple sql statements as well as code for writting Procs , triggeres, index...functions..and so on. I need to execute this XYZ.sql file from Java side.
Can you guide me about my problem?????
Thanks in advance.............
Mak -
BPA_DEMO - Problem With SQL Scripts
Hi,
In order to understand BPA functionality i have downloaded
1.oracle_BPA_SUite_10.1.3.4_download.zip
2.oracle BPA Suite 10.1.3.4 Sample
I am trying to setup the BPA Suite and execute the Case Study in the sample -oracle BPA Suite 10.1.3.4 Sample.
But the sql scripts requuired does not have create table scripts. the SQl scripta are placed in oracle_BPA_SUite_10.1.3.4_download.zip\samples\sql. The Scripts are:
1.createSchema.sql
2.populateSchemaTables.sql
These scripts have the code for creating users and datas to be inserted in the tables but they donot have the code for creating these tables.
If anyone has got the code to create those tables then please post.There's a specific [SQL Developer Forum|http://forums.oracle.com/forums/forum.jspa?forumID=260] where they're probably more knowledgeable of that tool, or readily available to give you an adequade response, if you don't mind reposting there.
-
Execute sql script in oracle server
hi how can i run an SQL script in oracle server in every first day of the month? i dont want to run that script manually every first day of the month.
What OS and version are you running?
You can schedule this from the OS side as well if you don't want to use the scheduler.
In linux you can make use of the crontab:
crontab -e
#then paste the following lines with the path to your scripts
#.---------------- minute (0 - 59)
#| .------------- hour (0 - 23)
#| | .---------- day of month (1 - 31)
#| | | .------- month (1 - 12) OR jan,feb,mar,apr ...
#| | | | .----- day of week (0 - 7) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
#| | | | |
#* * * * * command to be executed
00 01 1 * * /<path to your scripts>/script_name.shThe above script will run on the 1st day of every month at 01h00.
your script (the one you are calling in the cron) will have to call the sql script and should look similar to this:
#export all your environment variables here
# for example
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/<your path>
export ORACLE_SID=ORCL
export PATH=$ORACLE_HOME/bin:$PATH
sqlplus user/password@DB @/path/your_sql_script.sqlHope this helps -
How to create Batch file to execute sql scripts
Hi friends,
i want to create batch file to execute all my .sql scripts.
I have all table ( all table scripts in single file ) ,Udds ( all udds in single file ) ,Stored procedures( separate file for each SPs ),Functions ( Separate file for each Functions ),Triggers and views scripts in .SQL file.
can anybody tell me how to create batch file for executing all these scripts in sql server ?.
while executing, it should ask Database name,server name, password. if these details are given then it should execute my all scripts in given database
, if any error thrown then that error and procedure name alone have to move to separate log file..
Please help me if this possible or any other easy way to do this..
Thanks - RaviHi Mate.
can i save the below details in my batch file parmantly, so that i don't need to provide the details agains again in CMD while i execute this. Please help
set /p SName=Server Name :
set /p UName=User Name :
set /p Pwd=Password :
set /p DbName=Database Name
If i am providing the details before execution of this bat file it will throw error. -
Problem executing Unix script from Java...
Hi there, I'm having trouble executing a unix script from a java program. The script receives multiple parameters and it seems that one of them ( or more ) is not well interpreted. When I run the script directly from a shell, the script executes without any errors. But, when I run the exact same script with the exact same parameters, it does not work.
Here is the command to execute the script with all the parameters that is executed from the shell ( with success ) and also from the java program ( with errors ):
/z/opus/dcap/intfu001.csh 'NODEBUG^NOTKPROF^NOSTACK' opus dcap JACQUES JACQUES '2625781' 'ORA$PIPE$001D00D70001' JOB^DEBUG^SINISIMU^STATPROD^DECTIDANC^81^503^4080^86^87^151^97^98^99 BUT^N^N^SPRI^0^13^24^3^J^05^N^19^19^19 >> /tmp/switcher8.999.null.pgm.test
And here is my portion of code that executes the script:
Runtime wShell = Runtime.getRuntime();
Process wProc = wShell.exec(cmd_unix_final);
wProc.waitFor();
return wProc.exitValue();
Please give me your thoughts on this!
Thanks in advance!Ok.
Let's proceed surgically, else we'll never solve or overcome anything.
In the last your reply you wrote:
the normal output is what I get when the script runs successfully, the script first prints a few things
and then does stuff that takes at least 2 or 3 secondsWhat do you mean?
-Finally have you got your script correctly executed?
The stuffs you spoke of are really performed?
If this is the case I can't see the prob.
Is your concern only about exitValue() for it doesn't let you distinguish programmatically
the success or failure of the script execution?
Of course you surely already have a routine in your java code to handle
exceptional situations of errors from the script.
And the "normal output" is just what you must parse to detect those errors.
Then who cares about exitValue() in this case?
Don't invoke it, relay on the stdout and stderr of the script.
-Or you get only a deceiving standard output
that let you think the script execution went alright, while instead it didn't.
In this case we have to investigate some other thing.
I can't still exclude that the problem isn't related with the buffer size of the stdout
allocated by the environment to the subprocess. You spoke of few things printed out.
Be explicit. What's the size of the output you get?
And is the "normal output" complete till the very last char
or is it truncated from somewhere on?
Also it's important that you hit a ps command after the java main process terminates
(or simply when waitFor() returns) and see if the script subprocess hung up.
As an alternative approach directly call your pro*C code from Java through JNI, instead of translating it.
1. Exec.java
public class Exec{
static{
System.loadLibrary("Exec");
public static native void proCFunct();
public static void main( String[] args){
proCFunct();
}2. javac Exec.java
3. javah Exec
4.Exec.c
#include "Exec.h"
JNIEXPORT void JNICALL Java_Exec_proCFunct(JNIEnv * a, jclass b){
//here call the function that executes the script
5. cc -G -I$JAVA_HOME/include -I$JAVA_HOME/include/solaris -I$YOUR_INCLUDES Exec.c -o libExec.so
6. setenv LD_LIBRARY_PATH .
7. java Exec -
How to execute SQL scripts in batch
Hi,
I have separate scripts for Creation of Tables, Stored Procedures, Views, Triggers in different .sql files.
I have to execute thses scripts in batch in different servers and different databases without opening SSMS.
All .sql files to be executed in single command.
Please suggest how to achieve?
Appreciate your help.
Regards,
Balayou can use sqlcmd
https://msdn.microsoft.com/en-us/library/ms162773.aspx
other options are osql,isql
https://technet.microsoft.com/en-us/library/aa214012%28v=sql.80%29.aspx
https://technet.microsoft.com/en-us/library/aa214007%28v=sql.80%29.aspx
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Execute .sql scripts from a remote login
Hello,
1) How do I execute a remote sql script from sqlplus?
SQL>@remote_server:$HOME/test_sql.sql ...this did not work, which would work?
2) Another question, in sqlplus I can do...! echo testing123>$HOME/test123.txt.
How do I do this within a store procedure?
This does not work, which would work?
declare
v_test varchar2(300) := '! echo testing123>$HOME/test123.txt';
begin
execute immediate v_test;
end;
/Re Q2.
I take it that's an sqlplus feature on unix as it doesn't work on windows:
SQL> ! echo testing123>$HOME/test123.txt
SP2-0734: unknown command beginning "! echo tes..." - rest of line ignored.
SQL>Also the reason this isn't working from within PL/SQL is that the execute immediate statement is used to send SQL statements to the SQL engine. What you are attempting to do is to send sqlplus commands to the SQL engine which obviously knows nothing about sqlplus commands. Those commands are very specific to the sqlplus executable and will only work in that environment.
;) -
Has anyone has this problem:
1) I log onto my database (Oracle XE 10.2.0).
2) I open a SQL Script that I previously created and saved. The script is about 1700 bytes.
3) I edit the script. I run the script. I click "Edit Script" button on results screen.
4) Everything is fine.
5) I repeat these steps (1-4) 10 or 20 times and then all of a sudden all edits to my script stop saving.
A) When I run the script without explicitly saving the script, it runs the unedited version of the script.
B) When I explicitly save the script, the edits do not save.
C) If I log off the database and back on again, the effects are the same (beginning here with "5)" from the get-go).
D) I I log off the database, shut down IE 7.0, reboot IE, log back on to the database I begin here at "5)" again.
E) I mark all my script and copy it to clipboard. I replace script with 3 bytes: "aaa". I click "Save". The three bytes save.
F) I replace the 3 bytes with my original 1700 bytes of code. The 1700 bytes do not save; only the three bytes remain.
6) In summary, I would ask, "Is there a size limit to the amount of SQL script you can save using this application?". However, the problem with this question is that everything worked fine for me for one and one-half hours of using the app.
I will go now to reboot my machine to see if that resolves it.
I will report back here with the results of that experiment.
Anybody has any insight, I would be grateful 'cause this is frustrating!!
Thank you,
Mike Kemp
St. Petersburg, FLOK problem started right off the bat today.
But then again the computer had been up and running overnight, multiple users during that time, etc.
So I rebooted.
Script is up to 2120 bytes now.
Problem was not resoved by reboot.
No matter what I do I can't edit my script and have it save (I edit it, copy and paste to Notepad and move back and forth as needed ... however problem is that when I click "Run" it never recognizes the new script; it always runs the old one).
Let me take my 2120-byte script and paste it into a brand-new Script Editor window and see if it will run from there (thinking that maybe this Apex thing just can't run long scripts at all)....
OK that works!!
Hmmmm...so looks to me like Apex Script Editor can't edit long scripts (I started running into problems when my script exceeded 1700 bytes).
I'll keep posting back here in case somebody big in Oracle Apex World (I just heard Tom Kyte talking about the guy who created Apex ... can't remember his name now) cares.
I know, I know they'll probably tell me it's user error :-)
-Mike
Maybe you are looking for
-
Number that is a multiple of 9 and all digits are even?
I've writen this short program to find a number that is a multiple of 9 yet all its digits are even. Here is the code. I'm sure its not very compact and am doing this the hard way. public class alldigitseven public static void main(String[] args)
-
Reader version: 11.0.06 Acrobat version: 11.0.10 Illustrator Version 18.1.1 Attached is sample PDF file. Previous versions of the software, and current versions without any updates, open this file just fine. Shared Files - Acrobat.com link to scree
-
A trust between wls domains disables weblogic account
Hi, I have a foreign jndi provider between two wls servers , the first is 10.3 and the second which has a foreign jndi provider to the first is 10.3.1 I enabled Cross Domain Security Enabled and put the same password weblogic on these domains In 10.3
-
Make list of hidden columns scrollable?
I have a large and somewhat complex form being used for a summer camp registration. I would like to be able to hide a large number of columns and only make visible the ones for certain columns (or camps). I am able to hide as many columns as I want
-
Security issue , Attn: John Stegman and Frank
Hello Frank/John: I am in the process of experimenting with Frank's suggestion http://www.oracle.com/technology/products/jdev/howtos/1013/oc4jjaas/oc4j_jaas_login_module.htm I already have a schema in my local Oracle Express for testing ADFBC Demo an