Verify if a file is SQL or verify its syntax - oracle

I'm implementing DevOps with Oracle and Jenkins, I use a Gitlab repository for scripts .sql (PL/SQL and ORDS), I want to verify if a file is uploaded and trigger pipeline is indeed a SQL file and verify its syntax to avoid execute all pipeline if it is a wrong file. Exists some Oracle command or script that do this? (I find EXPLAIN PLAN FOR but it doesn't work with PL/SQL blocks and ORDS)
Thank you

script
var input = 'select * from emp';
var ParsedSql = Java.type('oracle.dbtools.parser.plsql.ParsedSql');
var parsed = new ParsedSql(input);
var root = parsed.parse();
root.printTree();
/
The other useful ParsedSql methods:
getInput()
getSrc()
getRoot()
getSyntaxError()

Related

Adobe Illustrator: Run python file from Extendscript in Windows

I am facing issue while running this script(time.jsx):
var timeStr = system.callSystem("cmd.exe /c \"time /t\"");
alert("Current time is " + timeStr); Documentation of AE
it works in Adobe After Effects but I want to use it specifically in illustrator. Basically, i want to run my Python script from Extendscript(.jsx). But I couldn't find any solution to do so yet.
Your help is appreciated.
Thanks in Advance.
i have found a way to execute Python or other scripts in Extendscripts(*.jsx), and that is it, there is named File object in documentation which has a function named execute(); which executes the scripts according to their statement. For example, you want to execute hello world in python through .jsx file, you need to make a py file including print("hello world"). After that, add these lines in the script.jsx script:
var pyHello = new File("<path of py file>");
var bool = pyHello.execute();
alert(bool);
If script executed, it would be true, otherwise, false,

Oracle command works in database but not in SQLPlus

I'm currently trying to implement a bash script that runs at the end of the day that runs a simple oracle query. The command works just fine in Oracle but when inside a .sql file it does not run.
I've attempted to put all of the code on one line and adding semicolons.
Contents of batch file (with user/pass altered):
sqlplus username/password#database #set_changed.sql
Contents of set_changed.sql file:
UPDATE ris_web a
SET a.changed = 0
where exists
(
select modified_date from invn_sbs b
where b.item_sid = a.item_sid
and b.modified_date <= sysdate-1
);
COMMIT;
END;
In SQLPlus you should use a / on a separate line to terminate an SQL statement or PL/SQL block instead of using a semicolon, so change your file to
UPDATE ris_web a
SET a.changed = 0
where exists
(
select modified_date from invn_sbs b
where b.item_sid = a.item_sid
and b.modified_date <= sysdate-1
)
/
SHOW ERRORS
/
COMMIT
/
SHOW ERRORS
/
END
You might also want to have a look at this question
You have end; command at the end of the script but no BEGIN for it.
Simply replace the END; with /
The original syntax was correct. There were uncommitted changes in sqldeveloper that were causing the .sql file to never finish running. Thank you everyone for your help.

Book rating predication using lenskit

I read this website : http://lenskit.org/documentation/evaluator/quickstart/ I first tried to run it using the script " $ lenskit eval " and I just created a new groovy file in my hello-lenskit example and run it using the command line but nothing happened. Then I tried to use it in Java program(hello-lenskit.java).
I run into some errors.
File dataFile = new File("ml-100k/u.data");
PreferenceDomain domain = new PreferenceDomain(1.0,5.0,1.0);
DataSource data = new CSVDataSource("ml-100k",dataFile,"\t",domain);//give me an error CSVDataSource is not public and can not be accessed from the outside package.
CrossfoldTask cross = new CrossfoldTask();
LenskitConfiguration config1 = new LenskitConfiguration();
config1.bind(ItemScorer.class)
.to(UserMeanItemScorer.class);
AlgorithmInstance alg1 = new AlgorithmInstance("PersMean",config1);
evl.addAlgorithm(alg1);
LenskitConfiguration config2 = new LenskitConfiguration();
config2.bind(ItemScorer.class)
.to(ItemItemScorer.class);
config2.bind(UserVectorNormalizer.class)
.to(BaselineSubtractingUserVectorNormalizer.class);
config2.within(UserVectorNormalizer.class)
.bind(BaselineScorer.class,ItemScorer.class)
.to(ItemMeanRatingItemScorer.class);
AlgorithmInstance alg2 = new AlgorithmInstance("ItemItem",config2);
evl.addAlgorithm(alg2);
evl.addMetric(RMSEPredictMetric.class);
File file = new File("eval-results.csv");
evl.setOutput(file);
What should I do next? How could I generate the overall rating error?
Using the LensKit evaluation commands manually is difficult, undocumented, and not recommended.
The SimpleEvaluator is the best way to get overall accuracy from a LensKit recommender in a Java application.
For further assistance in debugging LensKit runs, I recommend e-mailing the mailing list with exactly the commands you are running and the output or errors you are getting.

bulk compiling pl/sql procedures

i have lots of packages which needed to be compiled when i move from development to production or when we release a change request.
right now , we compile each of the packages one by one using toad or sqldbx , is there a way that i can write a batch file with sqlplus command so that i can run all my packages in one go.. like *.sql
You can execute dbms_utility.compile_schema(user,false); to compile all invalid objects in your schema at once.
You can read about that procedure here in the documentation: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/d_util.htm#ARPLS73226
Regards,
Rob.
Normally when we do lots of changes in a database that invalidates lots of objects, the easiest way to get them recompiled is by running sqlplus "/ as sysdba" #?/rdbms/admin/utlrp This procedure gets smarter every release and from 10g it uses the Oracle Scheduler to work in parallel. This of course only works with dba access to the database. If you lack that Rob van Wijk's answer is the way to go.
You can put all the SQLs in a text file and execute that by:
SQL > #/path/script.sql
You just need to provide path of script to be executed.
My approach would be to copy all package scripts into a directory then create a single sql script in that directory to load all packages, see example below.
-- load package specifications
##package1.pks
##package2.pks
-- load package bodies
##package1.pkb
##package2.pkb
One way of tackling this is to deploy your code in the correct order.
PL/SQL packages themselves are the API for the code in the package body, and the packages themselves are not dependent on each other. Package bodies however can be dependent on packages, so if a package is recompiled than it runs the risk of invalidating package bodies that reference it.
Unfortunately it's very common to see deployments that work in this order:
create or replace Package A ...;
create or replace Package Body A ...;
create or replace Package B ...;
create or replace Package Body B ...;
create or replace Package C ...;
create or replace Package Body C ...;
This has the side-effect that if code in Package Body A is dependent on Package B, then when Package B is (re)created it invalidates Package Body A.
The correct sequence for deployment is:
create or replace Package A ...;
create or replace Package B ...;
create or replace Package C ...;
create or replace Package Body A ...;
create or replace Package Body B ...;
create or replace Package Body C ...;
If there have not been changes in the package itself then there is no need to deploy it at all, of course.
Respecting these methods should give you much fewer invalid objects.
Package Headers first:
for i in $(ls *.hed); do sqlplus user/password #$i; done
Then package bodies:
for i in $(ls *.hed); do sqlplus user/password #$i; done
you can use dba_objects to check for invalid objects and use dynamic sql to generate compile statements, something like:
select 'alter ' || object_type || ' ' || owner || '.' || object_name || ' compile;'
from dba_objects
where status = 'INVALID'
and object_type in ('PACKAGE', 'PROCEDURE', 'FUNCTION');
you can then put that into a sql script.
You can also look into utl_recomp package

Update a package from SQLPLUS

I'm trying to update a package in Oracle, coming from SQL Server this has been confusing.
I have written a batch file that runs the .spec file first and the .body file second, but even running it manually does not work.
I use this syntax:
sqlplus username/password#databasename #c:\temp\myfile.spec
sqlplus username/password#databasename #c:\temp\myfile.body
When I go back to Sql Developer I can look at the stored procedures in the package and see that they have not been updated.
Why aren't my packages getting updated?
The spec and body files need to have / make SQL*Plus create/replace the object.
Without the /:
CREATE OR REPLACE PACKAGE TEST12_13 AS
PROCEDURE TEST12_13;
END;
STAGE#DB>#C:\TEST.PKS
6
With the /:
CREATE OR REPLACE PACKAGE TEST12_13 AS
PROCEDURE TEST12_13;
END;
/
STAGE#DB>#C:\TEST.PKS
Package created.
In reply to your comment about passing filename as parameter, instead of passing the filename as parameter, have SQL*Plus ask you for the filename
wrapper.sql
ACCEPT filename_var Prompt 'Enter filename'
#c:\temp\&filename_var
/
#c:\temp\&filename_var
/
Connect to SQL*Plus with
sqlplus username/password#databasename
Then run the script from the SQL*Plus prompt:
set echo on
#c:\temp\myfile.spec
You should be able to see whats going on like this, including any error messages.

Resources