I'm executing the following stored procedure:
rows, err := w.repo.GetConn().Queryx("EXEC [Users].[User_Get] #ids", sql.Named("ids", tvp))
And getting the following error:
SQL: expected 0 arguments, got 1.
What's wrong and how to fix this?
The problem was in driverName I put mssql there instead of sqlserver)
Related
I am trying to create a stored procedure in informix database, but when I try to run the create procedure code the following error appears on the very first line:
Error: A syntax error has occurred.
SQLState: 42000
ErrorCode: -201
Position: 167
Error occurred in:
create procedure test(p_from_date date, p_to_date date, p_department_id like department.id, p_username LVARCHAR(100)) returning decimal
DEFINE v_report LVARCHAR(32100)
this is my code:
create procedure test(p_from_date date, p_to_date date, p_department_id like department.id, p_username LVARCHAR(100)) returning decimal
DEFINE v_report LVARCHAR(32100);
DEFINE v_report_result_id LIKE report_result.id;
DEFINE v_amount, v_bank_amount, v_nap_amount, v_pos_amount DECIMAL(16);
DEFINE v_f_report_result SMALLINT;
DEFINE v_order_number LIKE report_result.order_number;
DEFINE v_payment_canal, v_type LVARCHAR(20);
DEFINE v_department_name like department.name;
DEFINE v_rownum integer;
DEFINE v_current_time VARCHAR(30);
.
.<rest of the code>
.
return v_report_result_id;
END PROCEDURE;
I found out what the problem was.
The statement separator needed to be changed from ; to whatever else that is not used inside the code (I changed it to #).
Because on the first ; character that the interpreter will find in the code (which was on the first line) was interpreted like end of whole code (whole procedure creation).
I am using SQurreL and changed statement separator like this: session > session properties > SQL > statement separator.
I hope this will help everyone else who gets in the same problem as me.
When i am running below query first time its working but after again i am going to run this query i am getting exception
Select count(*) into rec from all_tables where table_name='DefaultTable';
if(rec=1) then
CREATE TABLE DefaultTable(
Code INT NOT NULL,
Code1 INT NOT NULL,
ResultCode INT NOT NULL,
CONSTRAINT DefaultTable_PK PRIMARY KEY(Code,Code1)
);
else
PRMOPT DefaultTable Already Exist //To print in Console
end if;
Can anyone tell what i am doing wrong? and what all i am doing wrong to write the above query ?
Error starting at line 2 in command:
if(rec=1) then
Error report:
Unknown Command
Error starting at line 3 in command:
CREATE TABLE DefaultTable(
Code INT NOT NULL,
Code1 INT NOT NULL,
ResultCode INT NOT NULL,
CONSTRAINT DefaultTable_PK PRIMARY KEY(Code,Code1)
Error at Command Line:3 Column:14
Error report:
SQL Error: ORA-00955: name is already used by an existing object
00955. 00000 - "name is already used by an existing object"
*Cause:
*Action:
Error starting at line 16 in command:
else
Error report:
Unknown Command
Error starting at line 17 in command:
PRMOPT Table Already Exist
Error report:
Unknown Command
Error starting at line 18 in command:
end if
Error report:
Unknown Command
Well, as I understand the author is trying to do it in one sql query. But in Oracle you can not use IF statement in simple sql. Moreover, even if you use PL/SQL the DDL statements are not allowed to be directly invoked from PL/SQL code, so you should use dynamic SQL. I think, the following script will do what you want:
DECLARE
rec NUMBER;
BEGIN
SELECT COUNT(*) INTO rec FROM all_tables WHERE table_name='DEFAULTTABLE';
IF (rec=0) THEN
EXECUTE IMMEDIATE 'CREATE TABLE DefaultTable(
Code INT NOT NULL,
Code1 INT NOT NULL,
ResultCode INT NOT NULL,
CONSTRAINT DefaultTable_PK
PRIMARY KEY(Code,Code1,ResultCode)
)';
ELSE
dbms_output.put_line('DefaultTable Already Exist');
END IF;
END;
Please, note that in order to see the messages printed via dbms_output, you should execute:
SET SERVEROUTPUT ON;
If you read the error message you will notice it says:
ORA-00955: name is already used by an existing object
This means you are trying to create a table that already exists. That explains why it runs the first time and not any more after that.
Check the entries in all_tables and you will find that Oracle creates tablenames in uppercase. So check for 'DEFAULTTABLE'.
I had some help on here and got the following code:
-- Setup Solrid Function
CREATE OR REPLACE FUNCTION solrid(IN local_id INTEGER, OUT result TEXT) AS $$
DECLARE
database_id TEXT := 'A';
BEGIN
result := database_id || local_id::TEXT;
END;
$$ LANGUAGE PLPGSQL;
However when I run it in sqlfiddle it says:
Schema Creation Failed: ERROR: unterminated dollar-quoted string at or
near "$$ DECLARE database_id TEXT := 'A'":
This error may seem pretty self explanatory but I can't figure out the way to fix it. Would anyone mind shedding some light on this please?
There is absolutely nothing wrong with this function, it is 100 % legit. I tested with 8.4 and 9.1 in my installation.
There must be some kind of misunderstanding. This cannot be exactly the same code that triggers the error message.
I am trying to learn how to do a PreparedStatement as follows:
createConnection();
conn.setAutoCommit(false);
String sql = "SELECT MAX(?) FROM ?";
PreparedStatement stmt = conn.prepareStatement(sql);
However, when I hit the last line, it throws a java.sql.SQLSyntaxErrorException as follows:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "?" at line 1, column 20.
I have searched everywhere but cant find any reason for it to fail. What am I doing wrong? later on in the code I am setting the ? parameters as meaning full string values but when I debug I never get to that point. It hits this conn.prepareStatement line and throws the exception. Thanks for the help. I don't know if it makes a difference but it is on a derby database.
Think of your ? mark as a sql variable. You can't do a select MAX on a variable, it's syntactically incorrect.
You can't do the following:
declare #myvar int
select #myvar = 1
SELECT MAX(#myvar) from SomeTable
I am attempting to export a query in Sybase SQl Anywhere but am receiving an error when getting to the OUTPUT TO command. My query looks like this:
SELECT User_Name as 'Remote Database', nDaysBehind as 'Days Behind', Time_Received as 'Last Message Received'
FROM DailySynchRptView
WHERE Time_Received < today() -1 AND nDaysBehind > 0
ORDER BY Time_Received ASC
OUTPUT TO c:\daysbehind.txt format ascii
The information that shows up in ISQL when I leave off the "OUTPUT TO" is the following:
Remote Database,Days Behind,Last Message Received
'Rem00027',23,'2011-02-23 16:10:14.000'
'Rem00085',7,'2011-03-11 04:47:02.000'
'Rem00040',5,'2011-03-13 15:22:15.000'
'Rem00074',4,'2011-03-14 16:01:25.000'
'Rem00087',3,'2011-03-15 06:04:16.000'
However, when the OUTPUT TO command is placed in the query, I receive the following error:
Could not execute statement.
Syntax error near 'OUTPUT' on line 5
SQLCODE=-131, ODBC 3 State="42000"
Line 1, column 1
I am open to any suggestions that might help me be able to export the data from the query. I have ran a similar query that returns a single line of information and it does export without errors.
After a while looking at the code, I found that I was missing a semi-colon ; to separate the two sets of commands. Once I added the semi-colon before the OUTPUT line, I was able to export the information.