BEGIN
PROC_TEST('20-10-2020');
END;
I tried to execute this procedure,After executing output shows anonymous block completed. with out any error
but it is actually not compiled.
how solve this problem?
Compiled? You just executed an anonymous PL/SQL block which calls a procedure named PROC_TEST and passed a string as a parameter. I guess you meant to pass a DATE instead. Did you? If so, try
set serveroutput on
begin
proc_test(date '2020-10-20');
end;
/
instead.
Procedure executed successfully, regardless.
If you expected some kind of an output (via dbms_output.put_line, for example), enable serveroutput (like in my example, which works in SQL*Plus, SQL Developer or maybe some other tools as well; if not, enable it via GUI you use).
Finally, I don't see any problem here to be solved. What exactly do you have on mind?
Related
I have a PL/SQL package (say package1) which contains only 1 procedure. This procedure is used for security purpose and stores the application logged in user using SET_CONTEXT method.
I have another package (say package2) which contains several procedures related to application functionality but they use the SYS_CONTEXT to get the logged in user.
Whenever I want to call package2's procedures from Java, I want package1's procedure to be executed first and then package2's procedures. The reason is I want both these calls to happen in the same database connection.
Is there a way to configure this in Oracle instead of repeating the call to package1's procedure inside each and every package2's procedures.
Assuming your procedure in package1 is public (i.e., declared in the package specification), and assuming your package2 procedures have an EXECUTE authority on package1, one of the possible solutions will be using INITIALIZING PACKAGE .
The initialization consists of all the statements following the BEGIN statement at the end of the package declaration to the END statement
Ex.
PACKAGE BODY package2
IS
--All your package2 procedures
--initialization section at the end of package2:
BEGIN
package1.procedure1();
END package2;
This initialization section, will be run only the first time your session uses a package2 (by using any function/procedure in it). The package will be re-initialized in the same session if it is recompiled.
Another way to solve this problem is place code of package1 (package1.procedure1();) into user logon trigger or call that procedure from that trigger; please find example bellow for trigger
Example:
CREATE OR REPLACE TRIGGER hr_logon_trigger
AFTER LOGON
ON HR.SCHEMA
BEGIN
-- you code here or call to package1.procedure1();
END;
I need help in creating logs in a stored procedure.
Scenario is like:
I am creating a procedure. I need to log some intermediate information from the procedure in a log file, such that each time the procedure is executed the logs are generated.
Normally i was using SPOOL for this purpose, but as SPOOL is SQL PLUS and cannot be used in PL/SQL, i was look for a better way through which logs written to specific file each time the procedure is triggered informing the updates which are made in the procedure.
Can someone please help me in identifying any such code snap which i can insert in the stored procedure in order to meet my requirement.
NOTE: I am using Oracle.
You could simply create a package with simple logging functionality, which opens, writes and closes a log file that is stored on the database server. Look into the UTL_FILE package;
I am trying to add an control to my page. I am following the wizard. Step 1, I select my connection string. The connection works, no error messages. Step 2, I choose "Specify a custom SQL statement or stored Procedure" radio button. Step 3, in the "SELECT" tab I click the "Stored Prodedure" radio button, then select the stored procedure I would like to use. I take this as confirmation that the connection string is working. Step 4, I press the "Test Query" button.
A pop up appears with the message "There was an error executing the query. Please check the syntax of the command and if present, the types and values of the parameters and ensure they are correct. Could not find stored procedure .
I've tested the procedure in SSMS, and it works. I took the query string that is in the stored procedure and changed the radio from Step 3 to "SQL Statement" and pasted the string into the box. The statement worked fine.
I also changed the permissions for the login specified in the connection string to the same permissions I have on the server. (Full admin rights!) That did not correct the issue. I only found a few questions in the forums regarding this issue, and they all pointed to permission issues, but I have ruled that out as I set the permissions.
The Wizard can find the procedure when I am walking through the Wizard, but it can't find it when I test.
I hope someone can point me in the right direction... Thanks!
* EDIT *
Just to expand on the #BlackjacketMack's answer:
When I use the wizard to create the SqlDataSource, and select the Stored Procedure from the the list, it appears that VS is defaulting to the dbo schema at runtime, even though it displays all the sprocs in each schema. (I verified this by changing the schema the sproc was on to dbo and testing it. The results were returned with no errors.) Within the wizard, I do not see any options to change the schema. If I click the "SQL Statement" radio button and type EXECUTE [APP001].[MyStoredProcedure], it works perfectly. I did try the GRANT EXECUTE as #otaku recommended, but that did not work. I also changed the default schema for the user specified in the connection string to [APP001] to no avail. So this appears to be an issue when using the dropdowns in the wizard. Manually entering the data so that the schema can be fully qualified did the trick!
Make sure the application that you are running have the appropriate grant execute on the database objects. Sometimes they are tied to a database role such as below where the stored procedure need to have the execute permission:
GRANT EXECUTE ON ][dbo].[MyStoreProc] TO U_ExecuteProcs
Qualify your procedure with the schema If the proc has a schema 'APP001' as you indicated in a comment, make sure the Sql being passed looks something like EXEC APP001.YourStoredProcedureName.
Use a profiler! One great way to approach this problem is run a profiler on your SQL...either the MS Profiler, or we use http://anjlab.com/en/projects/opensource/sqlprofiler which used to be free. Basically, you'll see exactly what SQL your application is sending and who the login they're sending it as.
If you gave yourself admin permissions as you indicated, I wouldn't define too many object specific permissions simply because they tend to go unmaintained.
I think defining the execution context within your stored procedure will resolve the issue , Here is the link:
http://technet.microsoft.com/en-us/library/ms188354.aspx
I am very new to the PL/SQL programming. I tried to write a pl/sql procedure with some DML Statements(insert) inside the code. I am not doing any explicit commit after performing insert operations in the pl/sql code. But the transaction is getting commited after executing pl/sql procedure.
is this the default behaviour?
How can i control this?
DML statements (INSERT/DELETE/UPDATE/MERGE) don't do an auto commit in PL/SQL.
DDL statements do commit (ALTER/CREATE etc) and this will happen even if something failed. If you're running EXECUTE IMMEDIATE like dynamic statement that runs a DDL, this will also commit your transaction. And its been like that [and will remain] since 2000
Client interfaces like SQL*Plus have an auto commit feature that can be turned off/on , look for it in the client documentations. Something like
SET AUTOCOMMIT OFF
You can see the current status of this variable
SHOW AUTCOMMIT
and that will tell you whether its on/off .
Go through this for more variations of autocommit
In the PL/SQL Developer client, you control the autocommit of SQL Window transactions via Preferences.
I had a stored procedure with no arguments which was invoked form the UNIX
script by db2 call and the SP was working fine and script running fine as well.
The new requirement is to pass a file name to the stored procedure and do some
business logic -- I am not able to pass the file name from UNIX to the SP. I am using IN parameter of Varchar(50).
The SP compiled fine and is available in the correct schema -- I invoked
using multiple ways and none of them are working fine.
Please help me debug this.
DB2 Stored Procedure:
CREATE PROCEDURE ABC.sp_Update(IN FILE_NAME VARCHAR(50))
Different methods I tried Calling the DB2 stored proc from the UNIX script
db2 call "ABC.sp_Update("filename.txt")"
db2 call "ABC.sp_Update(("filename.txt"))"
FILE_NAME="filename.txt"
db2 call "ABC.sp_Update($FILE_NAME)"
FILE_NAME="filename.txt"
db2 call "ABC.sp_Update($(FILE_NAME))"
The error I get:
db2 call ABC.sp_Update(filename.txt)
SQL0206N "FILENAME.TXT" is not valid in the context where it
is used. SQLSTATE=42703
When I checked for the execution status of the command I get a return code 4
+ RC=4
Before the code change, this worked fine:
db2 call "ABC.sp_Update()"
When I Googled the description of the error 42703, it is An undefined column, attribute, or parameter name was detected.
Sorry Guys - Should have used a single Quote - It worked - Thanks and sorry