Execute PL/SQL from BC4J
Hi All,
Can anyone point me to documentation that tells how to execute PL/SQL from BC4J.
Thanks a lot
Srinivas Bhat
Try something like this:
try
final ApplicationModule am = panelBinding.getApplicationModule();
final CallableStatement stmt = ((DBTransaction) am.getTransaction()).
createCallableStatement ("{? = call yourpackage.yourfunction(?)}", 10);
stmt.registerOutputParamter(1, oracle.jdbc.driver.OracleTypes.INTEGER);
if (id == null)
stmt.setNull (2, oracle.jdbc.driver.OracleTypes.NUMBER);
else
stmt.setInt (2, id.intValue());
stmt.execute();
stmt.close();
return stmt.getInt(1);
Similar Messages
-
Execute PL/SQL From MS SQL SERVER PL
Hi.
I Need execute a Oracle PL/SQL from a SQLSERVER 2000 PL, i make a database link from sqlserver and i can see the tables to oracle, but i can't execute a pl/sql.
The PL/SQL i want execute return a ref cursor.
Thak's for your helpDo you have a final / in your script to execute it (which is presumably an anon pl/sql block).
-
How to execute PL/SQL from DOS PROMPT?
Hello:
I've seen that executing an SQl script via DOS prompt involves @script name, however all this seems to do is open the line editor. A GET command displays my script and sets the cursor on the next available line with the last line of the script with an asterics beside it. as does using the @scriptname command. I cannot do any commands like SAVE, RUN, etc.
Any help is appreciated.Do you have a final / in your script to execute it (which is presumably an anon pl/sql block).
-
How to execute PL/SQL from Java?
I want to execute (compile) a PL/SQL file to a database and I don't know how it can be done with Java.
Please note that I am NOT trying to call a stored procedure. I know that can be done with CallableStatement.
Background:
My actual requirement is to execute PL/SQL files with error notifications. I tried Ant SQL task; but it fails to give compilation error information. I also tried another open source task called Incanto - that also not that helpful as if I execute in bulk, very hard to figureout which one throws error. Hence I decided to write my own Ant task.Hi,
do u want to execute PL/SQL files? or just you want to execute the block of code?
in the case of PL/SQL file:
you need to read total file as StringBuffer/String and then execute.
Block of code:
you can directly pass the code to the java file as input and then execute.
Ex:
StringBuffer queryString = new StringBuffer();
queryString = queryString.append("BEGIN execute immediate ' ");
queryString = queryString.append(query);
//queryString = queryString.append("BEGIN dbms_job.run(142);END;");
queryString = queryString.append(" '; END; ");
final_Query = queryString.toString();
try {
System.out.println("final : "+final_Query);
cstmt = con.prepareCall(final_Query);
System.out.println("Job is Running...");
new ThreadCountdownExtThread().start();
System.out.println("bfore execute()...............");
cstmt.execute();Note: if you are running pl/sql file read file and save it in a Stirng , and then do the same as above stated -
Executing PL/SQL from a varchar2 variable
so i've got an instruction ie:
test in varchar2;
test <= TO_DATE('2009-08-27', 'YYYY-MM-DD') ;
how to execute "test" from inside a stored function/procedure?
thanks i'm kind of noob, any help would be appreciated :)¿Not sure here whether you've edited your original question, as Toon uses := instead of <=?
Anyway:
so i've got an instruction ie:
test in varchar2;
test <= TO_DATE('2009-08-27', 'YYYY-MM-DD') ;
how to execute "test" from inside a stored function/procedure?
thanks i'm kind of noob, any help would be appreciated :)So, I'm assuming your 'instruction' in human language would be something like:
"Check if your in-parameter is older or equal to the current present day (a.k.a. SYSDATE)"
But, WHY you need a stored function/procedure you do not mention.
So, please read this to begin with, to get the most and maximum out of your questions:
http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
And if my assumption is right, you could do something like:
MHO%xe> create or replace function date_in_future
2 (p_date_str in varchar2)
3 return varchar2
4 as
5 rtn varchar2(1);
6 begin
7 case when to_date(p_date_str, 'yyyy-mm-dd') > trunc(sysdate)
8 then rtn := 'Y';
9 else rtn := 'N';
10 end case;
11 --
12 return rtn;
13 --
14 end date_in_future;
15 /
Functie is aangemaakt.
Verstreken: 00:00:00.25
MHO%xe> select date_in_future('2008-02-12') from dual;
DATE_IN_FUTURE('2008-02-12')
N
Verstreken: 00:00:00.07
MHO%xe> select date_in_future('2020-02-12') from dual;
DATE_IN_FUTURE('2020-02-12')
YBut perhaps a BOOLEAN return or whatever would suit your requirement better.
But then you'd need to provide a more complete and concisive case/requirement/question.
Please remember these sites as well in any way, besides OTN, they contain tons of useful stuff (that's an understatement ;) ):
http://tahiti.oracle.com
http://asktom.oracle.com -
How execute pl/sql command from Oracle ADF Business Components
can't find examples for how execute pl/sql command from Oracle ADF Business Components and how call pl/sql package procedure from ADF Business Components.
insert,update,delete rows in view object instance cache is good but if i must do some complex operations while insert,update,delete rows..it's more better for me to call
pl/sql procedure from oracle db.Am i wrong ????Roman,
this should be similar to how it worked in JDeveloper 9.0.3. hava a look at <JDev903 Home>\BC4J\samples\StoredProc for a code example.
Frank -
Error when execute a package from SQL Server Agent
We have the next problem:
When we execute a package from a Job of SQL Server agent, it shows the success messege, but reviewing the results, the package didnt do all the tasks.
When we run it mannually by MSIS the package, it shows the success message and it works fine.
The workflow of the package is :
1) Shrink the databases (executing a sql file)
2) Backup the databases (Back up Database task of MSIS)
3) Rename the files to .BAK extension (by the Foreach loop container and fyle system task)
4) Execute command to compress the it (by a .bat)
5) Move the compress file to another location (by another Foreach loop)
Manually run correct, but when is a a SQL AGent Job that execute the package it does only the first 2 steps.
we are ussing Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) Jun 17 2011 00:54:03 Copyright (coffee) Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
We are using a user with administrator privilegies
CheersCan you check if account running package has proper access. You may need to define a proxy account for that.
See
http://www.databasejournal.com/features/mssql/article.php/3789881/Proxy-Accounts-in-SQL-Server.htm
http://gqbi.wordpress.com/2014/01/30/setting-up-a-proxy-account-to-run-sql-server-integration-services-ssis-2012-packages/
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Solution to execute sql from mysql application logs
We have some custom mysql application, which generate logs that are stored on common location on open linux box which has below format
$ cat minor20100809.log
20100809001^Aselect count(prod_id) from product_logs;
20100809002^Aselect count(order_id) from order_logs;
ID and the SQL statement with control A as seperater and daily 1000 logs files are generated
Now we have one oracle DWH, where we import all the mysql data and we need to test these counts on daily basis.
Could you please suggest a solution in oracle for this?
at high level we need to follow below steps
a) Import these logs in a table --> which is better way sqlldr, impdp, or plsql read file ?
b) execute these sql statement one by one
c) store the counts in log table on daily basisHi,
It is a simple two step process.
Step 1. Convert your log files statements to meaningful oracle statements. like removing prefixes 20100809001^A from each line.
This can be done in two ways.
(a). Using OS editors OR
(b). Following PL/SQL code...
-- Connect as sysdba
create or replace directory dir_tmp as '/tmp'; -- If oracle server is on Unix
create or replace directory dir_tmp as 'C:\your_folder'; -- If oracle server is on Windows
-- Grant permission to your_schema
grant read, write on directory dir_tmp to your_schema; Removing prefixes using:
SELECT regexp_replace (vNewLine, '([[:alnum:]]{1,})\^A', '\2')
INTO vStmt
FROM DUAL;
CREATE OR REPLACE PROCEDURE convert_to_sql_stmts
( input_file in varchar2,
output_file in varchar2
AUTHID CURRENT_USER
IS
InFile utl_file.file_type;
OutFile utl_file.file_type;
vNewLine VARCHAR2(4000);
vStmt VARCHAR2(4000);
i PLS_INTEGER;
j PLS_INTEGER := 0;
SeekFlag BOOLEAN := TRUE;
BEGIN
-- open a file to read
InFile := utl_file.fopen(dir_tmp, input_file,'r');
-- open a file to write
OutFile := utl_file.fopen(dir_tmp, output_file, 'w');
-- if the file to read was successfully opened
IF utl_file.is_open(InFile) THEN
-- loop through each line in the file
LOOP
BEGIN
utl_file.get_line(InFile, vNewLine);
i := utl_file.fgetpos(InFile);
dbms_output.put_line(TO_CHAR(i));
SELECT regexp_replace (vNewLine, '([[:alnum:]]{1,})\^A', '\2')
INTO vStmt
FROM DUAL;
utl_file.put_line(OutFile, vStmt, FALSE);
utl_file.fflush(OutFile);
IF SeekFlag = TRUE THEN
utl_file.fseek(InFile, NULL, -30);
SeekFlag := FALSE;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
COMMIT;
END IF;
utl_file.fclose(InFile);
utl_file.fclose(OutFile);
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20099, 'Unknown UTL_FILE Error');
END convert_to_sql_stmts;
Step 2. Directly executing above output log file
Use spool to generate the count....
set termout off
set feedback off
set trimspool on
set pagesize 0
set timing OFF
spool count.log
@new_file.log
spool off;Hope this helps... -
How to execute a .sql file from a batch file
Hi all
I've to take backup of a database weekly twice on every wednesday & Friday @ 5pm IST. I've written a hot backup script, which works every well.
now i want to automate the script. ie i want this script to run on wednesday & friday @ 5pm without any human interfearance ie with out actually any1 executing this script.
i created a batch file prod.bak with the following lines
@echo off
set oracle_sid=testdb
set oracle_home=d:\oracle\ora92
sqlplus /nolog
connect sys as sysdba/oracletest@testdb
this batch file when eexecuted connects me to sql prompt.
Now i want to execute my backup script bkp.sql automatically when it is connected to sql prompt.
(i tried with these lines in the above batch file...
call bkp.sql---it just opens the bkp.sql file in notepad & displays the script
start bkp.sql---same as call
connect / as sysdba/pwd@[email protected] --- does not work simply remains a the sql prompt.
At 17:00 /Every:w,f "d:\bkp.sql"---does not work simply remains at the sql promt.)
Can any1 let me know what should i write in the batch file that will execute the bkp.sql file automatically after it gets connected to sql prompt. M using oracle 9i.
I'll manage he time through windows utility of scheduling task.. Let me know how to execute the .sql file from a batch file.
Thanks
TriptiTry
sqlplus "sys/oracletest as sysdba" @bpk.sql
Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
Remember to put an exit at the end of the bpk.sql script. -
It is possible to execute a SQL query from OMBPlus?
We have some simple SQL scripts we'd like to be able to incorporate into our existing TCL scripts, instead of having to run them outside of OMBPlus in sqlplus. Is is possible to run a SQL SELECT query from OMBPlus and/or TCL? And get a result set back to iterate through?
Thanks,
Jim C.You can execute SQLPlus from OMB or just get down and use JDBC to execute the SQL, see others posts on forum such as below;
How to run SQL from OMB+
Cheers
David -
Strange problem with executing PL/SQL procedure from sqlplus.
Hello,
basicly, I'm strugling with executing a procedure written in PL/SQL from sqlplus.
It's all because I convert a data in procedure by other function.
SELECT partition_name
INTO strpartition
FROM user_tab_partitions
WHERE table_name = tablename_in
and substr(partition_name, -8, length(partition_name)) = (SELECT F_CONVERT_DATE(tablename_in,p_date) from dual);
/tablename_in and p_date are input parameters/
Function F_CONVERT_DATE looks more less like :
select
TO_CHAR(TRUNC(NEXT_DAY(ADD_MONTHS(substr(partition_name, -8, length(partition_name)), -3), 'MONDAY')-7), 'YYYYMMDD')
END
AS p_date
INTO v_okr
FROM user_tab_partitions
where substr(partition_name, -8, length(partition_name)) = p_date;
Well, the thing is that procedure is executable from TOAD without any errors !! But when I try to execute it straight from sqlplus it returns:
ORA-01861: literal does not match format string
ORA-06512: at "F_CONVERT_DATE", line 13
ORA-06512: at "NAME_OF_PROCEDURE", line 17
Tip: When I don't use functions ADD_MONTHS, NEXT_DAY and TO_CHAR in function F_CONVERT_DATE sqlplus can execute it. But only when I use them it returns an error.
Anybody has a clue how to solve it?
Regards !Hi, Nodex,
Avoid implicit conversions.
For example:
TO_CHAR(TRUNC(NEXT_DAY(ADD_MONTHS(substr(partition_name, -8, length(partition_name)), -3), 'MONDAY')-7), 'YYYYMMDD')ADD_MONTHS expects a DATE as its first argument.
SUBSTR returns a VARCHAR2, so you're calling ADD_MONTHS with a VARCHAR2 where it expects a DATE.
For good or ill, the system tries to avoid raising an error in this case by implicitly converting the VARCHAR2 to a DATE. Exactly how it does that depends on
(a) the tool you are using (SQL*Plus or Toad, for example),
(b) the version (Oracle 10 behaved quite different form Oracle 9),
(c) environmental settings (such as NLS_DATE_FORMAT), which in turn may depend on initialization parameneters, and
(d) who knows what else.
When you have to convert, do so explicitly.
You can convert a VARCHAR2 to a DATE using TO_DATE, like this:
TO_CHAR ( TRUNC ( NEXT_DAY ( ADD_MONTHS ( TO_DATE ( SUBSTR ( partition_name
, -8
, LENGTH (partition_name)
, 'YYYYMMDD' -- or whatever
, -3
, 'MONDAY'
- 7
, 'YYYYMMDD'
) -
Help! Executing SQL from ASP
This is my Code..
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.DbOpenDatabase(strDB, strID & "/" &
strPASS, 0)
OraDatabase.DbExecuteSQL("DELETE tmp_clean;")
It then runs a SQL statement which populates the table
tmp_clean. I don't really want to have to write a procedure to
do this. It seems not to like the semi colon, but with out it
it doesn't execute the SQL. Please Help.It's okay, I worked it out. I hadn't done a COMMIT from my SQL
Plus session, so the table was still empty, and it musn't like
that. -
Execute an SQL Script from Java (myScript.sql) ?
Hello!
I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
I'm connecting to mySQL server using JDBC which works fine, but I was wondering
how can I run an entire script file, say myScript.sql from within a Java class??
(an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
example of an SQL Scritp: myScript.sql>>
//#create new db
CREATE DATABASE sample_db;
//#set active db
USE sample_db;
//#set table paramaters
CREATE TABLE monkeys
(name CHAR(20),
age INT UNSIGNED,
sex ENUM('M','F')
//#create standard monkeys
INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
//#get recordset
SELECT * FROM monkeys WHERE age < 50;Thanks for your help!The way I understand it is that your mysql.sql script file uses ';' as a delimeter between statements. So now what you can do is that read the whole file and put it inside a string/stringbuffer. Now put this string/stringbuffer to a stringTokenizer with delimeter set as ';'. this way you will recieve your exact statements without scratching your heads as where the statements begin/ends. :-)
Now once you have your statements than its just a matter of executing them against the database.
hope this helps. -
Patterns to execute a SQL Statement from a Droplet (select)
Hi,
I need to perform a query on a table, Example: select * from ARF_QUERY "the database used is Oracle. I would like to know if the atg has some
standard method to perform this database connection and execute the SQL statement from a Droplet (select).
Thank.I dont think there is any generic droplet to run a select query directly against a table.
However, there are various lookup droplets available that run on the repositories.
Like /atg/targeting/RepositoryLookup droplet. you can run it for specific id or for all.
You might want to have a look at it in documentation of how exactly to use it.
Thanks -
Need help, executing a SQL file from Forms
Hi everyone,
I don't know if this can be done. I want to execute a SQL file from a When-Button-Pressed trigger. I checked a couple of place but havent found anything yet on how to do this. If someone know of a way, please help.
Thanks
Ericprocedure p_call_sqlplus is
l_filename varchar2 (1000) := 'C:\abc\def\test.sql' ;
begin
host ('sqlplus /NOLOG @' || l_filename ) ;
end ;
rem ======== test.sql ========
connect scott/tiger
spool 'C:\abc\def\test'
select * from emp ;
spool off
exit
rem ======================working on the machine where forms is running
Maybe you are looking for
-
[BIOS Update Failure] HP ENVY TouchSmart 15-j021tx stuck at black screen on startup
Hello So I decided to update the BIOS on my laptop because it was on the recommended list of driver updates. It started off smooth at first, but then the screen turned black and just stayed like that for like an hour. Having read from other posts tha
-
The wireless radio is not functioning on the Photosmart Premium c309a all in one printer
The wireless radio is not functioning on my Photosmart Premium C309A
-
How to calculate length of the string in transformation file
Hello all I have tried a number of ways and I am not able to calculate the length of the incoming field in transformation file for my data load. Here is the issue. I have an incoming string of length 10 and I need to use it to update multiple dimensi
-
JDBC connection to two different machines from the same program
I want to use JDBC to connect to two different databases that are on two different MySQL installations on two different machines. One of the installations is MySQL 4.1.12 and the other is 4.1.14-nt For some reason, all my statements seem to be going
-
IWeb crashes whenever I try to select a new font
Anytime I try to change a font type whether it's from the menu bar or from the prompts within a template, the programs shuts down. This is the message that appears. I just copied Thread O: Process: iWeb [60041] Path: /Applications/iWeb.app/Contents/M