I am new to the stored procedure in oracle and my simple code wont compile in oracle toad.
Here is my code:
code
There is a readline under the ALTER, and it says "Found: "ALTER", expecting select or (: BEGIN BASE COSE...) " why is that?
Oracle doesn't allow you to use DDL natively in PL/SQL. To work around this, you can use EXECUTE IMMEDIATE to run the DDL as a dynamic query.
Related
I am trying to solve a task with a dynamic SQL, but facing an issue ora-00900 invalid sql statement.
execute immediate 'alter table my_table set interval (NUMTOYMINTERVAL(1, ''MONTH''))';
However, it works in the anonymous block treating the statement to be executed as a string.
DECLARE
str VARCHAR2 (250) := 'alter table my_table set interval (NUMTOYMINTERVAL(1, ''MONTH''))';
BEGIN
execute immediate str;
END;
So where is the issue in the first case? It looks like with escape quotes, but can’t catch this.
As the error says, execute immediate is not a SQL statement. There is an execute command in some clients - SQL*Plus, SQL Developer, SQLcl and possibly others - which is a shorthand wrapper around an anonymous block; but from the error you don't seem to be using one of those. If you were you'd get ORA-06550 and PLS-0010: Encounter edthe symbol "alter table..." when expecting...
execute immediate is a PL/SQL statement. So it is only valid within a PL/SQL block.
It has no meaning in plain SQL; the only execute in the SQL reference is referring to directory object privileges.
Your alter table doesn't make much sense anyway, not sure if that's supposed to be an update, but if so it isn't say what to set to that interval value. It isn't obvious why you need it to be dynamic either. Possibly that reason and the actual statement have been lost in simplifying for posting your question.
I am trying to write an Oracle SQL query that can take a dynamically-generated string and convert it to a mathematical expression, for example: '1*2*1*3*2' would evaluate to 12.
I have done Google searches, but the only Oracle-specific examples I can find are ones that require using a PL/SQL Stored Function. That isn't an option for me, because I do not have 'CREATE' privileges on my organization's production database. Since I often need to troubleshoot SQL code against the production DB, I avoid using Stored Procedures or Stored Functions in my report development tool (LogiInfo).
So...what I am hoping to find is some type of 'built-in' function I can place directly into an SQL statement, that will perform the conversion and evaluation described in my opening sentence. Any guidance will be appreciated.
P.S. I am using Oracle 11g
If you can use SQLPLus you can execute anonymous plsql blocks of code.
Example:
set serveroutput on
declare
i pls_integer;
begin
execute immediate 'select 1*2*1*3*2 from dual'
into i;
dbms_output.put_line(i);
end;
/
I'm working with SSIS 2008 and am having a problem calling an Oracle stored procedure that has an output parameter.
I call the stored procedure in SqlPlus like this:
var vresult number;
exec my_stored_procedure(:vresult);
print vresult;
The statements work and I get the output I need. I am trying to do something similar in SSIS, yet I need to do this repeatedly, maybe in a ForEach or a script to update a temporary result set with the result of calling the stored procedure (the stored procedure generates a number, and I need to add that number to each row in a result set which just holds some state information).
I have tried a lot of different approaches and always end up with 'invalid statement' or similar errors.
I have also tried the following approaches:
How to resolve SQL query parameters mapping issues while using Oracle OLE DB provider?
Update a row in oracle using OLEDB command(SSIS)
Oracle variables
The crux of the problem seems to be the stored procedure's output parameter.
I have tried using the the Oracle Provider for OLE DB. Any ideas?
If you are trying to invoke The stored Procedure in Oracle PLSQL this Link is very brief.
http://plsql-tutorial.com/plsql-passing-parameters-procedure-function.htm
If you are Working in Java then. The Statement Object
java.sql.CallableStatement ps;
ps.registerOutParameter(parameterIndex, sqlType);
Similarly .Net or Any Other Platform must will have the same Convictions. Hope so.:)
I came up with a solution that works:
Use the 'declare' and 'end' construct
Combine with 'execute immediate'
Add the 'using' statement to the end of the exec immediate to inject variable
So a script that implements this might look something like this:
declare
myVar number;
myStatement varchar2(50);
begin
myStatement:='exec myProc(:1)';
execute immediate myStatement using output myVar;
end;
Paste this script into an Execute SQL task, set the task's properties and it works!
I'm new to Oracle but it looks like the :1 notation is a place-holder for the variable. You can test this using sqlplus too - just save the code in a file and start sqlplus using the # option on the command line.
The only problem: I can't get value of the variable for use in SSIS, but that's another problem.
check tis post: Run an Oracle package from SQL Server Integration Services
http://www.mssqltips.com/sqlservertip/2724/run-an-oracle-package-from-sql-server-integration-services/
regards
You are almost there. In order to retrieve the value of the output parameter from the Oracle stored procedure in SSIS, here is what worked for me
In the Execute SQL task, paste this in the SQL statement box
declare
vresult number;
begin
my_stored_procedure(vresult);
?:=vresult;
end;
In the Parameter Mapping, ensure to map your SSIS variable to this output of your stored procedure by setting the direction to "Output" and parameter name as "0" (if it is the first parameter)
PS: ensure the Oracle output variable datatypes match your SSIS variables
Thanks
Mezue
I've a script that I am using to build/drop tables and basically setting up the entire schema.
After googling, I still can't figure out how to run a stored procedure.
The script is a .txt file, and I run it using Apex SQL Oracle.
If I write only this line in a script:
execute procedurename(1); --where 1 is paramter.
You have requested to run a script that does not contain any runnable
statements.
SQL>create or replace procedure procedurename(p_num number)
as
begin
null;
end;
/
Procedure created.
SQL>execute procedurename(1);
PL/SQL procedure successfully completed.
everything seems ok on SQLPLUS with oracle 11.
so it must be an apex thing.
Since execute is a sqlplus statement ,try calling the procedure using begin-end PLSQL block in Apex SQL
BEGIN
procedurename(1);
END;
/
save this in a file proc_call.sql and then call it in your script like
#C:\proc_call.sql
where C: is the sample path
For some information refer the below link
https://forums.oracle.com/forums/thread.jspa?threadID=618393
i created a procedure with 32 in argument,it sucessfully created.but when i am executing this in back end oracle the errror came ORA:00900 Invalid sql statement
Use:
SQL> alter procedure [your procedure name here] compile;
SQL> show errors
...to be able to diagnose the issue from the resulting error output.
Also look at view USER_ERRORS.
Sometimes, show errors does not show anything when in fact there are errors. Especially after alter compile.
Finally, re-compile in TOAD or SQL Developer and you can easily navigate to the error.
In Oracle SQL Developer you should execute it this way:
BEGIN
YOUR_PROCEDURE(PARAM1, PARAM2);
END;
If you use EXECUTE or EXEC (which work in SqlPlus) you get the ORA-00900 error.