Embedded SQL against Oracle Question

Software: Forte 3.0.J.
Server Platform: HPUX 10.2
Database: Oracle
Problem Description: During the course of development, I ran into a
problem using multiple columns in an sql UPDATE/SET statement. I was trying
to update a.COLUMN_1 and a.COLUMN_2, which constitute part of the primary
key of associative TABLE_A (a). In order for me to make the update, I
needed to use the existing value of a.COLUMN_1 to lookup the new b.COLUMN_1
in TABLE_B (b). Where a.COLUMN_1 = b.RELATED_COLUMN_1, I am able to find
each b.COLUMN_2 that correspond to each a.COLUMN_2.
I was able to resolve the issue by separating the two columns so
that each had it's own select statement. Theoretically, it appears that
this shouldn't work, because the SET statement for a.COLUMN_1 would cause
the a.COLUMN_1 reference in the select statement of a.COLUMN_2 to be
overwritten.
In spite of this, I tried it, and it worked. I would like to
understand why the sql works, and how sql actually executes the statement.
Here is the sql:
UPDATE TABLE_A a
SET a.COLUMN_1 =
(SELECT DISTINCT b1.COLUMN_1
FROM TABLE_B b1
WHERE b1.RELATED_CASE_ID =
a.COLUMN_1 AND
b1.RELATED_COLUMN_TYPE_CD = 'NEPHI'),
a.COLUMN_2=
(SELECT DISTINCT b2.COLUMN_2
FROM TABLE_B b2
WHERE b2.RELATED_COLUMN_1=
a.COLUMN_1 AND
b2.RELATED_COLUMN_TYPE_CD = 'NEPHI' AND
b2.RELATED_COLUMN_2= a.COLUMN_2)
WHERE a.COLUMN_1 = 100
The table structure is as follows:
TABLE_A: (primary keys are bolded) This is an associative table.
Column_1 and Column_2 comprise the pk of one table; Column_3 and Column_4
comprise the pk of another table. Assume that the Column_1 and Column_2
values replacing the original values already exist in the parent table of
which they form the pk).
COLUMN_1
COLUMN_2
COLUMN_3
COLUMN_4
COLUMN_5
TABLE_B: (primary keys are bolded) This is a reference table.
COLUMN_1
COLUMN_2
RELATED_COLUMN_1
RELATED_COLUMN_2
RELATED_COLUMN_TYPE_CD
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

If you do an explain plan or set autotrace on against this update statement,
you'll find that the select operations are actually executed first by Oracle
- I believe because of the nature of the transaction. Thus, no problem.
Brian Wilson
U.S. Bancorp Piper Jaffray
[email protected]
Phone (612) 342-5682
From: David Pettit[SMTP:[email protected]]
Reply To: David Pettit
Sent: Friday, April 30, 1999 1:58 PM
To: '[email protected]'
Subject: Embedded SQL against Oracle Question
Software: Forte 3.0.J.
Server Platform: HPUX 10.2
Database: Oracle
Problem Description: During the course of development, I ran into a
problem using multiple columns in an sql UPDATE/SET statement. I was
trying
to update a.COLUMN_1 and a.COLUMN_2, which constitute part of the primary
key of associative TABLE_A (a). In order for me to make the update, I
needed to use the existing value of a.COLUMN_1 to lookup the new
b.COLUMN_1
in TABLE_B (b). Where a.COLUMN_1 = b.RELATED_COLUMN_1, I am able to find
each b.COLUMN_2 that correspond to each a.COLUMN_2.
I was able to resolve the issue by separating the two columns so
that each had it's own select statement. Theoretically, it appears that
this shouldn't work, because the SET statement for a.COLUMN_1 would cause
the a.COLUMN_1 reference in the select statement of a.COLUMN_2 to be
overwritten.
In spite of this, I tried it, and it worked. I would like to
understand why the sql works, and how sql actually executes the statement.
Here is the sql:
UPDATE TABLE_A a
SET a.COLUMN_1 =
(SELECT DISTINCT b1.COLUMN_1
FROM TABLE_B b1
WHERE b1.RELATED_CASE_ID =
a.COLUMN_1 AND
b1.RELATED_COLUMN_TYPE_CD = 'NEPHI'),
a.COLUMN_2=
(SELECT DISTINCT b2.COLUMN_2
FROM TABLE_B b2
WHERE b2.RELATED_COLUMN_1=
a.COLUMN_1 AND
b2.RELATED_COLUMN_TYPE_CD = 'NEPHI' AND
b2.RELATED_COLUMN_2= a.COLUMN_2)
WHERE a.COLUMN_1 = 100
The table structure is as follows:
TABLE_A: (primary keys are bolded) This is an associative table.
Column_1 and Column_2 comprise the pk of one table; Column_3 and Column_4
comprise the pk of another table. Assume that the Column_1 and Column_2
values replacing the original values already exist in the parent table of
which they form the pk).
COLUMN_1
COLUMN_2
COLUMN_3
COLUMN_4
COLUMN_5
TABLE_B: (primary keys are bolded) This is a reference table.
COLUMN_1
COLUMN_2
RELATED_COLUMN_1
RELATED_COLUMN_2
RELATED_COLUMN_TYPE_CD
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
Nondeposit investment products are not insured by the FDIC, are
not deposits or other obligations of or guaranteed by U.S. Bank
National Association or its affiliates, and involve investment
risks, including possible loss of the principal amount invested.
Past performance does not guarantee future results. We consider
our sources reliable. Accuracy and completeness are not guaranteed.
Information is subject to change. Transactional details should not
be relied on for tax purposes and do not supersede normal trade
confirmations or statements. Messaging outside U.S. jurisdictions
from U.S. Bancorp Piper Jaffray to non-institutional parties is not
intended for solicitation purposes.
Electronic mail sent through the Internet is not secure. We will
not accept time-sensitive, action-oriented messages, transaction
orders, fund transfer instructions or check stop payments
electronically.
If you are not the intended recipient, notify the Sender. This
information is intended only for the person named above and for
the purposes indicated. Do not distribute this message without
written consent of the author. Non-business opinions may not
reflect opinions of U.S. Bancorp Piper Jaffray and its affiliates.
U.S. Bancorp Piper Jaffray and its affiliates reserve the right to
monitor all e-mail.
Securities products and services are offered through
U.S. Bancorp Piper Jaffray Inc., member SIPC and NYSE, Inc.,
a subsidiary of U.S. Bancorp.
To unsubscribe, email '[email protected]' with
'unsubscribe forte-users' as the body of the message.
Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

Similar Messages

  • .......Embedding  SQL PLUS commands inside PL/SQL.....

    hai every body,
    I have a doubt regarding sql plus commands and PL/SQL..I am using Oracle 10g..I have created 1 procedure for deletion/updation of transactions..and the number of effected rows I just displayed with using " *dbms_output.put_line* (SQL%ROWCOUNT)"..hence before executing the procedure the sqlPlus command "*SET SERVEROUTPUT ON*" should turn on..at most times it is forget to turn on and output becomes vague..
    hence my question is "*Is there any package or any thing to execute sql plus commands(here it is SET SERVER OUTPUT ON) through PL/SQL statements???*"
    with thanks,
    jp@valapad

    jp@valapad wrote:
    I have a doubt regarding sql plus commands and PL/SQL..
    Easy PL/SQL supports PL/SQL commands and embedded SQL, which are found in the PL/SQL and SQL reference manuals.
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/toc.htm
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/toc.htm
    It does not support the commands of other applications or languages such as SQL*Plus, Unix or COBOL for example.
    I am using Oracle 10g..I have created 1 procedure for deletion/updation of transactions..and the number of effected rows I just displayed with using " *dbms_output.put_line* (SQL%ROWCOUNT)"..hence before executing the procedure the sqlPlus command "*SET SERVEROUTPUT ON*" should turn on..at most times it is forget to turn on and output becomes vague..You can set serveroutput on in your log in script for SQL*Plus if you keep forgetting.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/ch_two.htm#sthref94
    hence my question is "*Is there any package or any thing to execute sql plus commands(here it is SET SERVER OUTPUT ON) through PL/SQL statements???*"No.

  • Using a SQL for Oracle in Microsoft Excel Query

    I am having the most difficult time (in fact, I can't get it to work) trying to use an SQL I created in Toad for Oracle. It works fine in Toad for Oracle...gives me all the data I need. I am trying to use it in Excel for users that don't know SQL or Oracle so they can use the query to extract data they need for Charts, Graphs, etc.
    Here is the SQL code from Toad for Oracle:
    /* Formatted on 2006/09/22 11:42 (Formatter Plus v4.8.6) */
    SELECT a_compl_summary.incident_number, a_compl_summary.case_number,
           a_compl_summary.part_sequence, a_compl_summary.part_number,
           a_compl_summary.lot_number, a_compl_summary.alert_date,
           a_compl_summary.entry_date, a_compl_summary.NAME,
           a_compl_summary.MONTH, a_compl_summary.product_family,
           a_compl_summary.complaint, a_compl_summary.reportable,
           a_compl_summary.product_returned, a_compl_summary.case_desc,
           a_compl_summary.failure_invest_desc, a_compl_summary.lhr_search,
           a_compl_summary.root_cause, a_compl_summary.corrective_action,
           a_compl_summary.region,
           rp_qa_reported_device_codes.reported_device_code,
           rp_qa_reported_device_codes.reported_dev_clarification,
           rp_qa_reported_device_codes.reported_dev_code_desc,
           rp_qa_patient_codes.patient_code,
           rp_qa_patient_codes.patient_code_clarif,
           rp_qa_patient_codes.patient_code_severity,
           rp_qa_patient_codes.description
      FROM chsuser.a_compl_summary,
           chsuser.rp_qa_patient_codes,
           chsuser.rp_qa_reported_device_codes
    WHERE (    (a_compl_summary.product_division = 'CP')
            AND (    a_compl_summary.entry_date >= :date1
                 AND a_compl_summary.entry_date <= :date2
            AND (   a_compl_summary.product_family LIKE :pf1
                 OR a_compl_summary.product_family LIKE :pf2
                 OR a_compl_summary.product_family LIKE :pf3
                 OR a_compl_summary.product_family LIKE :pf4
                 OR a_compl_summary.product_family LIKE :pf5
            AND (a_compl_summary.region = :r1)
            AND (   a_compl_summary.NAME = :c1
                 OR a_compl_summary.NAME = :c2
                 OR a_compl_summary.NAME = :c3
                 OR a_compl_summary.NAME = :c4
                 OR a_compl_summary.NAME = :c5
            AND (a_compl_summary.complaint = :yorn)
            AND (   rp_qa_reported_device_codes.reported_dev_clarification LIKE
                                                                              :cl1
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
                                                                              :cl2
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
                                                                              :cl3
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
                                                                              :cl4
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
                                                                              :cl5
            AND (rp_qa_reported_device_codes.reported_dev_clarification NOT LIKE
                                                                              :dc1
            AND (a_compl_summary.incident_number =
                                               rp_qa_patient_codes.incident_number
            AND (a_compl_summary.case_number = rp_qa_patient_codes.case_number)
            AND (a_compl_summary.part_sequence = rp_qa_patient_codes.part_sequence
            AND (a_compl_summary.incident_number =
                                       rp_qa_reported_device_codes.incident_number
            AND (a_compl_summary.case_number =
                                           rp_qa_reported_device_codes.case_number
            AND (a_compl_summary.part_sequence =
                                         rp_qa_reported_device_codes.part_sequence
            AND (rp_qa_reported_device_codes.incident_number =
                                               rp_qa_patient_codes.incident_number
            AND (rp_qa_reported_device_codes.case_number =
                                                   rp_qa_patient_codes.case_number
            AND (rp_qa_reported_device_codes.part_sequence =
                                                 rp_qa_patient_codes.part_sequence
           )Can someone help me...maybe point out what I'm doing wrong.
    Note: I also tried creating this query in Microsoft Query (the simple way) and when I first create it...it works...But then if I go back in to edit the query, and refresh the query or try to Return data to Excel, it gives me a ORA-00936 error message.
    Why it works when I first create the query in Excel, I don't know. But I have to validate the queries I'm creating (SQL or not) and I can't validate it if every time I go into edit the query (which may have to happen; that's why I have to fix this before I can submit my validation).
    Anyway, any help would be greatly appreciated.

    Okay, I know I'm replying to my own threads here...but I want to add a little bit more information again.
    I was successful in figuring out that changing the :criteria to a ? worked.
    I tested this on 1 criteria at a time. Adding one more scenario ? at at time.
    It only worked up until about 3 scenarios of each criteria.
    Then when I refreshed the query in Microsoft Excel Query, I got an "out of memory" error, and then it ended up just erasing the SQL I had been using.
    Here's the SQL I had where it gave me this error. Am I possibly just making Excel work too hard? It just doesn't make sense because Toad for Oracle handled it in like 4 seconds. Which brings me back to an intial question I had. Can Excel use Toad for Oracle somehow?
    Here's the code:
    SELECT a_compl_summary.incident_number, a_compl_summary.case_number,
           a_compl_summary.part_sequence, a_compl_summary.part_number,
           a_compl_summary.lot_number, a_compl_summary.alert_date,
           a_compl_summary.entry_date, a_compl_summary.NAME,
           a_compl_summary.MONTH, a_compl_summary.product_family,
           a_compl_summary.complaint, a_compl_summary.reportable,
           a_compl_summary.product_returned, a_compl_summary.case_desc,
           a_compl_summary.failure_invest_desc, a_compl_summary.lhr_search,
           a_compl_summary.root_cause, a_compl_summary.corrective_action,
           a_compl_summary.region,
           rp_qa_reported_device_codes.reported_device_code,
           rp_qa_reported_device_codes.reported_dev_clarification,
           rp_qa_reported_device_codes.reported_dev_code_desc,
           rp_qa_patient_codes.patient_code,
           rp_qa_patient_codes.patient_code_clarif,
           rp_qa_patient_codes.patient_code_severity,
           rp_qa_patient_codes.description
      FROM chsuser.a_compl_summary,
           chsuser.rp_qa_patient_codes,
           chsuser.rp_qa_reported_device_codes
    WHERE (    (a_compl_summary.incident_number =
                                               rp_qa_patient_codes.incident_number
            AND (a_compl_summary.case_number = rp_qa_patient_codes.case_number)
            AND (a_compl_summary.part_sequence = rp_qa_patient_codes.part_sequence
            AND (a_compl_summary.incident_number =
                                       rp_qa_reported_device_codes.incident_number
            AND (a_compl_summary.case_number =
                                           rp_qa_reported_device_codes.case_number
            AND (a_compl_summary.part_sequence =
                                         rp_qa_reported_device_codes.part_sequence
            AND (rp_qa_reported_device_codes.incident_number =
                                               rp_qa_patient_codes.incident_number
            AND (rp_qa_reported_device_codes.case_number =
                                                   rp_qa_patient_codes.case_number
            AND (rp_qa_reported_device_codes.part_sequence =
                                                 rp_qa_patient_codes.part_sequence
    AND (a_compl_summary.product_division = 'CP')
            AND (    a_compl_summary.entry_date >= ?
                 AND a_compl_summary.entry_date <= ?
            AND (   a_compl_summary.product_family LIKE ?
                 OR a_compl_summary.product_family LIKE ?
                 OR a_compl_summary.product_family LIKE ?
                 OR a_compl_summary.product_family LIKE ?
                 OR a_compl_summary.product_family LIKE ?
            AND (a_compl_summary.region = ?)
            AND (   a_compl_summary.NAME = ?
                 OR a_compl_summary.NAME = ?
                 OR a_compl_summary.NAME = ?
                 OR a_compl_summary.NAME = ?
                 OR a_compl_summary.NAME = ?
            AND (a_compl_summary.complaint = ?)
            AND (   rp_qa_reported_device_codes.reported_dev_clarification LIKE
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
                 OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
            AND (rp_qa_reported_device_codes.reported_dev_clarification NOT LIKE
               ))

  • Can window and aggregate SQL functions used in Pro*C embedded SQL?

    It appears that the window functions such as dense_rank() over(partition by ... order by ...) are not available in Pro*C embedded SQL. Can somebody please confirm that that is really the case?
    Thanks
    Rawender Guron

    Please refer to this thread: "Is this forum also used for Pro*'C Questions? "
    Is this forum also used for Pro*'C Questions?

  • How to convert epoch time to datetime in sql*loader Oracle

    Hello,
    I wan't to question how to convert epoch time to datetime in sql*loader Oracle. I try this script for convert epoch time to datetime in sql*loader, but error:
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    This is my loader:
    LOAD DATA INFILE 'C:\Documents and Settings\Administrator\My Documents\XL_EXTRACT_211\load.csv'
    into table TEMP_TEST_LANGY append
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    DATADATA CHAR "TO_DATE('01-JAN-1970','DD-MON-YYYY')+:datadata/86400"
    This is my csv file:
    79314313.7066667
    79314336.2933333
    79314214.3466667
    This is my table:
    CREATE TABLE TEMP_TEST_LANGY
    DATADATA DATE
    Thanks
    Edited by: xoops on Sep 21, 2011 8:56 AM
    Edited by: xoops on Sep 21, 2011 8:58 AM

    thanks for your answer, but I asked to use sql loader instead of the external table, which so my question is why can not the epochtime converted to datetime, if there is no way to convert a datetime epochtime using sql loader, so I'm required to use the external table. thank you.
    This is my error log:
    Column Name Position Len Term Encl Datatype
    DATADATA FIRST * , CHARACTER
    SQL string for column : "TO_DATE('1-Jan-1970 00:00:00','dd-MM-YYYY hh24:mi:ss') + (:DATADATA/60/60/24)"
    Record 1: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 2: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Record 3: Rejected - Error on table TEMP_TEST_LANGY, column DATADATA.
    ORA-01722: invalid number
    Edited by: xoops on Sep 21, 2011 12:33 PM

  • PRO*C에서 EMBEDDED SQL STATEMENTS를 사용해서 LOB DATATYPES에 접근하는 예제

    제품 : PRECOMPILERS
    작성날짜 : 2001-07-12
    PRO*C에서 EMBEDDED SQL STATEMENTS를 사용해서 LOB DATATYPES에 접근하는 예제
    ==========================================================================
    Pro*C에서 LOB를 사용하는 방법에는 다음 3가지가 있습니다.
    (1) PL/SQL blocks에서 DBMS_LOB package를 이용하는 방법
    (2) OCI function을 이용하는 방법
    (3) Embedded SQL statements을 이용하는 방법
    다음은 (3)번째 방법에 대한 pro*c에서 지원하는 명령어들입니다.
    o APPEND: Appends lob value at the end of another LOB.
    EXEC SQL LOB APPEND :src TO :dst;
    o ASSIGN: Assigns LOB or BFILE locator to another.
    EXEC SQL LOB ASSIGN :src TO :dst;
    o CLOSE: Close LOB or BFILE.
    EXEC SQL LOB CLOSE :src;
    o COPY: Copy all or part of LOB value into another LOB.
    EXEC SQL LOB COPY :amt FROM :src [AT :src_offset] TO :dst [AT dst_offset];
    o CREATE TEMPORARY: Creates a temporary LOB.
    EXEC SQL LOB CREATE TEMPORARY :src;
    o ERASE: Erase the given amount of LOB data starting from a given offset.
    EXEC SQL LOB ERASE :amt FROM :src [AT :src_offset];
    o FILE CLOSE ALL: Closes all the BFILES open in the current session.
    EXEC SQL LOB FILE CLOSE ALL;
    o FILE SET: Set DIRECTORY alias and FILENAME in a BFILE locator.
    EXEC SQL LOB FILE SET :file DIRECTORY = :alias, FILENAME = :filename;
    o FREE TEMPORARY: Free the temporary space for the LOB locator.
    EXEC SQL LOB FREE TEMPORARY :src
    o LOAD FROM FILE: Copy all or part of BFIL into an internal LOB.
    EXEC SQL LOB LOAD :amt FROM FILE :file [AT :src_offset]
    INTO :dst [AT :dst_offset];
    o OPEN: Open a LOB or BFILE for read or read/write.
    EXEC SQL LOB OPEN :src [ READ ONLY | READ WRITE ];
    o READ: Reads all or part of LOB or BFILE into a buffer.
    EXEC SQL LOB READ :amt FROM :src [AT :src_offset]
    INTO :buffer [WITH LENGTH :buffer];
    o TRIM: Truncates the LOB vlaue.
    EXEC SQL LOB TRIM :src to :newlen;
    o WRITE: Writes contents of the buffer to a LOB.
    EXEC SQL LOB WRITE [APPEND] [FIRST | NEXT | LAST | ONE ]
    :amt FROM :buffer [WITH LENGTH :buflen] INTO :dst [AT :dst_offset];
    o DESCRIBE: Retrieves the attributes from a LOB.
    EXEC SQL LOB DESCRIBE :src GET attribute1 [{, attributeN}]
    INTO :hv1 [[INDICATOR] :hv_ind1] [{, :hvN [[INDICATOR] :hv_indN] }];
    Attributes can be any of the following:
    CHUNKSIZE: chunk size used to store the LOB value
    DIRECTORY: name of the DIRECTORY alias for BFILE
    FILEEXISTS: whether BFILE exists or not
    FILENAME: BFILE name
    ISOPEN: whether BFILE with this locate is OPEN or not
    ISTEMPORARY: whether specified LOB is temporary or not
    LENGTH: Length of BLOBs and BFILE in bytes, CLOBs and NCLOBs
    in characters.
    다음은 LOB를 사용하는 sample을 실행하는 방법입니다.
    1. 먼저 scott user에서 다음을 실행합니다. (create directory를 할 수 있는 권한이
    있어야 하며, directory는 사용하시는 환경에 맞도록 수정해 주십시요.)
    drop table lob_table;
    create table lob_table (key number, a_blob BLOB, a_clob CLOB);
    drop table lobdemo;
    create table lobdemo (key number, a_blob BLOB, a_bfile BFILE);
    drop directory dir_alias;
    create directory dir_alias as '/users/app/oracle/product/8.1.7/precomp/demo/proc';
    insert into lob_table values(1, utl_raw.cast_to_raw('1111111111'), 'aaaaaaaa');
    commit;
    2. 다음 코드는 out.gif 파일을 위에서 지정한 directory에 만들고 lob_table의
    내용에 들어있는 BLOB의 내용을 저장하는 sample입니다.
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <sqlda.h>
    #include <sqlcpr.h>
    /* Define constants for VARCHAR lengths. */
    #define UNAME_LEN 20
    #define PWD_LEN 40
    /* Declare variables. No declare section is
    needed if MODE=ORACLE. */
    VARCHAR username[UNAME_LEN]; /* VARCHAR is an Oracle-supplied struct */
    varchar password[PWD_LEN]; /* varchar can be in lower case also. */
    /* The following 3 lines avoid inclusion of oci.h during precompilation
    oci.h is needed only during compilation to resolve calls generated by
    the precompiler
    #ifndef ORA_PROC
    #include <oci.h>
    #endif
    #include <sqlca.h>
    OCIBlobLocator *blob;
    OCIClobLocator *clob;
    FILE *fp;
    unsigned int amt, offset = 1;
    #define MAXBUFLEN 5000
    unsigned char buffer[MAXBUFLEN];
    EXEC SQL VAR buffer IS RAW(MAXBUFLEN);
    /* Declare error handling function. */
    void sql_error(msg)
    char *msg;
    char err_msg[128];
    size_t buf_len, msg_len;
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    printf("\n%s\n", msg);
    buf_len = sizeof (err_msg);
    sqlglm(err_msg, &buf_len, &msg_len);
    printf("%.*s\n", msg_len, err_msg);
    EXEC SQL ROLLBACK RELEASE;
    exit(EXIT_FAILURE);
    void main()
    /* Connect to ORACLE--
    * Copy the username into the VARCHAR.
    strncpy((char *) username.arr, "SCOTT", UNAME_LEN);
    /* Set the length component of the VARCHAR. */
    username.len =
    (unsigned short) strlen((char *) username.arr);
    /* Copy the password. */
    strncpy((char *) password.arr, "TIGER", PWD_LEN);
    password.len =
    (unsigned short) strlen((char *) password.arr);
    /* Register sql_error() as the error handler. */
    EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");
    /* Connect to ORACLE. Program will call sql_error()
    * if an error occurs when connecting to the default database.
    EXEC SQL CONNECT :username IDENTIFIED BY :password;
    printf("\nConnected to ORACLE as user: %s\n", username.arr);
    /* Allocate the LOB host variables and select the BLOB value */
    EXEC SQL ALLOCATE :blob;
    EXEC SQL ALLOCATE :clob;
    EXEC SQL SELECT a_blob INTO :blob FROM lob_table WHERE key=1;
    /* Open external file to which BLOB value should be written */
    fp = fopen("out.gif", "w");
    EXEC SQL WHENEVER NOT FOUND GOTO end_of_lob;
    amt = 5000;
    EXEC SQL LOB READ :amt FROM :blob AT :offset INTO :buffer;
    fwrite(buffer, MAXBUFLEN, 1, fp);
    EXEC SQL WHENEVER NOT FOUND DO break;
    /* Use polling method to continue reading the next pieces */
    while (TRUE)
    EXEC SQL LOB READ :amt FROM :blob INTO :buffer;
    fwrite(buffer, MAXBUFLEN, 1, fp);
    end_of_lob:
    fwrite(buffer, amt, 1, fp);
    printf("\nG'day.\n\n\n");
    /* Disconnect from ORACLE. */
    EXEC SQL ROLLBACK WORK RELEASE;
    exit(EXIT_SUCCESS);
    3. 다음 코드는 위에서 만든 out.gif file을 lobdemo에 저장하는 sample입니다.
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <sqlda.h>
    #include <sqlcpr.h>
    /* Define constants for VARCHAR lengths. */
    #define UNAME_LEN 20
    #define PWD_LEN 40
    /* Declare variables. No declare section is
    needed if MODE=ORACLE. */
    VARCHAR username[UNAME_LEN]; /* VARCHAR is an Oracle-supplied struct */
    varchar password[PWD_LEN]; /* varchar can be in lower case also. */
    /* The following 3 lines avoid inclusion of oci.h during precompilation
    oci.h is needed only during compilation to resolve call generated by
    the precompiler
    #ifndef ORA_PROC
    #include <oci.h>
    #endif
    #include <sqlca.h>
    OCIBlobLocator *blob;
    OCIBFileLocator *bfile;
    char *alias = "DIR_ALIAS";
    char *filename = "out.gif";
    unsigned int amt = 50;
    unsigned int filelen;
    /* Declare error handling function. */
    void sql_error(msg)
    char *msg;
    char err_msg[128];
    size_t buf_len, msg_len;
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    printf("\n%s\n", msg);
    buf_len = sizeof (err_msg);
    sqlglm(err_msg, &buf_len, &msg_len);
    printf("%.*s\n", msg_len, err_msg);
    EXEC SQL ROLLBACK RELEASE;
    exit(EXIT_FAILURE);
    void main()
    /* Connect to ORACLE--
    * Copy the username into the VARCHAR.
    strncpy((char *) username.arr, "SCOTT", UNAME_LEN);
    /* Set the length component of the VARCHAR. */
    username.len =
    (unsigned short) strlen((char *) username.arr);
    /* Copy the password. */
    strncpy((char *) password.arr, "TIGER", PWD_LEN);
    password.len =
    (unsigned short) strlen((char *) password.arr);
    /* Register sql_error() as the error handler. */
    EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");
    /* Connect to ORACLE. Program will call sql_error()
    * if an error occurs when connecting to the default database.
    EXEC SQL CONNECT :username IDENTIFIED BY :password;
    printf("\nConnected to ORACLE as user: %s\n", username.arr);
    /* Allocate the LOB locator */
    EXEC SQL ALLOCATE :blob;
    EXEC SQL ALLOCATE :bfile;
    /* Initialize the DIRECTORY alias of the BFILE and FILENAME */
    EXEC SQL LOB FILE SET :bfile
    DIRECTORY = :alias, FILENAME = :filename;
    EXEC SQL INSERT INTO lobdemo values (1, EMPTY_BLOB(), :bfile);
    EXEC SQL SELECT a_blob, a_bfile INTO :blob, :bfile FROM lobdemo
    WHERE key = 1;
    EXEC SQL LOB OPEN :bfile;
    /* Get the BFILE length */
    EXEC SQL LOB DESCRIBE :bfile
    GET LENGTH INTO :filelen;
    printf("File length is: %d\n", filelen);
    amt = filelen;
    /* Read BFILE and write to BLOB */
    EXEC SQL LOB LOAD :amt FROM FILE :bfile INTO :blob;
    EXEC SQL LOB CLOSE :bfile;
    printf("\nG'day.\n\n\n");
    /* Disconnect from ORACLE. */
    EXEC SQL COMMIT WORK RELEASE;
    exit(EXIT_SUCCESS);
    4. 다음은 실행한 결과 입니다.
    첫번째 sample :
    Connected to ORACLE as user: SCOTT
    G'day.
    두번째 sample :
    Connected to ORACLE as user: SCOTT
    File length is: 10
    G'day.

  • Calling stored procedure from embedded sql

    I'm trying to call a stored procedure from embedded sql. I'm following the examples located in
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/a96109/pco06pls.htm#i9641
    I have the following section in my .pco file before precompiling.
    exec sql execute
    begin
    docs.grant_access_to_all_categories(:p_sam_id);
    end;
    end-exec.
    When running procob on the file with the above code I get the following error.
    Error at line 225, column 13 in file pco\docs_stored_procedures.pco
    exec sql execute
    ............1
    PCB-S-00576, PLS-201: identifier 'DOCS.GRANT_ACCESS_TO_ALL_CATEGORIES' must be d
    eclared
    Error at line 225, column 13 in file pco\docs_stored_procedures.pco
    exec sql execute
    ............1
    PCB-S-00576, PLS-0: Statement ignored
    Any ideas on what I am doing wrong on calling this stored procedure.

    I get the same error when trying to precompile sample11.pco from the demo directory in the oracle client software.
    Error at line 70, column 12 in file sample11.pco
    EXEC SQL EXECUTE
    ...........1
    PCB-S-00576, PLS-201: identifier 'EMP_DEMO_PKG.OPEN_CUR' must be declared
    Error at line 70, column 12 in file sample11.pco
    EXEC SQL EXECUTE
    ...........1
    PCB-S-00576, PLS-0: Statement ignored

  • Use of Pro*C with embedded SQL

    Is it possible to reuse existing Pro*C with embedded SQL written for an Oracle 9i database on an Oracle Lite running on Windows CE/PocketPC plattform? Wich steps and tools are required to transform (compile, precompile) this code?
    Can the functionality then be easily accessed from java code?
    Thanks in advanced!

    Oracle already did. Pradeep is an Oracle developer working in Oracle9i Lite group. This is this Product Manager speaking

  • Embedded SQL query in C - variable not in select list

    Hello everyone,
    I am new to using embedded SQL in C. I have written a query based on some very similar code I have found and I keep getting this error:
    ID: ORA-XXXX
    OVRD:
    TEXT: Oracle Errors Found - Consult Application Development Team
    INFO:
    SQLC: -1007
    GLM: ORA-01007: variable not in select list
    If anyone could help me figure out what I am doing wrong that is causing this error it would be much appreciated. Thanks in advance!
    Here is the query that is generating the error, I have changed the variable names but the syntax is the same:
    SELECT TEMP_TABLE.tble,
    TEMP_TABLE.item_date,
    TEMP_TABLE.item_number,
    TEMP_TABLE.item_id,
    TEMP_TABLE.amount,
    TEMP_TABLE.method
    FROM (
    SELECT 'C' tble,
    item_date,
    item_number,
    item_id,
    amount,
    method
    FROM current
    WHERE (settlement_date IS NULL)
    UNION ALL
    SELECT '1' tble,
    item_date,
    item_number,
    item_id,
    amount,
    method
    FROM prev1
    WHERE (date IS NULL)
    UNION ALL
    SELECT '2' tble,
    item_date,
    item_number,
    item_id,
    amount,
    pay_method
    FROM prev2
    WHERE (date IS NULL)
    UNION ALL
    SELECT '3' tble,
    item_date,
    item_number,
    item_id,
    amount,
    pay_method
    FROM prev3
    WHERE (date IS NULL)
    UNION ALL
    SELECT '4' tble,
    item_date,
    item_number,
    item_id,
    amount,
    method
    FROM prev4
    WHERE (date IS NULL)) TEMP_TABLE
    WHERE (TEMP_TABLE.item_date,
    TEMP_TABLE.item_number,
    TEMP_TABLE.item_id) IN
    (SELECT item_date, item_number, item_id
    FROM item
    WHERE (source, location) IN
    (SELECT source, location
    FROM SOURCE_REF
    WHERE online = 'O'
    AND (source, location) IN
    (SELECT source,
    location
    FROM SOURCE_METHOD_REF
    WHERE type = 'P')))

    Oh yeah I forgot to add that I have tested the query in TOAD and it works just fine so its something to do with embedding it into C I believe.

  • Error using setTimestamp and ojdbc14 against Oracle 7.3.4

    I am having a problem setting a timestamp value against Oracle 7.3.4 and Oracle 8.0.6 databases.
    Here's the code:
    public Tester
    (String passedUsername, String passedPassword, String passedHostName, String passedPort, String passedSID)
    throws SQLException {
    // Establish a database connection
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException e) { throw new SQLException("Can't find class oracle.jdbc.driver.OracleDriver"); }
    StringBuffer myStringBuffer = new StringBuffer(50);
    myStringBuffer.append("jdbc:oracle:thin:@");
    myStringBuffer.append(passedHostName);
    myStringBuffer.append(":");
    myStringBuffer.append(passedPort);
    myStringBuffer.append(":");
    myStringBuffer.append(passedSID);
    Connection myConnection = DriverManager.getConnection(myStringBuffer.toString(), passedUsername, passedPassword);
    myConnection.setAutoCommit(false);
    // Insert the test record
    PreparedStatement myPreparedStatement = null;
    try {
    myPreparedStatement = myConnection.prepareStatement("insert into test_table(date_field) values (?)");
    myPreparedStatement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
    myPreparedStatement.execute();
    } finally {
    if (myPreparedStatement != null) myPreparedStatement.close();
    Here's the error that occurs under Oracle 7.3.4:
    java.sql.SQLException: ORA-01024: invalid datatype in OCI call
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
         at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
         at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
         at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
         at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:656)
         at Tester.<init>(Tester.java:46)
         at Tester.main(Tester.java:62)
    Here's the error that occurs under Oracle 8.0.6:
    java.sql.SQLException: ORA-03115: unsupported network datatype or representation
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
         at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
         at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
         at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
         at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
         at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
         at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
         at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:656)
         at Tester.<init>(Tester.java:46)
         at Tester.main(Tester.java:62)
    Note that the table in the insert statement does not have to exist. You can even replace the statement with a garbage statement.
    The error is produced regardless.
    The code is being compiled under JDK 1.4
    I am using the latest version of the JDBC drivers (i.e. ojdbc14.jar)
    The code works fine under Oracle 8.1.7 and 9.0.1
    My code needs to access all four of these database version, sometimes concurrently, so I can only use a single driver class (i.e. I can't swap out ojdbc14.jar for classes12.zip).
    Any feedback would be appreciated!

    Hi,
    Only to say that we have the same problem like you:
    - Error ORA-01024 when connection to Oracle 8.0.1 on Sun Solaris
    - Error ORA-03115 when connection to Oracle 8.1.5 on Windows
    We are thinking about upgrading Oracle. Is it the only solution?
    Thank you

  • Can We use FDM as ETL tool between SQL and Oracle

    I want to use FDM as ETL tool between SQL and Oracle. Can it be possible. I didn,t found any target adapter for oracle database.My source system is SQL and Target system is Oracle database.
    Rahul
    Edited by: user12190125 on Nov 9, 2009 4:23 AM

    Rahul,
    I believe this is possible to do, but not an easy one and there are a few considerations:
    How much data are you processing? FDM has a lot of features which support the business process. While this is great for users and audit trail etc. it slows down performance if you want to process a lot of data. It also depends on the type of mappings you use (Like mappings are slower than explicit mappings).
    How familiar are you with VBScript? There is no explicit target adapter for Oracle, but there is a data mart adapter which can be used for anything. You have to implement everything yourself though, mainly the Export and Load actions. In there you will also have to handle the the connections to the MSSQL and Oracle databases.
    Check the data mart adapter and see if you feel comfortable with defining the vb code in there. There are reasons for and against this approach. ODI would probably be the better choice unless you really need to have FDM's process support.
    Regards,
    Matt

  • Can window and aggregate SQL functions be used in Pro*C embedded SQL?

    It appears that window functions such as dense_rank() over(partition by ... order by ...) can not be used in Pro*C embedded SQL? Can somebody confirm that that is really the case?
    Thanks
    Rawender Guron

    Please refer to this thread: "Is this forum also used for Pro*'C Questions? "
    Is this forum also used for Pro*'C Questions?

  • Uses for the Action Property with SQL and Oracle DB Adapters

    This thread is a complement to the Wiki Article
    BizTalk: Streamlining WCF SQL and Oracle Messaging-Only and Other Patterns
    The question.  In what circumstances is explicitly setting the Action value with the WCF SQL and Oracle DB bindings useful or beneficial. 
    A complimentary question.  Is it even possible to set the Action value to anything other than exactly what is required by the Message.
    I ask because of three very specific behaviors of the bindings themselves:
    The binding enforces a match between the Action and the Message, therefore...
    There is a one-to-one relationship between the Message and Action, but...
    The binding is able to correctly derive and perform the requested operation with the unspecific CompositeOperation.
    For clarity, I understand how to set the Action. I. understand what the Action represents in the SOAP scheme. I understand how Action can be used as an abstraction for SOAP operations.
    Thoughts?

    Do you have any good suggestion to learn how to use action property with SQL and Oracle DB adapters?  I learn a lot from your replies for years in BizTalk forum. :)

  • Need a function name for Sql and Oracle

    Retrieving value of next line by doing opteration in previous row.

    Can you rephrase the question? Or better yet, provide an example? I'm not sure I understand what you are asking.
    My best guess is that you are looking for the analytic functions LEAD or LAG in Oracle, assuming you are on a relatively recent Oracle version. If by "SQL and Oracle" in your subject you mean "SQL Server and Oracle" (SQL is a language that all relational databases implement, SQL Server is Microsoft's relational database), I have no idea how (or if) you can do something similar with a built-in function in SQL Server. You would want to post in a SQL Server group to see how they handle that sort of thing.
    Justin

  • Frequently transfering databases between MS SQL and Oracle

    Hello all,
    I am looking for a solution to easily, efficiently and be able to migrate/transfer databases between MS SQL and Oracle frequently.
    I need to be able to replicate a databases on Ms SQL and Oracle for testing purposes. I will need to do this on frequent basis - almost once a week.
    Please suggest what would be the best way.
    Thanks in advance.

    Hi Justin,
    You have guessed it right to a great extend. Yes dont actually need to develop, rather need to test an application that supports SQL and Oracle databases. Now when testing the application its obviously vital to create proper systematic test data. This usually takes a lot of time and effort from the testing team/team-member. So, yes what I need to do is create the test data on one database(may it be SQL or Oracle) and migrate/transfer the data into the database on another server( ie. SQL to Oracle or Oracle to SQL).
    So,
    Are you developing a product that works against both SQL Server and Oracle and trying to synchonize development efforts?Yes, thats correct to extend, I need to test an application against both the servers, as it supports both types of databases, and try to reduce the test setup efforts (literally double the amount) that go in after manual creating same data on each type of database.
    Are you trying to replicate structural changes between systems?I am not 100% sure, what you mean by this. But whats important and enough for me is to replicate the data. It would not be a lot of work to run the scripts and create empty schema objects.
    Are you trying to replicate data changes between systems? The fact that you're only doing this weekly suggests that you're not working in a traditional replication environment.Yes, again as I mentioned above. It would be sufficient for me to just get a copy of the initial dataset. And then replicating changes to it would not be that important. However, if I can achieve a solution to this, I can by all means create a new database on the one server (SQL or Oracle) and take the data-set of the most recent/correct changes and replicate it on the other type of server as and when needed.
    No - this is not a traditional replicating environment. I say weekly, because it is usually once in a week or forthnight that someone from the team will need to spent time to manually copy the test-data onto the another type of server in order to run the same testcases on two types of servers.
    How do you handle conflicts (i.e. if I modify a row in both systems, which modification wins)? This is not really a problem in my scenario, as I only need to be able to transfer the data across to the different server and forget about the two databases actually being in-sync.
    I have also, looked at DTS for a possible solution on SQL, however it seems highly un-realistic, having to map somewhere like 250 tables from the a drop-down list, only because the two database servers use different cases to represent tables internals. So, table 'Table' in my application's SQL database is called 'TABLE' is my applications Oracle database. DTS is highly inefficient in dealing with this. Also, having 250 tables move makes this a bit of a pain.
    Thank you Justin for your response; I highly appreciate your inputs.
    Regards, Nisarg

Maybe you are looking for

  • Here we go again...cannot update 10.0.0.1 via GPO

    Per usual, I'm trying to deploy some of the patches released via the Adobe Gods and once again, things aren't working. I'm a bit behind in updates just becasue of these issues.  Everytime I try and update, I run into brick walls and it's always such

  • Screen Scraper in Java

    If I have a checkbox on Line 1 and Line 2 and to the right of these I have text, is there anyway to "scrap" or get this text depending on whether the checkbox has been clicked on (visable) ? I assume I have to have some sort of listener for this and

  • Outlook and Droid calendar

    Can the Droid calendar and Outlook calendar on my home computer be synced?

  • Hyperion Essbase Best Practices Document...

    Hi All, Is there any document out there that has the best practices for Hyperion Essbase development? I am looking for methodologies, naming conventions and such information. Wondering if there is any such doc with Hyperion Essbase Guru's that outlin

  • Is there a script that automates mail:to links and hyperlinks?

    In a nutshell, maybe this was already done.  I searched the forum, but cant say I found what I was looking for. Jim Simon can be reached at [email protected]  Jim Simon work's gallery can be found at www.jsgallery.com.   Basic stuff like this.