I am creating a stored procedure inside my DB2 database, here is my stored procedure codes:
CREATE OR REPLACE PROCEDURE PWDCHANGE (UNAME IN VARCHAR(32),
OLDPWD IN VARCHAR(32),
NEWPWD IN VARCHAR(32))
AS
BEGIN
IF LOGINTABLE.USERNAME = UNAME AND LOGINTABLE.PASSWORD = OLDPWD THEN
UPDATE LOGINTABLE SET PASSWORD = NEWPWD;
DBMS_OUTPUT.PUT_LINE('Password Changed Successfully!');
ELSE DBMS_OUTPUT.PUT_LINE('Incorrect Old Password Input');
END IF;
END;
But as I deploy it in my IBM Data Studio it displays an error which says:
Deploy SENJOBLADE.PWDCHANGE(VARCHAR(32), VARCHAR(32), VARCHAR(32))
Running
SENJOBLADE.PWDCHANGE - Deploy started.
Create stored procedure returns SQLCODE: -104, SQLSTATE: 42601.
SENJOBLADE.PWDCHANGE: 1: An unexpected token "VARCHAR" was found following "PWDCHANGE (UNAME IN". Expected tokens may include: ",".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.13.111
An unexpected token "VARCHAR" was found following "PWDCHANGE (UNAME IN". Expected tokens may include: ",".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.13.111
SENJOBLADE.PWDCHANGE - Deploy failed.
SENJOBLADE.PWDCHANGE - Roll back completed successfully.
I don't know why VARCHAR is an unexpected token, I don't know what to change to be able to deploy my stored procedure. The function of this stored procedure is to accept 3 inputs which is used for password changing, a username, a current password, and the replacement password that's why I have 3 IN values.
SENJOBLADE is my schema name, LOGINTABLE is the table name which has two columns, the USERNAME & PASSWORD column
I tried removing the VARCHARs and this error displays:
Deploy SENJOBLADE.PWDCHANGE(IN, IN, IN)
Running
SENJOBLADE.PWDCHANGE - Deploy started.
Create stored procedure returns SQLCODE: -104, SQLSTATE: 42601.
SENJOBLADE.PWDCHANGE: 2: An unexpected token "BEGIN" was found following "PWD IN)
AS
". Expected tokens may include: ":".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.13.111
An unexpected token "BEGIN" was found following "PWD IN)
AS
". Expected tokens may include: ":".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.13.111
SENJOBLADE.PWDCHANGE - Deploy failed.
SENJOBLADE.PWDCHANGE - Roll back completed successfully.
Please help, I'm still learning about stored procedures so I'm not yet used to it. Any help would be appreciated, thank you!
try Deploy SENJOBLADE.PWDCHANGE(UNAME, OLDPWD, NEWPWD)
Related
I am creating a WPF application using Advantage database server. I want to insert some data using stored procedure
Any sample code ?
I tried two input parameter TestID and TestName (both NCHAR)
INSERT INTO TestTable(
Test_Id,
Test_Name)
VALUES (
#TestID,
#TestName);
But show error like
Error 7200: AQE Error: State = HY000; NativeError = 5154;
[SAP][Advantage SQL Engine][ASA] Error 5154: Execution of the stored
procedure failed. Procedure Name: TestInsert. Error 7200: AQE
Error: State = S0000; NativeError = 2121; [SAP][Advantage SQL
Engine]Column not found: #TestID -- Location of error in the SQL
statement is: 42 (line: 3 column: 5) Error in stored procedure:
TestInsert AdsCommand query execution failed.
I am new in SAP ADS. Please help me.
use _XXXX notation for input parameters.
ie,
INSERT INTO TestTable( Test_Id, Test_Name)
VALUES ( _#TestID, _#TestName);
I'm trying to recover a table from Litespeed bakcup. The table is of schema SOURCE. Litespeed object recovery wizard fails with the error:: Table name must be specified in the format owner_name.table_name. I tried with the store procedure directly as well but it's giving the same error. Please help me fix this issue:
EXEC master.dbo.xp_objectrecovery
#filename = 'backup_file_name'
, #filenumber = 1
, #objectname = 'SOURCE.target_rpt_2016'
, #destinationdatabase = 'database_name'
,#destinationtable ='SOURCE.target_rpt_2016_restore'
, #tempdirectory = 'recovery_temp_dir'
I tried giving destinationtable without schema/dbo as well but it's throwing same error.
Atlast figured out the issue.
The owner of the schema Source is a domain account Dom\AXp0101. So when I changed the paramter #ObjectName to '[Dom\AXp0101].[source].[2016_target_rpt_2016]' the recovery completed. Read somewhere that as the owner of this particular schema is a domain account, there might be issues associated with demiliters so we have exclusively specify like above.
I am trying to use the oracle SQL access advisor utility.
For recommendation on performance tuning and partitioning of tables.
But when i try to use it gives me no results and says there are no result for the task.
I am trying below code to generate the recommendation this is an example from SCOTT schema which also giving me same error
declare
v_sql varchar2(2000) := 'select * from emp where empno in (7369,7499)';
v_tuning_task varchar2(200) := 'tune_task_advisor_view7';
v_tune_result clob;
begin
dbms_advisor.quick_tune ( dbms_advisor.sqlaccess_advisor , v_tuning_task, v_sql );
DBMS_ADVISOR.reset_task(v_tuning_task);
dbms_advisor.set_task_parameter(v_tuning_task, 'ANALYSIS_SCOPE', 'ALL');
dbms_advisor.set_task_parameter(v_tuning_task, 'STORAGE_CHANGE', '10000000');
dbms_advisor.set_task_parameter ( v_tuning_task, 'MODE', 'COMPREHENSIVE');
dbms_output.put_line ('Quick Tune Completed');
end;
SELECT DBMS_ADVISOR.get_task_script ('tune_task_advisor_view7') AS script FROM dual;
The Error --
SELECT DBMS_ADVISOR.get_task_script ('tune_task_advisor_view7') AS script FROM dual
Error report -
SQL Error: ORA-13631: The most recent execution of task tune_task_advisor_view7 contains no results.
ORA-06512: at "SYS.PRVT_ADVISOR", line 3350
ORA-06512: at "SYS.DBMS_ADVISOR", line 641
ORA-06512: at line 1
13631. 00000 - "The most recent execution of task %s contains no results."
*Cause: The user attempted to create a report or script from a task that
has not successfully completed an execution.
*Action: Execute the task and then retry the operation
There is one more that when i comment all the SET_TASK_PARAMETER procedure then it run but does not provide any recommendations the output is like --
SCRIPT
--------------------------------------------------------------------------------
Rem SQL Access Advisor: Version 11.2.0.3.0 - Production
Rem
Rem Username:
Is there any parameter which i missed to define here.
For RESET_TASK if i do not rest_task then it gives me error for it also so i have used it here.
Thanks in advance
When I get this error, this typically means that the DBMS_ADVISOR does not have any advise for the profile based on its diagnostic so it doesn't return a report. I typically don't try to produce a ADDM advisor report, but rather look for all the HASH plans I can find for the query, run an explain plan on those hash values, and then profile the one with the best plan.
I forgot to execute the task !
exec dbms_advisor.execute_task('tune_task_advisor_view7');
and then
SELECT DBMS_ADVISOR.get_task_script ('tune_task_advisor_view7') AS script FROM
dual;
OUTPUT will be
SCRIPT
--------------------------------------------------------------------------------
Rem SQL Access Advisor: Version 12.1.0.2.0 - Production
Rem
Rem Username: CHRIS
Rem Task: tune_task_advisor_view7
Rem Execution date:
Rem
/* RETAIN INDEX "SCOTT"."PK_EMP" */
Find address and hash for the query SQL_ID
select address, hash_value, plan_hash_value from v$sqlarea where sql_id = '3mx8whn1c5jbb';
Purge the plan out of the cursor cache (only if it’s determined that it’s the wrong plan). Statistics should be up to date prior to purging out the plan.
exec sys.dbms_shared_pool.purge(',','C');
exec sys.dbms_shared_pool.purge('00000005DF37F740,46318955','C');
Create the tuning plan if one does not exist.
variable stmt_task VARCHAR2(64);
SET SERVEROUTPUT ON LINESIZE 200 PAGESIZE 20000 LONG 9999
EXEC :stmt_task := DBMS_SQLTUNE.CREATE_TUNING_TASK(sql_id => '3mx8whn1c5jbb',task_name => '3mx8whn1c5jbb_AWR_tuning_task');
SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('3mx8whn1c5jbb_AWR_tuning_task', 'TEXT', 'TYPICAL', 'FINDINGS') FROM DUAL;
If the tuning plan is reported. Accept the new plan.
DECLARE
sqlprofile_name VARCHAR2(30);
BEGIN
sqlprofile_name := DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (
task_name => '3mx8whn1c5jbb_AWR_tuning_task'
, name => 'sql_profile_1'
, force_match => true
);
END;
/
If creating a profile doesn’t work or if the plan does not exist in the cursor cache, check the AWR repository to see if a better plan exists.
If you have an AWR repository with the correct plan, you can rerun the queries above and just use the option to get the hash and sql_id from the AWR repository.
If that doesn't work. THEN I used ADDM (As you did above).
I'm trying to check if table exists and if not, then I want to create it. But I'm still getting this error:
Error report -
ORA-06550: řádka 30, sloupec 28:
PL/SQL: ORA-00942: tabulka nebo pohled neexistuje
ORA-06550: řádka 30, sloupec 3:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
My code is:
SELECT COUNT(*) into cnt FROM dba_tables WHERE owner = 'CENTRUMADMIN' and table_name = 'AUD$_BACKUP';
DBMS_OUTPUT.PUT_LINE(cnt);
IF (cnt <= 0) THEN
EXECUTE IMMEDIATE 'CREATE TABLE CENTRUMADMIN.AUD$_BACKUP AS select * from SYS.AUD$ where 1=2';
DBMS_OUTPUT.PUT_LINE('Vytvorena tabulka AUD$_BACKUP ve shematu CENTRUMADMIN:');
END IF;
This code is inside my procedure for cleaning audit trail.
Can anyone pls help? Thanks in advance!
As I read in your comments you said you get the error only when the table AUD$_BACKUP does not exist.
which means you get you error here:
EXECUTE IMMEDIATE 'CREATE TABLE CENTRUMADMIN.AUD$_BACKUP AS select * from SYS.AUD$ where 1=2';
I guess you just dont have permissions for sys.AUD$ in you schema.
please notice that PL/SQL code can use role privileges. which means, even if you have "dba" role on your schema, it wont work. so you should run the following grant command:
Alter user myuser select on sys.AUD$
good luck.
Hi I am using postgresql 8.1.22, I am trying to setup postgresql auditing using the following function.
CREATE OR REPLACE FUNCTION audit.if_modified_func() RETURNS TRIGGER AS $body$
DECLARE
v_old_data TEXT;
v_new_data TEXT;
BEGIN
/* If this actually for real auditing (where you need to log EVERY action),
then you would need to use something like dblink or plperl that could log outside the transaction,
regardless of whether the transaction committed or rolled back.
*/
/* This dance with casting the NEW and OLD values to a ROW is not necessary in pg 9.0+ */
IF (TG_OP = 'UPDATE') THEN
v_old_data := ROW(OLD.*);
v_new_data := ROW(NEW.*);
INSERT INTO audit.logged_actions (schema_name,table_name,user_name,action,original_data,new_data,query)
VALUES (TG_TABLE_SCHEMA::TEXT,TG_TABLE_NAME::TEXT,session_user::TEXT,substring(TG_OP,1,1),v_old_data,v_new_data, current_query());
RETURN NEW;
ELSIF (TG_OP = 'DELETE') THEN
v_old_data := ROW(OLD.*);
INSERT INTO audit.logged_actions (schema_name,table_name,user_name,action,original_data,query)
VALUES (TG_TABLE_SCHEMA::TEXT,TG_TABLE_NAME::TEXT,session_user::TEXT,substring(TG_OP,1,1),v_old_data, current_query());
RETURN OLD;
ELSIF (TG_OP = 'INSERT') THEN
v_new_data := ROW(NEW.*);
INSERT INTO audit.logged_actions (schema_name,table_name,user_name,action,new_data,query)
VALUES (TG_TABLE_SCHEMA::TEXT,TG_TABLE_NAME::TEXT,session_user::TEXT,substring(TG_OP,1,1),v_new_data, current_query());
RETURN NEW;
ELSE
RAISE WARNING '[AUDIT.IF_MODIFIED_FUNC] - Other action occurred: %, at %',TG_OP,now();
RETURN NULL;
END IF;
EXCEPTION
WHEN data_exception THEN
RAISE WARNING '[AUDIT.IF_MODIFIED_FUNC] - UDF ERROR [DATA EXCEPTION] - SQLSTATE: %, SQLERRM: %',SQLSTATE,SQLERRM;
RETURN NULL;
WHEN unique_violation THEN
RAISE WARNING '[AUDIT.IF_MODIFIED_FUNC] - UDF ERROR [UNIQUE] - SQLSTATE: %, SQLERRM: %',SQLSTATE,SQLERRM;
RETURN NULL;
WHEN OTHERS THEN
RAISE WARNING '[AUDIT.IF_MODIFIED_FUNC] - UDF ERROR [OTHER] - SQLSTATE: %, SQLERRM: %',SQLSTATE,SQLERRM;
RETURN NULL;
END;
$body$
LANGUAGE plpgsql
SECURITY DEFINER
But if you observe in the above function current_query() is not coming with the mentioned language plpgsql. It throws some error. When I googled I found that in order to use current_query() function PL/CTL language must be installed. I tried to install as mentioned below. It throws an error. So kindly help me how to install PL/CTL language into my database so that current_query() function should work
-bash-3.2$ createlang -d dbname pltcl
createlang: language installation failed: ERROR: could not access file "$libdir/pltcl": No such file or directory
Okay as you suggested I created that current_query() function,but this time I got some thing like this , What i did is ,
CREATE TABLE phonebook(phone VARCHAR(32), firstname VARCHAR(32), lastname VARCHAR(32), address VARCHAR(64));
CREATE TRIGGER phonebook_auditt AFTER INSERT OR UPDATE OR DELETE ON phonebook
FOR EACH ROW EXECUTE PROCEDURE audit.if_modified_func();
INSERT INTO phonebook(phone, firstname, lastname, address) VALUES('9966888200', 'John', 'Doe', 'North America');
for testing the function i created a table named phonebook and created a trigger so that the function mentioned above audit.if_modified_func() will be executed after any insert or update or delete.the row is getting inserted but I am getting a error reg the audit.if_modified_func() function .the error is as follows
WARNING: [AUDIT.IF_MODIFIED_FUNC] - UDF ERROR [OTHER] - SQLSTATE: 42703, SQLERRM: column "*" not found in data type phonebook
Query returned successfully: 1 rows affected, 10 ms execution time.
Kindly tell me what can i do to get rid of the above error.
Not sure where you found the information about current_query and pltcl. These are unrelated. The reason why you can't find pltcl is simply because you're using too old PostgreSQL. current_query() has been added to Pg in version 8.4.
Is there any particular reason why you're using such old version? It is no longer supported, and it lacks almost 8 years of added features!
If you have to use 8.1, you might want to define:
create function current_query() returns text as '
select current_query from pg_stat_activity where procpid = pg_backend_pid();
' language sql;
But it is much better idea just to upgrade.
As for edited and added second question - it's very likely that Pg 8.1 cannot use "row.*" construct. Find who wrote the original code with the "dance comments", and ask about it. Perhaps it was meant to work in newer Pgs.