Testing a procedure? [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I'm new to PL/SQL and I think Ive created a procedure inside of my package body, when i run it in SQL commands it says it been successfully created, I am just not sure how to test it?
The procedure is to delete a customer based on their ID
Here is the code
PROCEDURE remove_customer (customer_id VARCHAR2) IS
BEGIN
DELETE FROM customer
WHERE customer.customer_id = remove_customer.customer_id;
END;
any idea on how to test it works?
Thanks

You can run it from an anonymous block:
begin
your_package.remove_customer('CUST_ID');
end;
/
If you're using SQL*Plus or SQL Developer there's a shorthand for this with the execute command:
exec your_package.remove_customer('CUST_ID');
And then check that the customer you tried to delete is no longer in the table...

you would just run it as:
begin
your_package_name.remove_customer('abc');
-- commit; -- optional if you want to commit it.
end;
/

Related

What is a parametrised select? PL/SQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We need to add a parameterised select in a pl/sql function. But I don't know what is a parameterised select. :(
You are probably talking about using bind variables in SQL statement in a PL/SQL code, like this:
declare
anumb number:=1;
.....
begin
select ....
into ....
from your_table
where a_column=anumb .....;
....
end;
In this sample code, the select can be called 'parameterised', as is uses a variable set before in the SQL. 'anumb' can also be a parameter passed to a function or procedure.
Finally, why do you tag your quest with sql-server when you have PL/SQL in the subject?

SQL Server's SET NOCOUNT ON Postgresql equivalent [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I've to help migrating a SQL Server 2008 database to a PostgreSQL 9.4.10 one. The original querys have SET NOCOUNT ON and SET NOCOUNT OFF several times, and I can't change this fact so ignoring the number of rows affected isn't a solution. That's why I need to find an equivalent to this statement, but all I can find are really old posts where they say I should ignore the result. Any ideas? Thanks.
EDIT: these SET NOCOUNTare inside a stored procedure that goes like this:
CREATE PROCEDURE [procedureName]
Declares
--Variables
WITH ENCRYPTION
AS
SET NOCOUNT ON
--Procedure's code
SET NOCOUNT OFF
GO
As I've said this code isn't mine, so I can't post any of it more than the source of my doubt.

how to rollback a transaction using rollback command? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have deleted a record from my table and after executing rollback command it shows "command completed successfully" but when i check it using select statement the table is still looking empty? why ?
Some database connection methods such as ODBC default to what's known as "autocommit" mode - that is, the database connection automatically issues a COMMIT after each statement is executed. JDBC does the same thing. I cannot say if this is what's happening in your case, but if so there's no way to do a ROLLBACK. Best of luck.
Rollback command takes you back to the latest committed state of the table.I guess your delete query might have contained some statement that committed the change(deletion of record).
Jason Clark,
I did a test using MySql and use the "begin", "delete" and "rollback", used the following SQL (an example):
begin; delete from aluno where id = 1; rollback;
In PostgreSQL, SQL syntax is the same and also worked.
Are you sure you used the correct SQL? I might have been some mistake? Is it really necessary to use "begin transaction" instead of just "begin"?
I hope this helps!

SQL Query behaving weird [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Below queries in sql giving weird results. Please help me to understand why it is happening.
exec sp_executesql N'SP_MNP_DownLoadFiles #FileTypeId,#UserId',N'#FileTypeId smallint,#UserId bigint',#FileTypeId=2,#UserId=18 -- This query returns nothing
Exec SP_MNP_DownLoadFiles #FileTypeId=2,#UserId=18 -- This query returns some result
Select Type as FileTypeId ,FileStream as Attachment FROM MNPFiles
where CustomerId = 18
AND
Type = 2 -- This is the query inside SP.
Please consider the data types are same everywhere.
What I am doing wrong here?
Your dynamic SQL string doesn't match your non-dynamic statement.
exec sp_executesql N'EXEC SP_MNP_DownLoadFiles ...',...
^^^^
Other things to check:
Other SELECTs in your stored procedure prior to your main one. You may need to SET NOCOUNT ON.
That you're not RETURNing something before your main query

Can't execute a procedure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
this is the procedure name :
procedure misowner.proc_kr_text_niki(valdate in varchar2 default '20040101'
, v_table varchar2 default 'KR_TEMP')
and i what to EXEC it. What kind of variables i have to put?
Given that you have default values for the parameters you should be able to surround it with a block like this, and execute it as a script if you are using a GUI tool like SQL developer or Toad
DECLARE
valdate VARCHAR2(10);
v_table VARCHAR2(30);
BEGIN
misowner.proc_kr_text_niki;
END;
This works for testing, then, as suggested by BazzPsychoNut, initialize the variables, pass them in and test some more.
You call it by providing two parameters. The first parameter (= variable) "valdate" is in varchar2. It is apparently a date inputted as text in the form YYYYMMDD. The second parameter "v_table" is a varchar2, probably the name of the table to query on.