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 basis
Hi,
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...
Similar Messages
-
Translating SQL from MYSQL to ORACLE with more than one outer join.
I will translate the following sqlquery from MYSQL to ORACLE:
SELECT ticket.ticket_no,ticket.ticket_dato,ticket.ticket_subject,ticket.customer_id,customer_name,ticket.ticket_own_read, ticket.department_id, department.department_name, priority_name, tickstat_name, tickettype_name
FROM customer, ticket left join department
on ticket.department_id = department.department_id left join priority on ticket.priority_id = priority.priority_id
left join ticketstatus on ticket.tickstat_id = ticketstatus.tickstat_id
left join tickettype on ticket.tickettype_id = tickettype.tickettype_id
where ticket.customer_id = customer.customer_id and customer.owner_id =
#session.owner_id#
I have tried in ORACLE with:
SELECT ticket.ticket_no,ticket.ticket_dato,ticket.ticket_subject,ticket.customer_id,customer_name,ticket.ticket_own_read, ticket.department_id, department.department_name, priority_name, tickstat_name, tickettype_name
FROM customer, ticket ,department, priority, ticketstatus, tickettype
where
ticket.department_id(+) = department.department_id and
ticket.priority_id(+) = priority.priority_id and
ticket.tickstat_id(+) = ticketstatus.tickstat_id and
ticket.tickettype_id(+) = tickettype.tickettype_id and
ticket.customer_id = customer.customer_id and customer.owner_id = #session.owner_id#
I get an error:
MERANT][ODBC Oracle driver][Oracle]ORA-01417: a table may be outer joined to at most one other table
How do I translate the code to ORACLE?I think that your syntax is wrong. The (+) operator should be on the right hand table column, not the left hand table column if you want all rows on the left hand table column. If this syntax is really what you want, you can create underlying views for each join condiction.
-
Executing sql from table with in plsql procedure
I wonder if anyone can help.
I have a table that stores sql statements. They are actually a set of rules that I want to apply to my application. My intention is to execute the statement in plsql.
EG a sql statment held in the table might be:
'select count(id) from item where item_id = ' || constants_pkg.c_test_item || ' and client_id = ' || client_id_in
I am trying to call this from a plsql procedure, Ive CUT OUT some of the procedure task_rec.rule holds the statement above. The procedure is failing invalid SQL statement, I think the client_id_in may not be evaluating as the variable, passed into the procedure and constants_pkg.c_test_item not being taken from the constants pkg.
EG.
PROCEDURE create_additional_info_list(
client_id_in IN client.id%TYPE,
IS
result VARCHAR2(100);
BEGIN
EXECUTE IMMEDIATE
task_rec.rule
INTO result;
END;
If I was to do below the code would work ok. However I require the rule to come from the table.
EXECUTE IMMEDIATE
'select count(id) from item where item_id = ' || constants_pkg.c_test_item || ' and client_id = ' || client_id_in
INTO result;
Is there anyway constants_pkg.c_test_item and client_id_in can be evaluated as variables?Not that I've tried this but, if possible, change the SQL in the table to have bind variable; e.g.,
'select count(id) from item where item_id = :1 and client_id = :2 ';
Then in the procedure
execute immediate task
INTO result
USING constants_pkg.c_test_item ,
client_id_in ; -
Error in executing 'HR_INFOTYPE_OPERATION' from webdynpro application
Hi Experts,
I am using FM 'HR_INFOTYPE_OPERATION' for infotype PA0034 operations. I have written below code in assistant class.
when i execute the class method and pass the parameters this FM executing fine and creates record into pa0034. But when i execute the webdynpro application it is giving error "Invalid parameter EXCEPTION , value ". Please Help me in solving this issue
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = '0034'
NUMBER = lv_pernr
SUBTYPE = ls_p0034-subty
OBJECTID = ''
LOCKINDICATOR = ''
VALIDITYEND = ls_p0034-endda
VALIDITYBEGIN = ls_p0034-begda
RECORDNUMBER =
RECORD = ls_p0034
OPERATION = 'INS'
TCLAS = ' '
DIALOG_MODE = '0'
NOCOMMIT =
VIEW_IDENTIFIER =
SECONDARY_RECORD =
IMPORTING
RETURN = ls_return
KEY =
Thanks
VijayHi Vijay,
So you are passing the values from the screen. So you must have binded the screen fields with the attributes, just make sure that they are of the same type as the importing parameters of the FM
Regards
Arjun -
For a migration I have created a sql script that puts the full statement to be executed in a specific table column
I'm now looking for a way how to execute those statements.
Table structure like: oldName, newName, sqlStatement, id, otherField, otherField2
Instead of the full statement(sqlStatement) it would also be possible to use the oldName, newName and id field if that simplifies the problem.
The reason for building the statement and running that one is a) to validate upfront b) a self join is applied to the query result table to prevent some items for update.
The initial idea was to take the sql statements and execute them as a sql script but that process is pretty slow.user2833655 wrote:
For a migration I have created a sql script that puts the full statement to be executed in a specific table column
I'm now looking for a way how to execute those statements.That is wrong, tables are for data not executable code
Re: ref cursor - result set not known
http://en.wikipedia.org/wiki/Data_%28computing%29
>
Data is often distinguished from programs. A program is a sequence of instructions that detail a task for the computer to perform. In this sense, data is thus everything that is not program code.
>
user2833655 wrote:
The initial idea was to take the sql statements and execute them as a sql script but that process is pretty slow.This alternative will just make it difficult, complicated and unreliable as well. -
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. -
After executing sql from batch, its disconnecting
Hello All,
I have written a batch program to execute a pl/sql procedure. But after execution, it disconnects.
But i want to continue in the same session
echo exec tracer.trace_pck.start_('alter session set sql_trace=true') | sqlplus hr/hr
Output:
Press any key to Enable Tracing
SQL*Plus: Release 11.2.0.2.0 Production on Thu Oct 10 15:59:56 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
SQL>
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 -
Production
Trace Enabled Successfully. Press any key to input you sqlIf you are using a batch file I assume you are using the windows OS.
Essentially what you need to do is to call a sql file from the batch file and then get the sql file to call all the other files.
Batchfile test.bat calls sql file test.sql
sqlplus <username>/password @test.sql
test.sql calls test1.sql and test2.sql and then exits
@test1.sql;
@test2.sql;
exit;
test1.sql shows the current sid, and serial# fro our session and our filename
select 'test1',sid,serial# from v$session
where audsid=userenv('sessionid');
test2.sql shows the current sid, and serial# for our session and our filename
select 'test2',sid,serial# from v$session
where audsid=userenv('sessionid');
When you run this you get t output similar to the following: (Your SID and Serial# will be different )
'TEST SID SERIAL#
test1 771 97
'TEST SID SERIAL#
test2 771 97
This shows that two separate sql files were called but are still in the same session -
Executing SQL From A Forms Procedure
I am looking to execute a composed SQL command (ALTER USER ***** IDENTIFIED BY ****). The old execute immediate command in forms 5 would be the one I would have used, does any know the Forms 6i equivalent.
Regards
StephenHi John,
What I was having a problem with is that the following code from a Forms 5 procedure isn't working with Forms 6i :
Procedure dropSynonyms ()
sql_stmt carchar2(2000);
BEGIN
sql_stmt := 'drop synonym RT_'| |rec.runtime_table_name;
execute immediate sql_stmt;
END;
The method of executing the sql_stmt sees to have changed with Forms 6i but the help documentation isn't clear on the new syntax.
Any help appreciated.
Regards
Stephen -
How to Start Executable Files from JavaTM Applications?
If it is possible to start other executable files, for example EXE or BAT, from a Java application, how can it be done in VC++??
I can invoke executables (or whatever your OS is willing to execute) via Runtime.exec(). as per JDC member mtj or perhaps try:
import Java.lang.*;
import Java.io.*;
public class RuntimeExecTest {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
String[] callAndArgs = { "Notepad.exe",
"D:\\TEMP\\Test.txt" };
try {
Process child = rt.exec(callAndArgs);
child.waitFor();
System.out.println("Process exit code is:
" + child.exitValue());
catch(IOException e) {
System.err.println(
"IOException starting process!");
catch(InterruptedException e) {
System.err.println(
"Interrupted waiting for process!");
But in VC++ on of the method signature is causing the problem:
public Process exec( String command, String envp[] ) throws IOException
If I use the above code, I get this error:
Compiler Error J0122
Exception 'identifier' not caught or declared by 'identifier'
Please help
ThanksYes, it is possible to run both EXEs and BATs with exec().
I also suggest you to look at the following article:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
Unix OS /while executing SQL commands needs Error Log
hai ,
I am accessing the Development Server. While executing the SQL commands I need to log the errors. (like Spool in Windows )
Same way , i want to log the error on Unix Environment.
Thanks In Advance.
AnzySpool is a SQL*Plus command, just use it and you'll get your log.
-
Urg:Executing SQL From Java App using Jdbc Driver
Hi
I am using JDBC Driver version 9.0.1.1.0.
I am running this in Thin Client Mode
My Code Snippet Looks Like This:=
==========================================================
String url = "jdbc:oracle:thin:@localhost:1521:VpDb";
String userName = "scott";
String password = "tiger";
Connection conn = null ;
Statement st = null ;
ResultSet rs = null ;
String categoryCode="ABC";
try
conn = DriverManager.getConnection (url, userName, password);
st = conn.createStatement ();
String sqlStatement = "Select Count(*) From News Where CategoryCode=" +"\'" + categoryCode + "\'" + ";";
System.out.println(sqlStatement);
rs = st.executeQuery ( sqlStatement );
if( rs.next() )
System.out.println("Headline Exists");
else
System.out.println("No Headline Exists");
catch (SQLException e )
System.out.println();
System.out.println (" SQL ERROR IN IS_NEWS_EMPTY: " + e) ;
=========================================================
I have added the classes12.zip and nls_charset12.zip in the classpath.
Now when i run this it gives me an error saying the following error message:-
SQL ERROR IN IS_NEWS_EMPTY: java.sql.SQLException: ORA-00911: invalid character
Can anyone help me with this as to whats going wrong because the exact equivalent of my sqlStamenet runs on SQL command line but not from java code.Why??
Any Help appreciated
Thanks
MumI think it is complaining about the ";" that you add at the end of your string. You don't need to add that to the query.
-
Execute SQL after root application module is created
Hi friend
I override this method from Root appModule implementation
protected void afterConnect() {
super.afterConnect();
//I add this line to execute a query when appmodule get db connection
String statement = "ALTER SESSION SET CURRENT_SCHEMA='SCOTT';";
CallableStatement plsqlBlock = getDBTransaction().createCallableStatement(statement, 0);
plsqlBlock.execute();
This is right?, i want to alter schema in db session always.If it is a session specific initialization, you can try prepareSession() method as explained here.
http://adfcodebits.blogspot.in/2010/06/bit-21-overriding-preparesession-to-do.html
http://docs.oracle.com/cd/B31017_01/web.1013/b25947/bcservices006.htm -
Exporting and Importing Data of Application Log
Hello,
We do migrate an application from SAP System A to SAP System B.
Despite the application logic, we do need to migrate some data, too.
For this we do write an export report in System A that writes the data of some tables to files on the app server..
Another report in system B takes the files and fills the respecting tables.
So far so good:
One table (which reports certain actions) contains the handle to the application log, which was created for this action.
I do want to extract this application log and later import this log in the other system, but do not know how this can be done in the best way.
Do you have any suggestion ?
Best regards
MichaelIn my experience, it's an unrealistic expectation.
SAP doesn't provide a straight path to migrate logs the way you plan to do. It's kept in a combination of tables and index files on the system. So even if you were to successfully extract it, when you load the data into system B you will lose the date and time stamp. When you create a log entry, it picks up system date and time. That's what an auditor would look for.
An alternate solution would be to read the application log and store it in a new custom table in system B.
Any reporting should be done off that as of a specific date. -
Executing APEX_INSTANCE_ADMIN inside APEX Application
Hi,
I'm having trobule when I try to execute APEX_INSTANCE_ADMIN.SET_PARAMETER from an apex application.( For further information, I'm trying to implement this Re: Changing SMTP server from Apex Application )
I have the following scenario:
1) An Oracle Schema associated to an APEX Workspace (with one application inside)
2) Oracle Schema has been granted with APEX_ADMINISTRATOR_ROLE
3) If I execute (via SQL Developer) from my Oracle Schema:
begin
execute immediate 'ALTER SESSION SET CURRENT_SCHEMA = APEX_040100';
APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_HOST_ADDRESS','localhost');
end;It works fine.
4) So I put that code inside a PL/SQL Package
5) Then, I try to execute package from Apex Application, and I get:
Error:ORA-20987: APEX - User requires ADMIN privilege to perform this operation. - Contact your application administrator.What am I missing? Who is executing my package code when calling it from APEX? Do I have to grant APEX_ADMINISTRATOR_ROL to other users?
Thanksjcoves wrote:
Hi,
I'm having trobule when I try to execute APEX_INSTANCE_ADMIN.SET_PARAMETER from an apex application.( For further information, I'm trying to implement this Re: Changing SMTP server from Apex Application )
I have the following scenario:
1) An Oracle Schema associated to an APEX Workspace (with one application inside)
2) Oracle Schema has been granted with APEX_ADMINISTRATOR_ROLE
3) If I execute (via SQL Developer) from my Oracle Schema:
begin
execute immediate 'ALTER SESSION SET CURRENT_SCHEMA = APEX_040100';
APEX_INSTANCE_ADMIN.SET_PARAMETER('SMTP_HOST_ADDRESS','localhost');
end;It works fine.
4) So I put that code inside a PL/SQL Package
5) Then, I try to execute package from Apex Application, and I get:
Error:ORA-20987: APEX - User requires ADMIN privilege to perform this operation. - Contact your application administrator.What am I missing? Who is executing my package code when calling it from APEX? Do I have to grant APEX_ADMINISTRATOR_ROL to other users?
YES
Look at this {message:id=10266929} -
Hi,
I have written a report which gathers errors in a test data container.
These errors are stored in a internal table of type stringtab.
I want to create a Application Log of these errors so that the user can
view it at a later time.
Are there predefined function modules available in ABAP for creating and viewing log?
Kindly provide me the details.
Regards,
Bikash.Hi Monika,
Is it necessary to add messages from message class in
BAL_LOG_MSG_ADD --> Put message in log.
Is there any way where a string can also be added and viewed from a application
log?
For my use case i actually have a stringtab for which i want to have a log.
Regards,
Bikash.
Maybe you are looking for
-
ITunes cannot see data in the MyBookLive shared drive, but it's there
I have iTunes on a Mac OS X 10.6 and the 2TB MBL. I transferred 40G of music from local drives to my MBL successfully. I can see those in Finder - Public - Shared Music. I enabled the Public Share to be "ALL" for media sharing. I can see the MBL in t
-
Hi I wonder if the Exists condition can be used in the CDS view (WHERE EXISTS (SELECT * FROM .... ) . I actually never managed to used subqueries in any cds view so I wonder if this is a limitation for CDS view or if I just do not get the syntax rig
-
Two clips that are overlaid creates white line when rendered
In Final Cut Pro 7, I have copied a clip on top of itself in the timeline. - The clip on top was then moved to the right so that the clip below would be seen slightly ( I needed a way to scoot the subject over while preserving the background on the l
-
Setting a global/default background colour?
Hi, Is there a way in which I can set all objects in my program to have the same background colour with a global command, rather than have to do it for every single object seperately. Dave.
-
Hi guys, Does anyone know why would lsass.exe be using 3 GB of RAM on an application server with 8 GB of RAM in total running on Windows 2008 R2 SP1? Is this something I should log with Microsoft support? Thanks Zoran