Error during Invoking a Stored procedure from UNIX - unix

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

Related

why the output values length are getting reduced when using DB links in oracle and asp.net

We are retrieving the output from table through DB link by executing a stored procedure and input parameters which worked previously and got the output in asp.net application.But now we noted that outputs through DB links are getting trimmed say if status is 'TRUE' ,we are getting as 'TRU' etc why the output values are getting trimmed.The only change we did recently was we changed one of the type of input parameter from number to varchar at the receiving remote side,But i don't think that is the issue??whe we execute the stored procedure remotely on the table.It is giving proper output but through DB link outputs are getting trimmed.ANy one has any idea about this issue??
My oracle client is having issues,i reinstalled and it worked fine.Only my system was having issues.so i desided to reinstall

Oracle SQL French script file

I need to do a mass insert into my database. I have French characters(e.g é) into my table
When i connect to SQLPlus and run the query manually
INSERT INTO TEST VALUES ('é');
Data is inserted properly.
When i save the same query in an Sql file and execute same through SQLplus
I get below error:
SQLPLUS>#test.sql;
ERROR:
ORA-01756: quoted string not properly terminated
Can anyone guide me.
thanks

Using SET_CONTEXT and SYS_CONTEXT

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;

SP Not Found When It Clearly Exists

I copied a database from a live MSSQL server to my local one, and was able to log in correctly. I am having a problem however in that when it is time to call a stored procedure the Asp.Net application keeps telling me the SP does not exist, when it clearly does.
I am using windows authentication but on the server I was using credentials, could this be the problem?
Also, all of the SP's have my online username attached to their name, as in username.StoredProcedurenName.
Please help I have been trying to fix this for hours.
I just noticed that when I attempt to run the SP from the SQL Management Studio it works, but it appends the username to the SP such as:
USE [DBNAME]
GO
DECLARE #return_value int
EXEC #return_value = [username].[SPNAME]
SELECT 'Return Value' = #return_value
GO
If I remove the username, it says the same thing (SP not found). How do I get around this?
I suspect you are calling your stored procedure without specifying the schema. When calling a stored procedure (or accessing a table, view, etc) that's not in the default schema that your account is configured for, usually dbo, you need to explicitly include the schema like the sql command below
SqlCommand cmd = new SqlCommand("username.StoredProcedurenName", mySqlConnection);
It's likely what Jason said. The solution has to do with rights and ownership. When you see the SP in the SQL Management Studio, under Programmability->Stored Procedures, your SP should have a prefix like "dbo." or "GateKeeper."
If the SP has "dbo." as the prefix, the user account with which you're connecting to the DB just be part of the database owners (dbo) group, otherwise you won't have access to it. So, you can either add the user to that group, or create the stored procedure ("create procedure spBlahBlah as ..") using the account to plan to run the program under; when you call it you use "exec GateKeeper.spBlahBlah" to stipulate the Schema.StoredProcedureName.
Those are your two choices.

iSeries (AS400) Output with ODBC connection

I am very new to AS400, and I am stuck. I have read documenation but cannot find what I need.
I have an odbc connection to an AS400 server. When I run this command I get an Outfile with everything I need:
CALL QSYS.QCMDEXC('DSPUSRPRF USRPRF(*ALL) OUTPUT(*OUTFILE) OUTFILE(CHHFLE/TEST3)', 0000000061.00000)
Instead of the results going to an outfile I need to receive the results of this command to my script that is connecting through odbc. If I change 'OUTPUT(*OUTFILE)' to 'OUTPUT(*)' I get no results when I try to 'fetchall()'.
Is there any way to get this information through the odbc connection to my script?
EDIT: I am on a linux server, in a python script using pyodbc to connect. I can run sql queries successfully using this connection, but I can't figure out how to get the results of a command to come through as some sort of record set.
I hope I'm interpreting what you're asking correctly. it looks like you're accessing user profile data and dumping it to a file. It looks like you then want to use the contents of that file in a script or something that's running on Windows. If that's the case:
In general, when accessing data in a file from the Windows world, whether through ODBC and VBScript, or .NET, the AS/400 is treated like a database. All files in libraries are exposed via the built-in DB2 database. It's all automatic, and part of the Universal DB2 database.
So, after creating this file, you should have a file named TEST3 in library CHHFLE
You'd create a connection and execute the following SQL statement to read the contents:
Select * From CHHFLE.TEST3
This, of course, assumes that you have proper permissions to access this. You should be able to test this using the iSeries Navigator tool, which includes the ability to run SQL Scripts against the database before doing it in your script.
Added after reading comments above
There's info at this question on connecting to the DB2 from Python. I hope it's helpful.
OUTPUT(*) is not stdout, unfortunately. That means you won't be able to redirect OUTPUT(*) to an ODBC connection. Dumping to a DB2 table via OUTPUT(*OUTFILE) is a good plan. Once that's done, use a standard cursor / fetch loop as though you were working with any other DB2 table.

Resources