How to make temp table in PL-SQL procedure? [closed] - sql

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 5 years ago.
Improve this question
I am new to PL-SQL. Can anyone answered me how to write Select statement(temp table) and apply if/else on the basis of that temp table and print output line?
Sorry if you are asking my work/effort to see how far I have made it...I am looking a way to start.
Any help would be highly appreciable.

i didn't know about your exact requirement, below code is for my understating from your question.
COde
decalre
a varchar(100);
b varchar(100);
begin
select data1, data2 into a,b from temp_table where (condition);
if a= 1 then --- assume
--your code
elsif b=2 then
--your code
else
--your code
end if;
end;

Related

fetch all rows if where field is empty in postgres [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 1 year ago.
Improve this question
I am working with a sql query where I have fields set dynamically but few of the fields values can be null,In case its null I want to fetch all the records with that column data.
like:
Select * from users where name=:name and class=:class;
Now suppose I have got value of only name variable and not the class,So now As class variable is not there It will give a error but I want to fetch users with all the classes in that case?
I tried this but it doesnt work:
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("name", request.params.name);
//run the query
How can I achieve this?
If parameter value is NULL then retrieve all value.
-- PostgreSQL
SELECT *
FROM users
WHERE (name = param_name OR param_name IS NULL)
AND (class = param_class OR param_class IS NULL);

how do i divide 2 varchar2 columns? [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 3 years ago.
Improve this question
Need to divide 2 varchar columns
tried cast function to convert varchar to number
I have put sample below for SQL Server. I am explicitly casting both dividend(10 below) & divisor (2 below) for clarity in the programming.
DECLARE #value1 VARCHAR(10) = '10'
DECLARE #value2 VARCHAR(10) = '2'
SELECT CAST(#Value1 AS INT) / CAST(#Value2 AS INT)

procedure to return a result from existing query [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 4 years ago.
Improve this question
I am trying to create a stored procedure which when called will return me multiple results
so a small variation in my sql code is:
#getnames = select * from mytable order by firstname;
#getActivename = select * from #getnames where Status = 19;
but that sems to be failing and i am not sure what i am doing wrong here
Perhaps you want :
select top (1) #getActivename = firstname
from mytable
where Status = 19
order by firstname;
According to your code you don't need to use two variables you can directly express it as by using single variable.

Add character to end of field in SQL Database if condition = true? [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 6 years ago.
Improve this question
I want to add a star * to the end of the 'DisplayName' field of any record with a category of 2. Not sure how to do this but I think this is on the right track?
UPDATE `table_name`
SET `DisplayName` = replace(DisplayName, 'old_text', 'new_text')
WHERE Category = '2';
My problem is I need to just add a space and a character at the end, not do a find and replace.
The generic SQL would be:
UPDATE `table_name`
SET `DisplayName` = CONCAT(DisplayName, '*')
WHERE Category = '2';
CONCAT() can be spelled in different ways depending on the database -- such as + or ||.

Need help understand and INSERT/UPDATE procedure [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 8 years ago.
Improve this question
I have an INSERT/UPDATE Procedure that will only seem to update when I change the existing "name".
I added a code field to the java, and want to update the code to the existing table without having to modify the "name" because it already exists. If I modify the "name" then the "code" will get updated to that row in the table.
Can someone help me understand whats going or what I need to modify?
thanks
PROCEDURE update_things
(things IN OUT things_bean, user_id IN NUMBER)
IS
t_things things_bean;
BEGIN
-- If there is already an id set ... this is an update
IF things.ID <> 0
THEN
SELECT things_bean (ID, NAME, code, work, foo)
INTO t_things
FROM things
WHERE things.ID = ID;
IF NOT things.equals (t_things)
THEN
things.foo:= t_things.foo;
things.foo.modified_date := SYSDATE;
things.foo.modified_by := user_id;
UPDATE things
SET NAME = things.NAME,
code = things.code,
foo= things.foo
WHERE ID = things.ID;
END IF;
END update_things;
looks to me like you should check this call:
things.equals(t_things)
to make sure your code value is part of the equality check.