Stats gathering pl/sql syntax
Hi All:
I'm trying to write PL/SQL to conditionally either run or delete table stats (I am on 10.2.0.3):
The table name is a variable, something like that:
exec dbms_stat.delete_table_stats('MYOWNER','v_table_name');
else
exec dbms_stat.gather_table_stats(ownname=>'MYOWNER',tabname=>'v_table_name',estimate_percent=>'20', method_opt=>'for all column size SKEWONLY');
Two questions:
- what is the syntax to include the variable into the parameter list?
- is there any way to include more than 1 method_opt: ALL INDEXED and SKEWONLY
Thanks!
As 10g is already automatically gathering statistics,.why doe this at all?
Apart from that you would only need
create or replace procedure foo(p_owner in varchar2, p_table_name in varchar2, p_percent in number, p_opt in varchar2) is
begin
-- dbms_stat.delete_table_stats(p_owner,p_table_name);
dbms_stat.gather_table_stats(ownname=>p_owner,tabname=>p_table_name,estimate_percent=>p_percent, method_opt=>p_opt);
end;
exec foo('MY_OWNER' etc..
Just standard PL/SQL!
You only don't need to delete statistics. gather stats will take care of it
Sybrand Bakker
Senior Oracle DBA
Similar Messages
-
DB2 9.7 DFACT.SQL syntax error in Import ABAP phase - System Copy
Hi all. I'm trying a system copy with a source system SAP ECC 6.0 ehp4 based on NW 701 and db2 LUW 9.1 .
As it seems supported by SAP, i'm using db2 LUW 9.7 in target system.
O.S. is Windows 2008.
I got an error in phase "Import ABAP".
Sapinst.log says:
INFO 2010-02-18 10:12:14.337
An error occured and the user decided to retry the current step: "|NW_ABAP_OneHost|ind|ind|ind|ind|0|0|NW_Onehost_System|ind|ind|ind|ind|1|0|NW_CreateDBandLoad|ind|ind|ind|ind|10|0|NW_ABAP_Import_Dialog|ind|ind|ind|ind|5|0|NW_ABAP_Import|ind|ind|ind|ind|0|0|runMigrationMonitor".
INFO 2010-02-18 10:12:14.509
Switched to user: devadm.
INFO 2010-02-18 10:12:14.572
Creating file C:\Program Files\sapinst_instdir\ERPEhP4\LM\COPY\DB6\SYSTEM\CENTRAL\AS-ABAP\import_monitor.java.log.
INFO 2010-02-18 10:12:14.603
Switched to user: devadm.
INFO 2010-02-18 10:12:14.618
Working directory changed to C:\Program Files\sapinst_instdir\ERPEhP4\LM\COPY\DB6\SYSTEM\CENTRAL\AS-ABAP.
INFO 2010-02-18 10:12:14.618
Output of C:\j2sdk1.4.2_24-x64\bin\java.exe -classpath migmon.jar -showversion -Xmx1024m com.sap.inst.migmon.imp.ImportMonitor -sapinst is written to the logfile import_monitor.java.log.
WARNING 2010-02-18 10:12:44.790
Execution of the command "C:\j2sdk1.4.2_24-x64\bin\java.exe -classpath migmon.jar -showversion -Xmx1024m com.sap.inst.migmon.imp.ImportMonitor -sapinst" finished with return code 103. Output:
java version "1.4.2_24-rev"
Java(TM) Platform, Standard Edition for Business (build 1.4.2_24-rev-b06)
Java HotSpot(TM) 64-Bit Server VM (build 1.4.2_24-rev-b06, mixed mode)
Import Monitor jobs: running 1, waiting 1, completed 73, failed 0, total 75.
Loading of 'SAPDFACT' import package: ERROR
Import Monitor jobs: running 0, waiting 1, completed 73, failed 1, total 75.
WARNING[E] 2010-02-18 10:12:44.790
CJS-30022 Program 'Migration Monitor' exits with error code 103. For details see log file(s) import_monitor.java.log, import_monitor.log.
ERROR 2010-02-18 10:12:44.790
FCO-00011 The step runMigrationMonitor with step key |NW_ABAP_OneHost|ind|ind|ind|ind|0|0|NW_Onehost_System|ind|ind|ind|ind|1|0|NW_CreateDBandLoad|ind|ind|ind|ind|10|0|NW_ABAP_Import_Dialog|ind|ind|ind|ind|5|0|NW_ABAP_Import|ind|ind|ind|ind|0|0|runMigrationMonitor was executed with status ERROR .
Looking into import_monitor.java.log i found that the problem is in dfact import.
I've looked into sapdfact.log and i found:
S:\usr\sap\DEV\SYS\exe\uc\NTAMD64\R3load.exe: START OF LOG: 20100218105045
S:\usr\sap\DEV\SYS\exe\uc\NTAMD64\R3load.exe: sccsid @(#) $Id: //bas/701_REL/src/R3ld/R3load/R3ldmain.c#8 $ SAP
S:\usr\sap\DEV\SYS\exe\uc\NTAMD64\R3load.exe: version R7.01/V1.4 [UNICODE]
Compiled Jan 28 2010 20:22:25
S:\usr\sap\DEV\SYS\exe\uc\NTAMD64\R3load.exe -i SAPDFACT.cmd -dbcodepage 4103 -l SAPDFACT.log -stop_on_error -loadprocedure fast LOAD:COMPRESS_ALL
(DB) INFO: connected to DB
(DB6) INFO: COMPRESS YES is set during table creation.
(DB6) DB2 9.5 automatic dictionary creation does not require an explicit REORG.
(DB6) Compression threshold is ignored.
(GSI) INFO: dbname = "DEV "
(GSI) INFO: vname = "DB6 "
(GSI) INFO: hostname = "UNKNOWN "
(GSI) INFO: sysname = "Windows NT"
(GSI) INFO: nodename = "SRVSAPDEV"
(GSI) INFO: release = "6.0"
(GSI) INFO: version = "6002 Service Pack 2"
(GSI) INFO: machine = "4x AMD64 Level 6 (Mod 26 Step 5)"
(DB) ERROR: DDL statement failed with SQL error
( ALTER TABLE "/BI0/E0PPM_VC1" DROP PRIMARY KEY )
(SQL error -539)
error message returned by dsql:
SQL0539N Table or nickname "SAPDEV./BI0/E0PPM_VC1" does not have a "PRIMARY" key. SQLSTATE=42888
(IMP) INFO: a failed DROP attempt is not necessarily a problem
(DB6) INFO: executing DDL statements for object /BI0/E0PPM_VC1 from external SQL file.
(DB) ERROR: DDL statement failed with SQL error
( CREATE TYPE 2 UNIQUE INDEX "/BI0/E0PPM_VC1~0" ON "/BI0/E0PPM_VC1" ("KEY_0PPM_VC1T" , "KEY_0PPM_VC11" , "KEY_0PPM_VC1U" , "KEY_0PPM_VC1P" ) USING STOGROUP ___FAI PRIQTY 16 SECQTY 10240 FREEPAGE 0 PCTFREE 0 GBPCACHE CHANGED DEFINE NO BUFFERPOOL BP3 COPY NO PIECESIZE 2097152 K CLUSTER NOT PADDED )
(SQL error -7)
error message returned by dsql:
SQL0007N The character "_" following "" ) USING STOGROUP" is not valid. SQLSTATE=42601
(DB) INFO: disconnected from DB
S:\usr\sap\DEV\SYS\exe\uc\NTAMD64\R3load.exe: job finished with 1 error(s)
S:\usr\sap\DEV\SYS\exe\uc\NTAMD64\R3load.exe: END OF LOG: 20100218105045
So as you can see it seems that there's some syntax error in dfacl.log. The wrong SQL statement referred by sapdfact.log is
ind: /BI0/E0PPM_VC1~0
sql: CREATE TYPE 2 UNIQUE INDEX "/BI0/E0PPM_VC1~0" ON "/BI0/E0PPM_VC1"
("KEY_0PPM_VC1T" ,
"KEY_0PPM_VC11" ,
"KEY_0PPM_VC1U" ,
"KEY_0PPM_VC1P" )
USING STOGROUP ___FAI PRIQTY 16
SECQTY 10240 FREEPAGE 0 PCTFREE 0
GBPCACHE CHANGED DEFINE NO
BUFFERPOOL BP3 COPY NO
PIECESIZE 2097152 K CLUSTER NOT PADDED ;
|
ALTER TABLE "/BI0/E0PPM_VC1"
ADD PRIMARY KEY ("KEY_0PPM_VC1T",
"KEY_0PPM_VC11",
"KEY_0PPM_VC1U",
"KEY_0PPM_VC1P") ;
Am i missing something?
Data in referred tables (infocubes) isn't really important.
Is there a safe way to proceed?
Thanks in advance.
Regards
Simone ZaffalonAnd this is the strange point: my source system is not a BI and my dataclasses .SQL files are not empty.
Me too i would expect that the files should be empty but instead they are full of object definitions.
For example i have APPL0.SQL that contains a list of all tables of ECC system, for example
tab: MAMT
sql: CREATE TABLE "MAMT"
("MANDT" SAPDB6VARCHAR(000003)
DEFAULT '000' NOT NULL,
"MATNR" SAPDB6VARCHAR(000018)
DEFAULT ' ' NOT NULL,
"SPRAS" SAPDB6VARCHAR(000001)
DEFAULT ' ' NOT NULL,
"MEINH" SAPDB6VARCHAR(000003)
DEFAULT ' ' NOT NULL,
"MTXID" SAPDB6VARCHAR(000002)
DEFAULT ' ' NOT NULL,
"LFDNR" SAPDB6VARCHAR(000002)
DEFAULT '00' NOT NULL,
"MAKTM" SAPDB6VARCHAR(000040)
DEFAULT ' ' NOT NULL)
IN "&location&"
INDEX IN "&locationI&"
LONG IN "&locationL&"
COMPRESS YES;
ALTER TABLE "MAMT" LOCKSIZE ROW;
and like this for all others tables.
What would occur if i launch an import with such .SQL files?
(shuld i put this question to another thread or is fine for you to answer on this?)
Thank you again.
Simone Zaffalon -
Case statement in advanced sql
how to use case statement in advanced sql.Example if quarter=1 i need to select jan,fev,and march months from table
this is the case statement i am using :
case when 1=@{quarter} then substring(cast((etxnmis.month_year) as char) from 5 for 2) IN ('03', '04', '05') else null end
and i get the below error
: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <IN>: Syntax error [nQSError: 26012] . (HY000) -
SQL Developer 1.1.0.21: Issues with Data Grid and SQL syntax checking
In this new release of SQL Dev, when I execute a SQL in the SQL Worksheet and click in the Data Grid in the Results tab and try to navigate within a record using arrow keys, the grid cell enters into edit mode by default and so I cannot use the Left or Right arrow keys to navigate the grid. I am forced to use tab key to navigate. This is counter intuitive in my opinion.
Is there any option to change this behavior?
Another issue that I have come across is with SQL syntax checking. In some cases, when I press F9 to execute a SQL, it shows the SQL as executed i.e. shows something like 0.0134 seconds in the toolbar and no results displayed. In reality, the SQL had some syntax error which were NOT reported. This can be frustrating since now I have to fall back to SQL*Plus or TOAD just for syntax check.
I like the fact that SQLDev highlights the current SQL but it would be more useful if it just indicated the first line of the current sql instead of highlighting the whole sql.
Manish"In this new release of SQL Dev, when I execute a SQL in the SQL Worksheet and click in the Data Grid in the Results tab and try to navigate within a record using arrow keys, the grid cell enters into edit mode by default and so I cannot use the Left or Right arrow keys to navigate the grid. I am forced to use tab key to navigate. This is counter intuitive in my opinion."
In the "Results" tab, Click Ctrl & Tab keys (at the same time) or with mouse click on any cell other than the first column (a sequence or rownum), you will be able to navigate using the arrow keys.
"Another issue that I have come across is with SQL syntax checking. In some cases, when I press F9 to execute a SQL, it shows the SQL as executed i.e. shows something like 0.0134 seconds in the toolbar and no results displayed. In reality, the SQL had some syntax error which were NOT reported. This can be frustrating since now I have to fall back to SQL*Plus or TOAD just for syntax check."
The 0.0134 seconds could be the result of the most recently executed successful statement. Check the Script Output tab for errors. Use F5 (Run Script option) instead of F9.
"I like the fact that SQLDev highlights the current SQL but it would be more useful if it just indicated the first line of the current sql instead of highlighting the whole sql."
On the SQL statement (or code), Right Click -> Format SQL (or press Ctrl & B), proper formatting would help.
I use version 1.0.0.15.57 and seems to be working allright.
- Babu Rangasamy -
How to change Bulk Insert statement from MS SQL to Oracle
Hi All,
Good day, I would like to bulk insert the content of a file into Oracle db. May I know how to change the below MS SQL syntax to Oracle syntax?
Statement statement = objConnection.createStatement();
statement.execute("BULK INSERT [TBL_MERCHANT] FROM '" MERCHANT_FILE_DIR "' WITH ( FIELDTERMINATOR = '~~', ROWTERMINATOR = '##' )");
Thanks in advance.
cs.Oracle SQL Loader utility allows you to insert data from flat file to database tables.
Go to SQL Loader links on following url to learn more on this utility
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/server.920/a96652/toc.htm
Chandar -
After updating our ODBC driver to match our current Unidata database version (7.1), we now get the following message from Crystal Reports 2011 on many of our existing reports:
"Failed to retrieve data from the database. Details: 37000:[Rocket U2][U2ODBC][1401249]Error ID: 21 Severity: ERROR Facility: DBCAPERR - SQL Syntax error. [Database Vendor Code: 5365440]
The generated SQL statement follows:
SELECT "INVCDETH_NF"."ITEM_NBR", "ITEMMAST_NF"."ITEM_DESC", "INVCDETH_NF"."SHIPPED_QUANTITY", "INVCDETH_NF"."Z_INV_DATE", "INVCDETH_NF"."Z_COMPANY", "INVCHDRH_NF"."INVOICE_TYPE", "INVCDETH_NF"."EXTENDED_PRICE", "INVCDETH_NF"."COST_OF_SALES", "INVCDETH_NF"."Z_PCC_CODE", "INVCDETH_NF"."DISCOUNT_AMOUNT", "INVCDETH_NF"."WAREHOUSE", "ITEMMAST_NF"."PRICE_CODE", "INVCHDRH_NF"."INVOICE_NBR", "INVCHDRH_NF"."REFERENCE_NBR"
FROM ("Administrators"."ITEMMAST_NF" "ITEMMAST_NF" INNER JOIN "Administrators"."INVCDETH_NF" "INVCDETH_NF" ON "ITEMMAST_NF"."ITEM_NBR"="INVCDETH_NF"."ITEM_NBR") INNER JOIN "Administrators"."INVCHDRH_NF" "INVCHDRH_NF" ON ((("INVCDETH_NF"."INVOICE_NBR"="INVCHDRH_NF"."INVOICE_NBR") AND ("INVCDETH_NF"."INV_HEADER_ID"="INVCHDRH_NF"."INV_HEADER_ID")) AND ("INVCDETH_NF"."REFERENCE_NBR"="INVCHDRH_NF"."REFERENCE_NBR")) AND ("INVCDETH_NF"."RELEASE_NBR"="INVCHDRH_NF"."RELEASE_NBR")
WHERE "INVCDETH_NF"."Z_COMPANY"='01' AND "INVCDETH_NF"."WAREHOUSE"='086' AND ("INVCDETH_NF"."Z_INV_DATE">={d '2013-12-08'} AND "INVCDETH_NF"."Z_INV_DATE"<={d '2013-12-26'})
ORDER BY "INVCDETH_NF"."WAREHOUSE"
I downloaded the trial version of CR2013 and get the same result. Can anyone shed any light? Thanks!Yes, in that the query is what Crystal generated from the report being built in the designer. I simply copied it from the Database > Show SQL Query screen. Since the error I'm receiving is a SQL Syntax Error, I thought it would be appropriate to show it.
The bottom line is that because I am not very knowledgeable in SQL, I can't look at the query and identify the error. However, I am responsible for supporting CR in-house. Naturally, I have reported this to Rocket (the makers of the ODBC driver) but haven't received their reply yet. -
I have temp table inside my stored procedure:
CREATE TABLE #tmpOrders(product_id VARCHAR(20))
SELECT * FROM #tmpOrders o INNER JOIN dbo.products p ON o.productID=p.productID
o.productID column doesn't exists. The join should be:
ON o.product_id=p.productID
But when I create procedure, parser doesn't raise an error. The error is raised at run time.
Is there some option to check the SQL syntax before run time - to parse also temp table names?
Thanks,
SimonHi Simon
See my latest replay... I create a temporary table and then run CREATE PROCEDURE script to get the error, that was a mistake
CREATE TABLE #t (c int)
CREATE PROCEDURE sp1
AS
CREATE TABLE #t (c int)
SELECT * FROM #t JOIN sys.objects o on #t.c1=o.object_id
Msg 207, Level 16, State 1, Procedure sp1, Line 6
Invalid column name 'c1'.
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How to create nested CASE statements in PL/SQL
Can anyone please tell how to create Nested CASE statements in PL/SQL with proper syntax?
It would be better if you can help with an example.
Thank you!Something like this:
SQL> set serveroutput on
SQL> declare
2 v1 number := 2;
3 v2 varchar2(1) := 'C';
4 begin
5 case v1
6 when 1 then dbms_output.put_line('First');
7 when 2 then begin
8 case v2
9 when 'A' then dbms_output.put_line('Found A');
10 when 'B' then dbms_output.put_line('Found B');
11 when 'C' then dbms_output.put_line('Found C');
12 else dbms_output.put_line('NONE');
13 end case;
14 end;
15 else dbms_output.put_line('Else');
16 end case;
17 end;
18 /
Found C
PL/SQL procedure successfully completed
SQL> If you have further doubts regarding syntax you can read the docs on the Case statement here:
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/case_statement.htm -
Multiple SQL statements in dynamic SQL
Hello experts,
is there a possibility in Oracle (in sybase and ms sql there is one) to place in dynamic query several SQL (e.g. SELECT) statements and to execute them additionally?
Example:
v_sqlQuery :='
SELECT column_1
FROM table_a
SELECT column_1
FROM table_b'
open cv_1 for to_char(v_sqlQuery);
or
v_sqlQuery='
SELECT x, y INTO #temp_table FROM table_x
SELECT y FROM #temp_table';
Thank you in advance!
antonHi cth,
not in pl block, but within dynamic query. An example what I want to do:
What is actually need to be done is
1)to read and count all IDs into temporary table doc_id_count.
2)to read and count all IDs and marital_fields into table status_presel
3) to match data using their ids
Ouput would be like:
v_doc_id married single widowed
Miller 2 3 4
I think the idea is becomming more clear - to write data in temporal table and then read them in the next SELECT statement by matching the IDs.
Comment: I am using a wrong syntax (T-SQL syntax) for coping into temporary tables.
v_counter := '
SELECT
NAMES.' || v_doc_id || '
,Count(*) Count
INTO #doc_id_count
FROM
NAMES
GROUP BY
....-- group by v_doc_id
v_status_pre := '
SELECT
NAMES.' || v_doc_id || '
,NAMES.'|| v_marital_field || ' status_field
,COUNT(*) Count
INTO #status_presel
FROM
NAMES
GROUP BY
... -- group by v_doc_id and v_marital_field
ORDER BY
v_status := '
SELECT
#doc_id_count.' || v_doc_id || '
,#status_presel.Count married
,status_1.Count single
,status_pre2.Count widowed
FROM
#doc_id_count
LEFT OUTER JOIN #status_presel
ON ...
AND #status_presel.status_field = ''married''
LEFT OUTER JOIN #status_presel status_1
ON ...
AND status_1.status_field = ''single''
LEFT OUTER JOIN #status_presel status_2
ON ...
AND status_2.status_field = ''widowed''
ORDER BY
v_sql := v_counter + v_status_pre + v_status;
open cv_1 for to_char(v_sqlQuery); -
Multiple SQL statements in Init SQL in WLS 8.1
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do I seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxMahendra wrote:
Thanks Joe.
Following worked for Oracle 8.1.7Good news.
but did not for 8.0.6
SQL BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''MM/DD/YYYY''';
EXECUTE IMMEDIATE 'SET ROLE xxx identified xxx'; end;
Do you know 8.0.6 syntax ?You might try asking oracle, but note that no one is supporting that old version
of Oracle any longer...
Joe
>
Mahendra
Joe Weinstein <[email protected]> wrote:
Hi.
I found the syntax, I think. Try this:
BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = 'MM/DD/YYYY'';
EXECUTE IMMEDIATE 'SET ROLE <<role name>> identified
by <<pwd>>';END;
Joe
Mahendra wrote:
Still getting following exception.
<Feb 19, 2004 1:47:58 PM EST>
<Warning>
<JDBC> <BEA-001164>
<Unable to initialize connection in pool "XXXX".
Initialization
SQL = "BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole xxxx_role
identified by
xxxx; END;".
Received exception: "java.sql.SQLException: ORA-06550: line 1,column7:
PLS-00103: Encountered the symbol "ALTER" when expecting one of thefollowing:
begin declare exit for goto if loop mod null pragma raise
return select update while <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql commit <a single-quoted SQL string>
The symbol "update was inserted before "ALTER" to continue.
ORA-06550: line 1, column 61:
PLS-00103: Encountered the symbol "ROLE" when expecting one of thefollowing:
transaction
".>
<Feb 19, 2004 1:47:59 PM EST> <Notice> <WebLogicServer> <BEA-000355><Thread "Li
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
Thanks for reply, but that did not worked.
Get following exception
Unable to initialize connection pool "POOL_NAME".
Initialization SQL = "Select count(*) from ""SQL BEGIN alter sessionset nls_date_format
= 'MM/DD/YYYY'; set role xxx_role identified by xxxx; END;"". Receivedexception:
"java.sql.SQLException: ORA-00972: identifier is too long
Since we have not given SQL before that statement, BEA is treating
statment "SQL Begin ....." as a table name.
Then I tried by putting SQL out side quotes, like SQL "Begin .....end;" but the
same error.
Is there any way around it ?
MahendraHi. The full string you should enter into the console when you define
the
initSQL parameter is:
SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; set role
xxx_role identified by xxxx; END;
Let me know...
Joe
Joe Weinstein <[email protected]> wrote:
Mahendra wrote:
How to seperate multiple SQL statements in Init SQL text box ?
For example, I want to enter following two SQL statements. How do
I
seperate them.
I tested with / and ; as seperator, but did not worked..
alter session set nls_date_format = 'MM/DD/YYYY'
set role xxx_role identified by xxxxThis will always be DBMS-specific. If this is for oracle, you can
try:
"SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole
xxx_role identified by xxxx; END;"
Joe -
Ok, I'm sure this is a very simple problem but I'm confused.
Statement s = con.createStatement();
s.execute("SELECT COUNT (*) FROM table WHERE id = 6 AND somechar = 'N'");java.sql.SQLException: Syntax error or access violation message from server: "You have an error in y
our SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax
to use near '(*) FROM table WHERE id = 6 AND somechar = 'N'' at line 1"
This works fine when input into the phpMyAdmin database interface. Is there something blatantly wrong with my syntax, or...?Maybe it doesn't like the space between COUNT and (*)
%Yuck.
Yep, that was it. Thanks.
Weird, I'm accustomed to programs ignoring most whitespace as long as it doesn't create ambiguity. -
SQL syntax error when creating record insertion form
Good day,
I was hoping someone could help me. I am trying to create a record insertion form on a website to insert data into a database table. When attempting to create the form, I am getting the following error:
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 ' Organization, Office, Department, Phone, EmailAddress, JobTitle, `OfficialMaili' at line 1
Not sure what is going on. I am running windows 8 and DW cs5 w/ MYSQL. I am testing on a local server prior to pushing to the remote server.
Thank you for your assistance and please advise any code you would like me to send.Here is all the code from this particular webpage. I apologize, I am too stupid to realize which parts are SQL vice PHP vice HTML:
<?php require_once('Connections/group4.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO individual (Grade, LastName, FirstName, M.I., Organization, Office, Department, Phone, EmailAddress, JobTitle, `OfficialMailing Address`, Citizenship, Designation, IATrainingComplete, IADate) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Grade'], "text"),
GetSQLValueString($_POST['LastName'], "text"),
GetSQLValueString($_POST['FirstName'], "text"),
GetSQLValueString($_POST['MI'], "text"),
GetSQLValueString($_POST['Organization'], "text"),
GetSQLValueString($_POST['Office'], "text"),
GetSQLValueString($_POST['Department'], "text"),
GetSQLValueString($_POST['Phone'], "double"),
GetSQLValueString($_POST['EmailAddress'], "text"),
GetSQLValueString($_POST['JobTitle'], "text"),
GetSQLValueString($_POST['OfficialMailing_Address'], "text"),
GetSQLValueString($_POST['Citizenship'], "text"),
GetSQLValueString($_POST['Designation'], "text"),
GetSQLValueString($_POST['IATrainingComplete'], "text"),
GetSQLValueString($_POST['IADate'], "text"));
mysql_select_db($database_group4, $group4);
$Result1 = mysql_query($insertSQL, $group4) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $insertGoTo));
mysql_select_db($database_group4, $group4);
$query_rsIndividual = "SELECT * FROM individual ORDER BY IndividualNumber ASC";
$rsIndividual = mysql_query($query_rsIndividual, $group4) or die(mysql_error());
$row_rsIndividual = mysql_fetch_assoc($rsIndividual);
$totalRows_rsIndividual = mysql_num_rows($rsIndividual);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Us</title>
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.header {
font-size: 36px;
text-decoration: underline;
.quote {
font-size: 18px;
font-style: italic;
.tablethisone {
margin: 5px;
padding: 25px;
border: medium none #000;
text-align: center;
</style>
</head>
<body>
<p><img src="Images/EGA.png" width="227" height="222" alt="EGA" /><span class="header">SAAR Tracking System
</span></p>
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a href="index.php">Home</a> </li>
<li><a href="search.php">Search</a></li>
<li><a href="contact.php">Contact Us</a> </li>
</ul>
<p> </p>
<p>PRIVACY ACT STATEMENT</p>
<p>Executive Order 10450, 9397; and Public Law 99-474, the Computer Fraud and Abuse Act.
To record names, signatures, and other identifiers for the purpose of validating the trustworthiness of individuals requesting
access to Department of Defense (DoD) systems and information. NOTE: Records may be maintained in both electronic
and/or paper form.</p>
<p> </p>
<p> </p>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Grade:</td>
<td><input type="text" name="Grade" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">LastName:</td>
<td><input type="text" name="LastName" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">FirstName:</td>
<td><input type="text" name="FirstName" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">M.I.:</td>
<td><input type="text" name="MI" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Organization:</td>
<td><input type="text" name="Organization" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Office:</td>
<td><input type="text" name="Office" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Department:</td>
<td><input type="text" name="Department" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Phone:</td>
<td><input type="text" name="Phone" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">EmailAddress:</td>
<td><input type="text" name="EmailAddress" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">JobTitle:</td>
<td><input type="text" name="JobTitle" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">OfficialMailing Address:</td>
<td><input type="text" name="OfficialMailing_Address" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Citizenship:</td>
<td><input type="text" name="Citizenship" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Designation:</td>
<td><input type="text" name="Designation" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">IATrainingComplete:</td>
<td><input type="text" name="IATrainingComplete" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">IADate:</td>
<td><input type="text" name="IADate" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Disclosure of this information is voluntary; however, failure to provide the requested information may impede, delay or
prevent further processing of this request.</p>
<p class="quote">"Be polite, be professional, but have a plan to kill everybody you meet" General James Mattis</p>
<p> </p>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>
<?php
mysql_free_result($rsIndividual);
?> -
in Sybase/SQL server, you can do conditional compound SQL like following:
begin transaction
begin
insert into blah values ("blah")
if(@@rowcount>0)
begin
update blah set blah = "blah" where blah = "blah"
end
end
commit transaction;Does anyone know to do that in DB2 SQL syntax?
Thanks alot.Your question has nothing to do with Java, and I don't really understand it.
If you are talking about Subqueries, then all you need to use is brackets grouping different parts of the statement. -
Automatic stats gathering job log
Hi
we are auto stats gathering feature in ORACLE 10g.I want to know the following information Reg this.
For last one week,Start time and end time of this Job and any errors while gathering jobs.Where can i find this info
Thanks,
pramodYou can check from the following table
SQL> desc DBA_SCHEDULER_JOBS;
Name Null? Type
OWNER NOT NULL VARCHAR2(30)
JOB_NAME NOT NULL VARCHAR2(30)
JOB_SUBNAME VARCHAR2(30)
JOB_CREATOR VARCHAR2(30)
CLIENT_ID VARCHAR2(64)
GLOBAL_UID VARCHAR2(32)
PROGRAM_OWNER VARCHAR2(4000)
PROGRAM_NAME VARCHAR2(4000)
JOB_TYPE VARCHAR2(16)
JOB_ACTION VARCHAR2(4000)
NUMBER_OF_ARGUMENTS NUMBER
SCHEDULE_OWNER VARCHAR2(4000)
SCHEDULE_NAME VARCHAR2(4000)
SCHEDULE_TYPE VARCHAR2(12)
START_DATE UNDEFINED
REPEAT_INTERVAL VARCHAR2(4000)
EVENT_QUEUE_OWNER VARCHAR2(30)
EVENT_QUEUE_NAME VARCHAR2(30)
EVENT_QUEUE_AGENT VARCHAR2(30)
EVENT_CONDITION VARCHAR2(4000)
EVENT_RULE VARCHAR2(65)
END_DATE UNDEFINED
JOB_CLASS VARCHAR2(30)
ENABLED VARCHAR2(5)
AUTO_DROP VARCHAR2(5)
RESTARTABLE VARCHAR2(5)
STATE VARCHAR2(15)
JOB_PRIORITY NUMBER
RUN_COUNT NUMBER
MAX_RUNS NUMBER
FAILURE_COUNT NUMBER
MAX_FAILURES NUMBER
RETRY_COUNT NUMBER
LAST_START_DATE UNDEFINED
LAST_RUN_DURATION UNDEFINED
NEXT_RUN_DATE UNDEFINED
SCHEDULE_LIMIT UNDEFINED
MAX_RUN_DURATION UNDEFINED
LOGGING_LEVEL VARCHAR2(4)
STOP_ON_WINDOW_CLOSE VARCHAR2(5)
INSTANCE_STICKINESS VARCHAR2(5)
RAISE_EVENTS VARCHAR2(4000)
SYSTEM VARCHAR2(5)
JOB_WEIGHT NUMBER
NLS_ENV VARCHAR2(4000)
SOURCE VARCHAR2(128)
DESTINATION VARCHAR2(128)
COMMENTS VARCHAR2(240)
FLAGS NUMBER -
Can someone kindly tell me the correct syntax for this statement?
String sql = "UPDATE answers SET q1 = '" + value + "'" + "WHERE EXISTS (SELECT * FROM users u, answers a WHERE u.username = a.username)";
int numRows = stmt.executeUpdate(sql);
The error I am getting is:
Caught SQL Exception: java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near 'EXISTS SELECT * FROM users u, answers a WHERE u.username = a.username' at line 1I am using a cookie instead. But, when I use an update, my values are the same for each column, not the appropriate values. Is my syntax below correct?
String delete = request.getParameter("delete");
String question = request.getParameter("question");
String value = request.getParameter("R");
Cookie[] cookies = request.getCookies();
if (delete.equals("no") && !value.equals(""))
if(cookies != null)
for (int i = 0; i < cookies.length; i++)
String name = cookies.getName();
String valuecook = cookies[i].getValue();
//Cookie getUser = new Cookie(name, valuecook);
String sql = "UPDATE answers SET q1 ='" + value + "' " + "WHERE USERNAME = '" + valuecook + "'";
int numRows = stmt.executeUpdate(sql);
String sql2 = "UPDATE answers SET q2 ='" + value + "' " + "WHERE USERNAME = '" + valuecook + "'";
int numRows2 = stmt.executeUpdate(sql2);
String sql3 = "UPDATE answers SET q3 ='" + value + "' " + "WHERE USERNAME = '" + valuecook + "'";
int numRows3 = stmt.executeUpdate(sql3);
out.println(value);
out.println(valuecook);
// UPDATE table_name SET column_name1 = value1 [, column_name2 = value2, etc.] WHERE criteria
out.println("Record has been inserted");
String nextPage = request.getParameter("nextPage");
Maybe you are looking for
-
Hello: I am trying to get a text input field to perform a function. I have a training animation and I want the learner to input the correct password in a text field. if the text is correct I would like a gotoAndPlay nextscene function to occur. any s
-
Mapping parametrized table's name
We have some similar parallel flows that have in input tables with identical structure but different names (like: anag704, anag768, anag763). Can we use one mapping and one flow in Warehouse Builder using parameters?
-
How do I fix this?
-
How to add new table into running extract pump and replicat files
Hi all, i am very much confused how we should add a new table for replication into extract pump and replicat parameter files without stopping them manually? Is there any way where we can add them without disturbing functionality of OGG? Experts help
-
Import folder and automatically create a playlist
I've have a folder which contains about 100 songs. I want to import this folder into iTunes and also have iTunes create a playlist for me at the same time I import. Is this possible? I didn't want all the songs to get imported into the Music Library