functios in pl sql that returns week in ISO - function

how to create a simple function in pl sql that contains 2 variables that returns Week in ISO and second varable returns error message that "data was inserted incorrectly" for any table insertion
throw in exception
dbms.output

Related

Creating MySQL Stored Procedure

I am using Aqua Data Studio 20.6 to create a MySQL stored procedure. The following is my procedure, I have named it sp_GetObjIDByProType:
( IN prono char(15), IN imgtype char(8), OUT objid bigint )
BEGIN
SELECT ObjectID INTO objid FROM images WHERE ProNumber = prono AND DocType = imgtype LIMIT 20;
END
When I try to create the stored procedure, I get this error message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN imgtype char(8) )
( OUT objid bigint )
BEGIN
SELECT ObjectID INTO objid F' at line 3
However, it appears as if creating the task was actually successfully
(sp_GetObjIDByProType appears under 'Procedures'). I can view and alter this created stored procedure in another window (resulting stored procedure in 'Alter' window). Does this mean that creation of the stored procedure was actually successful, or is there something wrong with what I did?
Looks like your procedure was created. However, the LIMIT 20 in the query does not make sense. You are returning the selected ObjectID in the OUT parameter which can hold only one value. Yet you limit the query to 20 rows.
If you want to return max 20 rows, return the rows as a result set (leave out the out parameter and the INTO objid), or limit the rows to just one row.

Inserting date from working subselect occurs in error

Context:
CREATE TABLE dates (
date DATE
);
I have following select query which returns 2000-01-01, because LAST_DAY function returns null because of invalid date.
Edit: I know that 2012-02-31 is incorrect date. That's the point of this question.
SELECT IFNULL(LAST_DAY('2012-02-31'), '2000-01-01'); // returns 2000-01-01
However when I try to insert this result into the table it returns an error:
Query Error: Error: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: '2012-02-31'
INSERT INTO dates (date)
SELECT IFNULL(LAST_DAY('2012-02-31'), '2000-01-01');
Why does it happen like that? What's the explanation?
DB Fiddle

Count the number of rows returned from a view or stored procedure written in a table

I need to created a SQL SERVER stored procedure which count for me the number or rows returned from a view or a stored procedure writted in a table. For example this script:
select QueryString
From abo.PageContents
where PageElementID = 1 and DataDomainID = 4
returns me:
select * from dbo.vGEcProduseAtrib
And a need to output the number of rows returned from the previous select (or exec dbo.Example) which come random, by the DataDomainID i selected. Thank you!

can i run a group by statement within stored procedure and return the output as variable

Hi All,
i am a nub to mysql and i am experimenting with stored procedure, i have written a script to calculate count of Respondent id, for now stored procedure returns a cumulative number however i would like resultant grouped by each city. when i attempt that i get an error message stating "Result consisted of more than one row error"
Note: i am aware that i can query using where statement for each city however that method is in-efficient as i have to manually key in each distinct city name hence i am looking for alternatives to efficiently tackle this
any help would be greatly appreciated
regards
Sri
Stored Procedure code
DROP PROCEDURE IF EXISTS `Total_grpby`$$
CREATE DEFINER=`root`#`localhost` PROCEDURE
`total_grpby
`(
OUT ex_total INT
)
BEGIN
SELECT COUNT(rsp_id) As total INTO ex_total
FROM test.`jnk_test`
GROUP BY Dmc_Cty;
END$$
desired output
dmc_cty Total
Chennai 337
Delhi 263
Gurgaon 53
Hyderabad 406
Mumbai 482
Noida 464
Pune 522
No, it's not possible in MySql.
OUT ex_total INT declares a variable of type INT.
The type Int can hold one - and only one value - it is a scalar variable.
However your query returns many values, not one.
To store many values you need something like an array, or a collection.
Unfortunately, MySql doesn't support array nor collection datatypes, so in MySql you cannot store many values in one variable and return them as OUT parameter from the procedure.
This is possible in other databases, like PostgreSQL, Oracle, SQL-Server, they support collection datatypes.
In MySql, an ordinary SELECT (without INTO clause), which is execuded in the procedure, creates a resultset and returns it from the procedure to the client.
Unfortunately MySql is not able to read this resultset - for example if you call a procedura A, that returns a resultset, from another procedure B, then the procedure B is not able to retrieve data from the resultset returned by the procedure A.
This resultset can be read only by some clients, for example JDBC or ODBC connectors, SQLPlus or MySQLWorkbench etc.

Mysql stored procedure called successfully but no output records shown

I have used the following code to create a procedure:
DELIMITER //
CREATE procedure GetBooksbyBorrowerID (IN Bor_id VARCHAR(10))
BEGIN
SELECT borrower_details.Borrower_ID ,borrower_details.Book_ID, book_mst.book_Title,book_mst.LANGUAGE, borrower_details.borrowed_from_date
FROM borrower_details
JOIN book_mst
ON borrower_details.BOOK_ID = book_mst.ISBN
WHERE (borrower_details.borrower_id = 'Bor_id');
END //
When I call this procedure, it says Mysql query executed successfully, but does not show the output records. And there are records in the database that match the criteria in the query. I use the following statement to call:
CALL GetBooksbyBorrowerID ('BOR001');
What should I do to view the output records?
You are comparing borrower_details.borrower_id with the string 'Bor_id' and not the parameter.
Use WHERE (borrower_details.borrower_id = Bor_id);