Help in SQL or PL/SQL
Hi,
I have the following data:
CREATE TABLE My_table
DEPART VARCHAR2(5 BYTE),
ARRIVED VARCHAR2(9 BYTE),
CODE_SEC VARCHAR2(2 BYTE),
FIRST_SEC VARCHAR2(8 BYTE),
LAST_SEC VARCHAR2(8 BYTE),
ESTIMATE VARCHAR2(3 BYTE)
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A1','Paris','Lille','50');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A1','Nantes','Bordeaux','40');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A1','Bordeaux','Toulouse','25');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A2','Paris','Lille','50');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A2','Lille','Lyon','80');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A2','Lyon','Agen','100');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A2','Lyon','Paris','55');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A3','Paris','Lille','50');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A3','Troyes','Dax','30');
Insert into My_table (DEPART,ARRIVED,CODE_SEC,FIRST_SEC,LAST_SEC,ESTIMATE) values ('Paris','Marseille','A3','Bordeaux','Toulouse','25');
Depart Arrived code_Sec First_Sec Last_Sec Estimate
Paris Marseille A1 Paris Lille 50
Paris Marseille A1 Nantes Bordeaux 40
Paris Marseille A1 Bordeaux Toulouse 25
Paris Marseille A2 Paris Lille 50
Paris Marseille A2 Lille Lyon 80
Paris Marseille A2 Lyon Agen 100
Paris Marseille A2 Lyon Paris 55
Paris Marseille A3 Paris Lille 50
Paris Marseille A3 Troyes Dax 30
Paris Marseille A3 Bordeaux Toulouse 25
and I'd like to make the following calculation on these data:
Add estimate for the Paris-Marseille, whatever the section, so that each pair (First_Sec, Last_Sec) is counted only once. for information, there may be other routes.
in this example dssus: the total score must send:
50 +40 +25 +80 +100 +55 +30 = 380
Thank you in advance for your help.
may be try this...
WITH t AS
(SELECT ROW_NUMBER () OVER (PARTITION BY first_sec, last_sec ORDER BY ESTIMATE)
rn,
depart, arrived, code_sec, ESTIMATE, first_sec, last_sec
FROM my_table)
SELECT depart, arrived, code_sec, MAX (sm_estimate) OVER (PARTITION BY NULL)
FROM (SELECT depart, arrived, code_sec, ESTIMATE,
SUM (CASE
WHEN rn = 1
THEN TO_NUMBER (ESTIMATE)
ELSE 0
END) OVER (PARTITION BY rn) sm_estimate
FROM t)
Similar Messages
-
Help required in writing an sql to fetch the the difference of the data.
Hi Gurus,
Could some one help me in writing an sql to pull data the difference between two same structured tables from two different database and to store that data in an temperory table.
many many thanks in advanceLets say you have two db SOURCE and DEST
SOURCE is the DB that you have Logged in into. Now you do the following.
1. Createa DBLink to DEST database.
2. Check if the DBLink works properly.
3. Then execute the following sql.
select <column_list> from <table_name>
minus
select <column_list> from <table_name>@<dblink>
union all
select <column_list> from <table_name>@<dblink>
minus
select <column_list> from <table_name> -
Help with translating SQL query from SQL Server syntax to Oracle syntax
Hi,
is it someone that can help me translate following SQL query from SQL Server syntax to Oracle syntax.
SELECT ID,
[LMT(MTR)] = MAX(case when TYPE = 'LMT' then VALUE end),
[AAD(KGM)] = MAX(case when TYPE = 'AAD' then VALUE end),
[VOL(MTQ)] = MAX(case when TYPE = 'VOL' then VALUE end)
FROM yourtable
GROUP BY ID
Your help is highly appreciated, thanks in advance.Like this,
SELECT ID,
MAX(case when TYPE = 'LMT' then VALUE end) LMT_MTR,
MAX(case when TYPE = 'AAD' then VALUE end) AAD_KGM ,
MAX(case when TYPE = 'VOL' then VALUE end) VOL_MTQ
FROM yourtable
GROUP BY ID-Arun -
Please help me in writing the SQL
Hi,
I am new to oracle.. Can you please help me in writing a SQL
I have a table which has the following columns
Start_date m1 ---- Start month of each quarter (Jan,Apr,Jul,oct)
end_date m3---- End month of each quarter
m1_start_date,
m1_end_date,
m2_start_date,
m2_end_date,
m3_start_date,
m3_end_date,
M1_act_rev,
m2_act_rev,
m3_act_rev
If a user selects the dates from Jan,2011 to Jun, 2011
I should get the aggregate of the revenues (m1+m2+m3+m1+m2+m3)Hi Gurus,
Will this work
select
b.DISTRICT_NAME,
count(c.CONTRACT_NUMBER),
sum(C.M1_ACT_REV),
sum(C.M2_ACT_REV),
sum(C.M3_ACT_REV),
sum(C.M1_EXP_PRICE),
sum(C.M2_EXP_PRICE),
sum(C.M3_EXP_PRICE)
from
clm_mn_compliance_data c,
CLM_MN_CUSTOMER_ALIGNMENT_DATA b
where
((m1_start_date between '01-01-2011' and '03-31-2011' ) and (m1_end_date between '01-01-2011' and '03-31-2011')) or
((m2_start_date between '01-01-2011' and '03-31-2011' ) and (m3_end_date between '01-01-2011' and '03-31-2011')) or
((m3_start_date between '01-01-2011' and '03-31-2011' ) and (m3_end_date between '01-01-2011' and '03-31-2011')) and
b.CUSTOMER_ID = C.CUST_CTRT_ID
group by
B.DISTRICT_NAME; -
Help!!!: catalog.sql and catproc.sql damage my db
after running the file my.sql (see below), i encounter some error:
when i try to edit the table data, the following error displayed:
ORA-04045 ... SYS.DBMS_OUTPUT
ORA-06508 ...
ORA-06512 ...
ORA-06508 ...
ORA-06512 ...
then i go to the package SYS.DBMS_OUTPUT, the status is "invalid", i try to recompile it, the following error displayed:
ORA-04045 ... SYS.CDC_ALTER_CTABLE_BEFORE
ORA-06508 ...
ORA-06512 ...
ORA-06508 ...
ORA-06512 ...
my db works well before running the file my.sql. it seems the execution of catalog.sql and catproc.sql cause the error. i am using 9i, and the document histories show that the catalog.sql and catproc.sql are last updated in Apr,2001.
my questions are:
1.with 9i db, do i need to run the two files?
2.how can i recover my db?(i don't have backup, can i use redoXX.log?)
***my.sql***
connect sys/change_on_install@orcl as sysdba
@/opt/oracle/rdbms/admin/catalog.sql
connect sys/change_on_install@orcl as sysdba
CREATE database mydb
@/opt/oracle/rdbms/admin/catproc.sql
***my.sql***how can i get my db work properly just as it was?
what do you mean by "create database script"?
Database configuration assistant allows you to create the database template and then save it as a set of scripts that you
can later customize and run to create the database. If you created your "create database scripts" using this option then
these scripts automatically run the catproc.sql and catalog.sql scripts along with several other scripts.
If you use Database configuration assistant to create such a set of DB creation scripts, than look at the
CreateDBCatalog.sql script, as you can see it runs both the scripts. so, if you do it this way, you do not need to do any
extra steps (apart from your custom scripts that may be part of your post install steps).
A sample of such DB creation script will be as below (for your reference):
===================================================================
connect SYS/change_on_install as SYSDBA
set echo on
spool /home/oracle/Ora9i/assistants/dbca/logs/CreateDBCatalog.log
@/home/oracle/Ora9i/rdbms/admin/catalog.sql;
@/home/oracle/Ora9i/rdbms/admin/catexp7.sql;
@/home/oracle/Ora9i/rdbms/admin/catblock.sql;
@/home/oracle/Ora9i/rdbms/admin/catproc.sql;
@/home/oracle/Ora9i/rdbms/admin/catoctk.sql;
@/home/oracle/Ora9i/rdbms/admin/owminst.plb;
connect SYSTEM/manager
@/home/oracle/Ora9i/sqlplus/admin/pupbld.sql;
connect SYSTEM/manager
set echo on
spool /home/oracle/Ora9i/assistants/dbca/logs/sqlPlusHelp.log
@/home/oracle/Ora9i/sqlplus/admin/help/hlpbld.sql helpus.sql;
spool off
spool off
exit;
=========================================================================== -
Help on - convert ansi sql to oracle sql
hi gurus,
i'm try'g to convert ansi sql to oracle sql.
but i'm getting an error. can u please let me know, if i can convert it or is it better to use ansi sql!
original code in ansi format::
select distinct bfc.NBR_SEQ, bfc.IDN_ENTITY, bfc.CDE_TYPE_ENTITY, n.CDE_STATUS,
gec.idn_group as idn_parent_id, bfc.IDN_FUNC_BUSS,
case when bfc.CDE_TYPE_ENTITY = 'P' OR bfc.CDE_TYPE_ENTITY = 'A' then
PKG_FW_NVGTR.GET_NAM_PAGE(bfc.IDN_ENTITY)
else
PKG_FW_NVGTR.GET_NAM_GROUP(bfc.IDN_ENTITY)
end as ENTITY_NAM,
p.Category, p.Display_Txt, p.show_in_nav, p.page_uri
from
T_BUSS_FUNC_ENTITY_CREF bfc
inner join t_buss_func bf on bfc.idn_func_buss = bf.idn_func_buss
inner join t_entity_prog_cref epc on bfc.idn_entity = epc.idn_entity and bfc.cde_type_entity = epc.cde_type_entity
left outer join t_page p on bfc.idn_entity = p.idn_page
left outer join t_group_entity_cref gec on bfc.idn_entity = gec.idn_entity and bfc.cde_type_entity = gec.cde_type_entity
left outer join t_nvgtr n on bfc.idn_entity = n.idn_entity and bfc.cde_type_entity = n.cde_type_entity
where
BF.nam_func_buss = 'CP' AND--P_NAM_FUNC_BUSS and
epc.cde_program in
( select p.cde_program from t_program p where p.nam_program in (
SELECT * FROM TABLE (CAST(PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST('LC', ',') AS TYP_ARRAY))))
order by
bfc.NBR_SEQ;tried to convert into oracle
SELECT DISTINCT bfc.NBR_SEQ,
bfc.IDN_ENTITY,
bfc.CDE_TYPE_ENTITY,
n.CDE_STATUS,
gec.idn_group as idn_parent_id,
bfc.IDN_FUNC_BUSS,
case when bfc.CDE_TYPE_ENTITY = 'P' OR bfc.CDE_TYPE_ENTITY = 'A' then
PKG_FW_NVGTR.GET_NAM_PAGE(bfc.IDN_ENTITY)
else
PKG_FW_NVGTR.GET_NAM_GROUP(bfc.IDN_ENTITY)
end as ENTITY_NAM,
p.Category,
p.Display_Txt,
p.show_in_nav,
p.page_uri
FROM T_BUSS_FUNC_ENTITY_CREF bfc,
T_BUSS_FUNC bf,
T_ENTITY_PROG_CREF epc,
T_PAGE p,
T_GROUP_ENTITY_CREF gec,
T_NVGTR n
WHERE bfc.IDN_FUNC_BUSS = bf.IDN_FUNC_BUSS
AND bfc.IDN_ENTITY = epc.IDN_ENTITY
AND bfc.CDE_TYPE_ENTITY = epc.CDE_TYPE_ENTITY
AND bfc.IDN_ENTITY(+) = p.IDN_PAGE
AND bfc.IDN_ENTITY(+) = gec.IDN_ENTITY
AND bfc.CDE_TYPE_ENTITY(+) = gec.CDE_TYPE_ENTITY
AND bfc.IDN_ENTITY(+) = n.IDN_ENTITY
AND bfc.CDE_TYPE_ENTITY(+) = n.CDE_TYPE_ENTITY
AND BF.nam_func_buss = 'CP' AND--P_NAM_FUNC_BUSS and
epc.cde_program in
( select p.cde_program from t_program p where p.nam_program in (
SELECT * FROM TABLE (CAST(PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST('LC', ',') AS TYP_ARRAY))))
order by
bfc.NBR_SEQ;error is
ORA-01417: a table may be outer joined to at most one other tableso how can i convert it?
thanksuser642856 wrote:
explain plan for this select statement
ID PID Operation Name Rows Bytes Cost CPU Cost IO Cost Temp space IN-OUT PQ Dist PStart PStop
0 SELECT STATEMENT 10M 1183M 570694 33G 567917
1 0 SORT UNIQUE 10M 1183M 287940 17G 286502 2607M
2 1 HASH JOIN 10M 1216M 179 1G 84
3 2 COLLECTION ITERATOR PICKLER FETCH PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST
4 2 HASH JOIN OUTER 2693 299K 58 34M 55
5 4 HASH JOIN OUTER 37 3959 11 24M 9
6 5 HASH JOIN OUTER 37 3663 10 18M 8
7 6 HASH JOIN 37 1147 7 12M 6
8 7 HASH JOIN 59 1180 5 6060823 4
9 8 NESTED LOOPS 2 24 3 15843 3
10 9 TABLE ACCESS BY INDEX ROWID T_BUSS_FUNC 1 6 1 8341 1
11 10 INDEX UNIQUE SCAN UK_NAM_FUNC_BUSS 1 0 1050 0
12 9 TABLE ACCESS FULL T_PROGRAM 2 12 2 7501 2
13 8 INDEX FULL SCAN PK_T_ENTITY_PROG_CREF 59 472 1 18921 1
14 7 TABLE ACCESS FULL T_BUSS_FUNC_ENTITY_CREF 37 407 2 14891 2
15 6 TABLE ACCESS FULL T_PAGE 26 1768 2 14141 2
16 5 INDEX FULL SCAN UK_UNIQUE_GROUP_DEPENDENT 26 208 1 12321 1
17 4 TABLE ACCESS FULL T_NVGTR 6986 47K 46 3179613 46 as you can see.. cpu cost is in 33G..
is there any better way?
thanksCan you run this in a session please:
ALTER SESSION set optimizer_dynamic_sampling = 4;Then run an explain plan again.
And you have a function in there - PKG_FW_NVGTR.FN_GET_ARRAY_FROM_COMMA_LIST - which isn't helping things. -
Help me clear the OCP sql and pl/sql exam
can anybody out there guide me how should i proceed with the preparation and what all should i study to clear the SQL and PL/SQL OCP exam.
thank you all in advance..Try going for the Exam Cram. The exam at the end of the book will definitely help a lot. The rest of the book might help, so just give it a try.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Nosferatu:
Hello people...
I'm taking a preparation course for the Oracle DBA certification exam. I just finished preparing for the first exam -- SQL and PL/SQL.. The book I used for the course Oracle 8i DBA Certification Exam Guide as well as TEach yourself SQL in 21 days and Teach yourself PL/SQL in 21 days...
I'd say I'm prepared to pass the exam... Before I make my first attempt, I am thinking of going through the Exam Cram for the first exam. However, judging from the reviews on amazon.com, the book doesn't seem to be helpful...
Anyone have any tips or recommendations before I take the exam? Should I go through the Exam Cram? If not, are there better books to go through for last minute preparations?
Also, how many questions on the exam and what percentage do I need to pass?
Any input would be much appreciated... Thanks for ur help!<HR></BLOCKQUOTE>
null -
Logical SQL to physical SQL in datamodel.
I am designing a report in BI publisher and for that I am creating a datamodel.
My datamodel contains 4 dataset with 4 different logical SQLs and all use source as Oracle BIEE.
When I generate/execute xml from datamodel I observed in nqquery.log that BI publisher is executing each logical SQL in sequence.
That is OBIEE first send logical SQL of one of the dataset and then convert it to physical SQL. After first physical SQL is completed then only it is converting second logical SQL to physical.
So logical to physical query is happening in sequence rather than in parallel.
My datamodel contains huge logical SQLs and OBIEE takes almost 40 seconds each to convert it physical query. This will result in total 160 seconds for just converting 4 logical SQLs to physical SQLs.
Does anybody know if there is any setting where I can manage to convert multiple logical to physical in parallel?Hi Experts,
Please help on this. -
Calling SQL function in SQL query fails
Hi There,
I am trying to execute INSERT INTO XML_DATA (NAME, DATASIZE, DATA) VALUES (?,?,XMLType('?')) using ODBC C
SQLBindParameter APIs.
If I execute the INSERT INTO XML_DATA (NAME, DATASIZE, DATA) VALUES (?,?,XMLType('<name>milind</name>')) works fine.
Can anybody please help me out here?
Thanks,
Milind
/* blob.c
* The following C code demonstrates how to read an input file, piecewise
* (in chunks), and write it into a BLOB or LONG RAW column in the database.
* It then reads that BLOB or LONG RAW data, piecewise, from the database
* and writes it back to the OS as an output file that you specify.
* Enter the following SQL statement via SQL*Plus to create the table
* 'images_data' for use with this sample. Make sure you log into
* Oracle as a user appropriate for running this example.
* For BLOB, use the following table:
* CREATE TABLE images_data (
* name VARCHAR2(100),
* imagesize NUMBER,
* image BLOB);
* For LONG RAW, use the following table:
* CREATE TABLE images_data (
* name VARCHAR2(100),
* imagesize NUMBER,
* image LONG RAW);
* Change the connection information at the beginning of the procedure OpenOra
* to your DSN, username and password.
* To run this program, open a Command Prompt and use the following syntax:
* Syntax: <program_name> <infile_name> <outfile_name>
* Example call: C:\> blob my_photo.jpg copy_of_my_photo.jpg
#include "stdafx.h"
#include <stdio.h>
#include <io.h>
#ifndef NUTC
#include <windows.h>
#endif
#include <sql.h>
#include <sqlext.h>
#ifdef NUTC
#include <sys/types.h>
#include <sys/stat.h>
#endif
* Global variables
HENV hOdbcEnv = NULL; /* Environment handle */
HDBC hDbConn = NULL; /* Connection handle */
int sr; /* Return value */
#define BUFSIZE 32020 /* Chunksize */
* Connect routine
void OpenOra()
char szDSN[] = "XY10g2"; /* Data Source Name (DSN) */
char szUID[] = "odbc1"; /* Username */
char szAUTH[] = "pdmuser"; /* Password */
* Allocate environment handle
sr = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hOdbcEnv);
if (sr != SQL_SUCCESS)
printf ("Error allocating environment handle\n");
* Set the ODBC Version
sr = SQLSetEnvAttr(hOdbcEnv, SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
if (sr != SQL_SUCCESS)
printf ("Error setting ODBC version\n");
* Allocate connection handle
sr = SQLAllocHandle (SQL_HANDLE_DBC, hOdbcEnv, &hDbConn);
if (sr != SQL_SUCCESS)
printf ("Error allocating connection handle\n");
* Connect
sr = SQLConnect(hDbConn, (UCHAR *)szDSN, SQL_NTS,(UCHAR *)szUID, SQL_NTS, (UCHAR *)szAUTH, SQL_NTS);
if (sr != SQL_SUCCESS)
printf("Connection failed\n");
* Disconnect routine
void CloseOra()
* Disconnect and free connection and environment handles
sr = SQLDisconnect(hDbConn);
if (hDbConn != SQL_NULL_HANDLE)
SQLFreeHandle(SQL_HANDLE_DBC, hDbConn);
if (hOdbcEnv != SQL_NULL_HANDLE)
SQLFreeHandle(SQL_HANDLE_ENV, hOdbcEnv);
* Read INFILE into the database and read data back out and save as OUTFILE.
void readCertImage(char read_name, long filesize, char write_name)
SQLCHAR iSqlCmd[300] = "INSERT INTO XML_DATA (NAME, DATASIZE, DATA) VALUES (?,?,XMLType('?'))";
SQLCHAR iSqlCmd1[300] = "SELECT DATA FROM XML_DATA WHERE NAME = ?";
FILE ifile, ofile; /* File pointers */
time_t startTime, endTime;
time_t startTimeIO, endTimeIO;
int IOtime = 0;
unsigned char buf[BUFSIZE]; /* Buffer to hold chunk */
unsigned char buf1[BUFSIZE]; /* Buffer to hold chunk */
SQLINTEGER type[3]; /* Type of data */
SQLPOINTER pToken; /* Which column is piecewise */
HSTMT hstmt = NULL; /* Statement handle */
long i; /* Byte Counter */
long count; /* Piecewise Counter */
long rd; /* Amount to read */
* Log on
OpenOra();
ifile = fopen(read_name, "r"); /* Open the file for reading in ASCII mode */
* Allocate statement handle
sr = SQLAllocHandle(SQL_HANDLE_STMT, hDbConn, &hstmt);
if (sr != SQL_SUCCESS)
printf("Error allocating statement handle\n");
* Prepare insert statement
sr = SQLPrepare(hstmt, iSqlCmd, SQL_NTS);
if (sr != SQL_SUCCESS)
printf("Error preparing insert statement\n");
* Bind Parameters
/* Name of BLOB */
sr = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0,read_name, strlen(read_name), &type[0]);
if (sr != SQL_SUCCESS)
printf("Error binding name variable\n");
/* Size of BLOB */
sr = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_NUMERIC, 0, 0,&filesize, 0, &type[1]);
if (sr != SQL_SUCCESS)
printf("Error binding length variable\n");
* As this will be a piecewise insert do not need to pass a buffer here.
* Instead pass the parameter number for identification purposes.
/* BLOB data */
sr = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 0, 0,(SQLPOINTER)3, 0, &type[2]);
if (sr != SQL_SUCCESS)
printf("Error binding data variable\n");
type[0] = SQL_NTS; /* Null terminated string */
type[1] = 0; /* Ignored for numbers */
type[2] = SQL_LEN_DATA_AT_EXEC(filesize); /* Data at execution time */
time( &startTime );
* Execute the insert
sr = SQLExecute(hstmt);
if (sr == SQL_NEED_DATA)
printf("\nAbout to perform piecewise insert of data\n\n");
else if (sr != SQL_SUCCESS)
printf("Error executing insert statement\n");
* Retrieve the pointer to the buffer containing the address
* of the location where the source BLOB will be sent
sr = SQLParamData(hstmt, &pToken);
if (sr != SQL_NEED_DATA)
printf("Error - no piecewise operations required\n");
* Write the data in BUFSIZE chunks
i = 0; /* Initialize bytes inserted
count = 0; /* Initialize pieces/chunks inserted */
do
count++; /* Increment chunk number */
* If remaining bytes to read is greater than BUFSIZE,
* read another BUFSIZE chunk. Otherwise, read remaining
* chunk of bytes (which will be less than BUFSIZE)
if (filesize - i >= BUFSIZE)
rd = BUFSIZE;
else
rd = (filesize - i);
printf("%5ld:%10ld - About to write %ld bytes to the database\n",count,i,rd);
* Reads one rd sized chunk of data into buffer from source file (BLOB)
time( &startTimeIO );
fread(buf, rd, 1, ifile);
time( &endTimeIO );
IOtime = IOtime + (endTimeIO - startTimeIO);
* Sends the contents of the buffer to the ODBC driver
SQLPutData(hstmt, buf, rd);
/* Recalculate total bytes sent */
if (filesize - i >= BUFSIZE)
i+= BUFSIZE;
else
i+= (filesize - i);
} while (i < filesize);
/* Check to see if all data has been sent */
sr = SQLParamData(hstmt, &pToken);
if (sr == SQL_NEED_DATA)
printf("Error - still need data\n");
printf("%5ld:%10ld - Done writing data\n",++count,i);
time( &endTime );
printf("BLOB Write completed StartTime: %d, EndTime: %d, IOTime: %d in seconds.\n", endTime, startTime, IOtime);
printf("BLOB Write completed in %d seconds.\n", (endTime - startTime) - IOtime);
fclose(ifile); /* Close the INFILE */
printf("\nData inserted into database\n\n");
* Now read the data back. Reuse the previous statement handle.
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
sr = SQLAllocHandle(SQL_HANDLE_STMT, hDbConn, &hstmt);
if (sr != SQL_SUCCESS)
printf("Error allocating statement handle\n");
* Prepare select statement, bind variable and execute
sr = SQLPrepare(hstmt, iSqlCmd1, SQL_NTS);
if (sr != SQL_SUCCESS)
printf("Error preparing select statement\n");
sr = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, read_name, strlen(read_name), &type[0]);
if (sr != SQL_SUCCESS)
printf("Error binding name variable\n");
time( &startTime );
sr = SQLExecute(hstmt);
if (sr != SQL_SUCCESS)
printf ("Error executing insert statement\n");
ofile = fopen(write_name, "w"); /* Open the file for writing in ASCII mode */
sr = SQLFetch(hstmt);
if (sr != SQL_SUCCESS)
printf ("Error fetching data\n");
* Read the data in BUFSIZE chunks.
i = 0; /* Initialize bytes inserted */
count = 0; /* Initialize pieces/chunks inserted */
memset(buf, NULL, BUFSIZE);
do
* Retrieve a BUFSIZE chunk of data into the buffer
sr = SQLGetData(hstmt, 1, SQL_C_CHAR, buf, BUFSIZE, &type[2]);
if (sr == SQL_ERROR)
printf("Error fetching data\n");
break;
time( &startTimeIO );
count++; /* Increment chunk number */
/* Determine if this is a full chunk or the last chunk */
if (filesize - i >= BUFSIZE)
printf("%5ld:%10ld - About to write %ld bytes to file\n",count,i,BUFSIZE);
fwrite(buf, BUFSIZE, 1, ofile); /* Write BUFSIZE chunk to file */
else
printf("%5ld:%10ld - About to write %ld bytes to file\n",count,i,filesize-i);
fwrite(buf, filesize-i, 1, ofile); /* Write remaining chunk to file */
time( &endTimeIO );
IOtime = IOtime + (endTimeIO - startTimeIO);
/* Recalculate total bytes retrieved */
if (filesize - i >= BUFSIZE)
i+= BUFSIZE;
else
i+= (filesize - i);
} while (sr == SQL_SUCCESS_WITH_INFO);
printf("%5ld:%10ld - Done writing file\n",++count,i);
time( &endTime );
printf("BLOB Read completed StartTime: %d, EndTime: %d, IOTime: %d in seconds.\n", endTime, startTime, IOtime);
printf("BLOB Read completed in %d seconds.\n", (endTime - startTime) - IOtime);
fclose(ofile); /* Close the OUTFILE */
printf("\nData written to file\n");
* Log off
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
CloseOra();
* Main routine
void main(argc, argv)
int argc; /* Number of command line arguments */
char argv[]; / Array of command line arguments */
long filesize = 0; /* Size of INFILE */
FILE ifile; / Pointer to INFILE */
#ifdef NUTC
struct stat statbuf; /* Information on a file. */
#endif
/* Check for the proper number of command line arguments entered by user */
if (argc != 3)
printf("\nCommand line syntax: <program_name> <infile_name> <outfile_name>");
printf("\n Example call: blob input.exe output.exe\n");
exit(1);
/* Open INFILE */
if( (ifile = fopen(argv[1], "rb" )) == NULL )
printf( "\nThe file '%s' could not be opened\n",argv[1]);
exit(1);
else
printf( "\nThe file '%s' was opened successfully\n",argv[1]);
#ifdef NUTC
/* Determine length of the INFILE */
if (fstat(fileno(ifile), &statbuf) == 0)
filesize = statbuf.st_size;
else
filesize = 0;
#else
filesize = filelength(fileno(ifile));
#endif
printf( "The file is %d bytes long\n",filesize);
/* Close INFILE */
fclose(ifile);
/* Insert and retrieve BLOB */
readCertImage(argv[1], filesize, argv[2]);
}During binding, strings are generally skipped. As such, you should first try replacing XMLType('?') with XMLType(?). You don't need to specify '?' because the system knows the proper type from your SQLBindParameter call.
Also, you should try replacing:
sr = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 0, 0,(SQLPOINTER)3, 0, &type[2]);
with
sr = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 0, 0,(SQLPOINTER)buf, BUFSIZE, &type[2]); -
What is the diffrence between package javax.sql and java.sql
Is javax designed for J2EE?
And when to use package javax?Hi,
What is the diffrence between package javax.sql and java.sql?The JDBC 2.0 & above API is comprised of two packages:
1.The java.sql package and
2.The javax.sql package.
java.sql provides features mostly related to client
side database functionalities where as the javax.sql
package, which adds server-side capabilities.
You automatically get both packages when you download the JavaTM 2 Platform, Standard Edition, Version 1.4 (J2SETM) or the JavaTM 2, Platform Enterprise Edition, Version 1.3 (J2EETM).
For further information on this please visit our website at http://java.sun.com/j2se/1.3/docs/guide/jdbc/index.html
Hope this helps.
Good Luck.
Gayam.Srinivasa Reddy
Developer Technical Support
Sun Micro Systems
http://www.sun.com/developers/support/ -
How to read BLOB column from a table in SQL or PL/SQL
I have table which is having one BLOB data type column . Ihave inserted few rows in that table . Now i want to see wheather BLOB column has been inserted properly or not . How to read that column through SQL or PL/SQL.
Can anyone help me to do this.You can only manipulate LOBs in PL/SQL because you have to use the DBMS_LOB package.
Check out the Oracle Developer's Guide -
Please help me.
data's on sql server and application on oracle. I need a query to sum (sls+mkdn+ rtn) but one of column has null value. thank you. chrisHi,Etbin, thank you for your help. I can't use that because my data warehouse is on sql server. that select statement only works on oracle.
-
SQL Report not showing data - available in SQL Workshop and SQL Developer
I am having an issue with developing a SQL Report in APEX 3.2.1. I run the code in both SQL developer and SQL Workshop and I get data pulled back (both against my development environment). When I run the same code in a SQL Report region, it returns no data available. Does anyone have any idea what would be causing this? Other regions on the page accessing different tables in the same schema return data without issue. Any help would be appreciated.
Thanks
FreddieCould you explain the last comment a bit more. Here is a bit more info just in case I touch on the info with it. The db schema is BPAMGR, the Workspace is BPAMGR. We use the same schema for all of our reporting. All of our tables are in the same schema. We don't use any tables outside of this schema. Our APEX workspace has been associated to only this schema. The tables are able to be queried by SQL Workshop in the same APEX instance that the report application is under.
Freddie -
Creation of System Stored Procedure in SQL Server 2012 & SQL Server 2012 R2.
Hi all,
I am stuck at a point I am looking for a system stored procedure named 'sp_dboption' in SQL Server 2012 & R2 but could not find.
Searched for it on the net and found that, this stored procedure 'sp_dboption' is now obsolete. So I tried to copy the content of 'sp_dboption' stored procedure from SQL Server 2008 R2 and create new system stored procedure with this name 'sp_dboption' in
SQL Server 2012 but was unable to create the system stored procedure.
Can you guys please tell me how to create system stored procedure in SQL Server 2012 & SQL Server 2012 R2. The reason of why I want to achieve this is because I have used 'sp_dboption' system stored procedure in my application to create a database.
As 'sp_dbotion' stored procedure is present in SQL Server 2008 R2 I am able to create the database in SQL server 2008 R2 but not in SQL server 2012.
Can you please guide me how to create system stored procedure. I am out of luck.
Please assist me, thanks & looking for help at the earliest. Hope someone will come to the fore and help me.Hi Vishwajeet,
If you tried to create any object in the sys schema, you will get the error below.
The specified schema name "sys" either does not exist or you do not have permission to use it.
So I am afraid creating any object in sys schema is not supported by SQL Server. Here is a similar link for your reference.
How to create table in SYS schema in SQL Server?
Though sp_dboption is not in SQL Server 2012, does creating a user-defined one with the same content in 2008 make any difference in your business? You just need to specify the fully qualified name dbname.dbo.sp_dboption.
If you are still interested in creating a system sp_dboption, you can register it with the
sp_ms_marksystemobject.
See
Creating Your Own SQL Server System Stored Procedures.
Eric Zhang
TechNet Community Support -
Hi Gurus,
I have this problem in my MS SQL Server 2012 that is running in SQL Server 2008 R2 Enterprise 64 bit.. Not sure why... Here is the full details of the error:
Microsoft OLE DB Provider for ODBC Drivers 80040E14
[Microsoft][ODBC SQL Server Driver][SQL Server]The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction.
/Libraries/DBA/DBA.asa, line 717
Line 717 is this:
rs.open destTableName,,,,adCmdTable
Full details of the code:
'Field object used to iterate through each field of the rs
dim rs, fld
'call dbInitRS(rs)
set rs = server.createobject("adodb.recordset")
'On Error Resume Next
'Open rs
set rs.activeConnection = myConnection
rs.cursorType = adOpenKeyset
rs.lockType = adLockOptimistic
'rs.open destTableName
rs.open destTableName,,,,adCmdTable
'if err.number <> 0 then
' goto HandleError
'end if
rs.addNew
Any ideas how to solve this problem?
ThanksStill does not work. I have allow MSDSTC in my firewall list.
Hi dudskie,
Have you try to use DTCTester or DTCPing to verify MSDTC functionality over the network? Please refer to the following article:
Troubleshooting Problems with MSDTC:
http://msdn.microsoft.com/en-us/library/aa561924.aspx
Use the DTCTester utility to verify transaction support between two computers if SQL Server is installed on one of the computers. The DTCTester utility uses ODBC to verify transaction support against a SQL Server database. For more information about
DTCTester see How to Use DTCTester Tool.
Use DTCPing to verify transaction support between two computers if SQL Server is not installed on either computer. The DTCPing tool must be run on both the client and server computer and is a good alternative to the DTCTester utility when SQL Server
is not installed on either computer. For more information about DTCPing, see
How to troubleshoot MS DTC firewall issues.
If you have any feedback on our support, please click
here.
Hope this helps.
Regards,
Elvis Long
TechNet Community Support -
OBIEE: logical SQL to Physical sql conversion
Hi,
Is there any way i can get the physical sql from logical sql ( Apart from reading log file).. I am looking something like JAVA api which does that for us.. Do we have any mapping table which stores this mapping.
Does the OBIEE provides any Java API.
Appreciate your help in advance.Hi Experts,
Please help on this.
Maybe you are looking for
-
How do I delete/hide songs from iTunes Match? (More info inside)
How do I delete/hide songs from iTunes Match? When I mark them, and delete them (and yes, I mark the box where it says delete from the cloud as well), they just reappear once I sync with itunes match again. (the symbol available for download appears)
-
How do you create an interactive floor plan in flash using AS2?
I am attempting to make an interactive floor plan. I am sure that I have done it wrong, I am new to flash. So far I have outlined the rooms that I want to make "hot spots", turned them into buttons. Then I selected all the buttons and turned it int
-
Why did my iTunes money disappear after I spent only 10.30
Why did my iTunes money disappear after I spent only $10.30?
-
Upgraded to new software, Now I have 39gig worth on my itunes, not 8gig
I deleted my old itunes software and quicktime and installed the new stuff. Now it is saying I have 39 gigs of music with the same amount of songs(1900). I actually only have 8 gigs of music. Anyway to fix this. I have a 30gig ipod. thanks Wes
-
7.5 Standby apply log issue - Cold backup of standby
We are in the process of migrating to 7.8 from 7.5 and have a 7.5 standby. Needed to test the time is takes to backup from the standby once we go-live on the 7.8 64bit server. Logs have been applied to the 7.5 standby for more than a month just fine