SQL script(column statement) understanding

hi,
i am ataching the code of one of the SQL scripts. I am having problem in understanding some of the lines of the code for which i have put a comment, the lines start with the "column" statement and the spool statements. Please help in solving my query.
regards,
jatin
SET LINESIZE 200
SET PAGESIZE 10000
--Problem in understanding below 4 lines
column spool_text_source new_value spool_text
select 'c:\temp\DAR_' || to_char(sysdate,'YYYYMMDD')
spool_text_source from dual;
spool &spool_text..txt
--query starts here 
SELECT DISTINCT E.CITY_CODE,A.MOBILE_NO,A.ITEM_TYPE_ID,B.DOCUMENT_NUM,B.DOCUMENT_DT,E.DISTRIBUTOR_NAME
FROM
INV_SIM_SERIAL A,INVOICE_HEADER B,INVOICE_DETAIL C,INV_SIM_SERIAL D,DISTRIBUTOR_MASTER E WHERE
A.DOC_LINE_ID=C.DOC_LINE_ID AND
B.DOCUMENT_NUM=C.DOCUMENT_NUM AND
A.SERIAL_ID=NVL(D.OLD_SERIAL_ID,D.SERIAL_ID) AND
(trunc(A.FIRST_CALL_DT) = trunc(sysdate-1) OR trunc(D.FIRST_CALL_DT)= trunc(sysdate-1)) AND
NVL(A.OLD_DISTRIBUTOR_ID,A.DISTRIBUTOR_ID)=E.DISTRIBUTOR_ID AND A.ACTIVATE_DT IS NULL
order by e.distributor_name;
--query ends here
spool off
exit

Hi
The part
column spool_text_source new_value spool_text
select 'c:\temp\DAR_' || to_char(sysdate,'YYYYMMDD')
spool_text_source from dual;
spool &spool_text..txt can be written as
column spool_text_source new_value spool_text
select 'c:\temp\DAR_' || to_char(sysdate,'YYYYMMDD') spool_text_source from dual;
spool &spool_text..txt line 2 and 3 are just one sql-statement
but back to what it does
line 1 column ...
it tells SQL*Plus to get the result from the column spool_test_source of next sql-statement and put into the spool_text variable.
line 2 the SQL-statment it actuallt create an file name for the spool file and the result is put into the spool_text variable.
line 3 open the spool file and start spooling output from the script.

Similar Messages

  • Used Columns in SQL script/query

    Hi,
    we really have many SQL scripts.
    Since we expect changes within the schema, we need to know the scripts which have to be reworked.
    Is there any tool available which identifies all columns refereced by a sql script (columns used in select-list, where-clause, order-by clause, ...) ?
    Axel.

    There is a function in TOAD (http://www.toadsoft.com/) Schema Browser you select the table that need to be changed then you select the tab "used by" and it will show the stored procedures that are using this TABLE (not columns). Also this option only display stored code in the database and not unnamed scripts.
    This is a script you can use:
    Select owner, object_type, object_name, object_id, status
    from sys.DBA_OBJECTS where object_id in (
    Select object_id
    from public_dependency
    connect by prior object_id = referenced_object_id
    start with referenced_object_id = (
    Select object_id from sys.DBA_OBJECTS
    where owner = 'OWNER'
    and object_name = 'TABLE_NAME'
    and object_type = 'TABLE' ))
    I hope this is useful to you.
    Message was edited by:
    Delfino N.

  • IF statement syntax in SQL script view

    I need to include a "IF" condition in the "SELECT" section of my SQL script view.
    I tried the following syntax's but I get the error 'Incorrect SQL syntax near 'IF'
    1.  IF(Revenue <> '0' AND Quantity <> '0', Revenue/Quantity, '0') AS Gross Price
    2.  IF(Revenue != '0' AND Quantity != '0', Revenue/Quantity, '0') AS Gross Price
    3.  IF(Revenue <> '0' AND Quantity <> '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    4.  IF(Revenue != '0' AND Quantity != '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    My final SQL would read like follows:
    SELECT field1, field2, IF(......) AS field3
    FROM table1
    Can anybody please help with the correct IF statement syntax to be used in the SQL script based view?

    Hi Lakshmi,
    below is the syntax for IF statement.
    IF <bool_expr1> THEN
    <then_stmts1>
    ELSEIF <bool_expr2>
    THEN <then_stmts2>
    [ELSE <else_stmts3>]
    END IF
    eg :
    BEGIN
    DECLARE found INT := 1;
    SELECT count(*) INTO found FROM books WHERE isbn = :v_isbn;
    IF :found = 0 THEN
    INSERT INTO books VALUES (:v_isbn, 'In-Memory Data Management', 1, 1, '2011', 42.75, 'EUR');
    ELSE
    UPDATE books SET price = 42.75 WHERE isbn =:v_isbn;
    END IF;
    END;
    Sreehari

  • SQL script into a CASE statement ?

    Hy,
    can someone tell me, please, if is it possible insert into a case statement (shell unix script) one or more SQL script ?
    For example :
    case aaa in
    1 )
    sqlplus blabla <<!
    update ...
    insert ...
    2 )
    esac
    Thank you very much !
    Andys

    /unix/sqlplus -s username/pwd @file_name.sql
    This will work on unix prompt. use this in shell script and implement. file_name.sql containts update logic.
    I hope it will solve ur problem.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Andys:
    Hy,
    can someone tell me, please, if is it possible insert into a case statement (shell unix script) one or more SQL script ?
    For example :
    case aaa in
    1 )
    sqlplus blabla <<!
    update ...
    insert ...
    2 )
    esac
    Thank you very much !
    Andys<HR></BLOCKQUOTE>
    null

  • Anyone got a SQL script that outputs Oracle create statements?

    Hi all,
    I've been using a data modeling tool (ER/Studio from Embarcadero Technologies) to design my database (which currently is 11g XE running on Win7). I need to ensure that the data model and database are 100% in sync. My lack of DBA abilities now haunts me. I need to accomplish one of two things.
    1. Run a SQL script that outputs the full compliment of Oracle CREATE statements that define my app's database (BTW, all of my tables are prefixed with "PT_").
    2. Connect ER/Studio with the local 11g XE database.
    Unless someone is familiar with ER/Studio reverse-engineering, I imagine #1 above is the more straightforward solution. Does anybody have such a script they can share with me?
    Thanks so much,
    Kim

    Hi,
    Maybe this blog post helps you.
    http://www.apex-at-work.com/2013/03/generate-ddl-source-code-with-sql.html
    BTW, you are posting in wrong forum as this is Application Express forum and your question do not have anything do with this product.
    Regards,
    Jari
    My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai

  • Encoding character type in sql server column

    Hello,
    I am having troubles during REPLACE character in sql server column due to fact that, it seems to me, SQL Server does not recognize two "the same" characters i.e., some of them it translates into another encoding system correctly while, some of
    them, keeps untouched, as entered. Obviously, according to my understanding, they "look the same shape" but, obviously, belong to different encoding systems. How to change encoding system for some of them?
    Namely, this UPDATE statement:
    UPDATE TOP (4000000) tblName
    SET       FirstName = N'Đ' + SUBSTRING(FirstName, 2, 8000)
    WHERE (FirstName LIKE N'Ð%')
    works fine for my case but, as you see, it replaces just the first occurrence. Could it be possible to expand  this pattern to all occurrences?

    I'm not sure that I have fully understood what you want to achieve, but it seems that you want to replace occurrances of Latin Captial Letter Edh with Latin Capital Letter D with Stroke, which looks virtually identical in uppercase (but are entirely different
    in lowercase). Or vice versa.
    Using the glyphs is certainly bound to cause confusion, and I think the best for clarity is to use the nchar function. Or possibly upper in combination with the lowercase glyphs. As for entering the characters, the Character Map utility, which you find in
    the  folder Accessories/System Tools folder in the Start Menu is useful.
    Below is a script that demonstrates the techniques above. You can also see that the characters are considered equal in a accent-insensitive collation. (Well, at least Latin1_General. They are of course unequal in Icelandic and Croatian AI collations.)
    CREATE TABLE tblName(FirstName nvarchar(20) NOT NULL)
    INSERT tblName(FirstName)
    VALUES(upper('eðh'))
    SELECT FirstName, lower(FirstName)
    FROM tblName
    UPDATE dbo.tblName
    SET FirstName = REPLACE(FirstName, nchar(208), nchar(272))
    WHERE FirstName LIKE N'%' + nchar(208) + '%';
    SELECT FirstName, lower(FirstName)
    FROM tblName
    SELECT CASE WHEN nchar(208) = nchar(272) COLLATE Latin1_General_CI_AI THEN 1 ELSE 0 END AS Equal
    go
    DROP TABLE tblName
    Erland Sommarskog, SQL Server MVP, [email protected]

  • IF Condition in a PL/SQL Script give a report error.

    Hello, I’m German and I hope you can unterstand my Question.
    First, I work with the HTML DB Version 1.6.0.0.0.87 and the Oracle Version 9.2.0.6.
    I create a SQL Report, where a PL/SQL Script return the SQL Statement for the Report. This is my source-code, I have short it...:
    Declare
    sql_str varchar(2000);
    sql_str_select varchar(1000) :=' select dim_sparte …... ';
    sql_str_from varchar(1000) := ' from faktentabelle,dim_sparte ';
    sql_str_where varchar(1000):= ' where … and faktentabelle.zeit_id = :POPUP_ZEIT ';
    sql_str_groupby varchar(1000):= ' group by dim_sparte.name, faktentabelle.zeit_id ';
    Begin
    If ( (V('POPUP_NETZGEBIET') is not NULL) and (V('POPUP_NETZGEBIET') <>
    'Alle Netzgebiete')) THEN
    sql_str_select := sql_str_select || ' ,dim_organisationseinheit.netzgebiet_name ';
    sql_str_from := sql_str_from || ' , dim_organisationseinheit ';
    sql_str_where := sql_str_where || ' and faktentabelle ... and
    dim_organisationseinheit.netzgebiet_name = :POPUP_NETZGEBIET';
    sql_str_groupby := sql_str_groupby || ' , dim_orga .... ';
    End IF;
    sql_str:= sql_str_select || sql_str_from || sql_str_where || sql_str_groupby;
    htp.print(sql_str);
    Return sql_str;
    End;
    This Script include a IF-THEN condition. The Condition is true and the sql-String-Variables are updatet.
    I can get the string with htp.print() and the Statement is OK.
    The report get a Error “report error: ORA-1403: no data found”. If I copy the printet sql String in a new Report Region with SQL String, the Report is OK. When I write IF(true) instead of IF( Condition) the Report is OK, too.
    I try ist with Varibalen V(‘name‘) and with :name. It’s always the same problem. I can’t use IF-THEN-Else Conditions in a Script.
    Please help me and say me what is the problem???
    Thanks,
    Simona

    Hi Simona,
    In the sql region below the region source see that you have " Use Generic Column Names (parse query at runtime only)" check and not " Use Query-Specific Column Names and Validate Query".
    This error you usually get when you have a mismatch in your report heading.
    Vivek
    [email protected]

  • "ORA-1722 Invalid number" error while runing a SQL script in SQL*Plus

    Hello,
    I created a SQL script that is intended to populate tables with
    baseline data. When I run the script in the SQL*Plus program
    that comes with the Oracle 8.1.6 (client), I receive an "ORA-
    1722 Invalid number".
    The error always occurs when SQL*Plus tries to execute the
    following SQL statement:
    insert into components(db_ind,module_id,ext_compid,active) values
    ('cm',modules_seq.currval,1046682,'y');
    The datatypes for the columns on the components table are as
    follows:
    db_ind varchar2(2);
    module_id number;
    ext_compid number;
    active varchar2(1);
    It seems that for some reason Oracle is having trouble
    recognizing 1046682 as a number.
    I also tried the following INSERT statements to see if that
    would work:
    insert into components(db_ind,module_id,ext_compid,active) values
    ('cm',modules_seq.currval,to_number('1046682'),'y');
    insert into components(db_ind,module_id,ext_compid,active) values
    ('cm',modules_seq.currval,'1046682','y');
    but I still receive the same error message
    Is there some NLS setting(s) I need to modify so that Oracle
    does not give me this error? Does anyone know the answer to
    this problem?
    Your help is greatly appreciated.
    Oscar
    (NOTE: I also receive this same error when trying run the
    script in SQL Navigator and Toad programs)

    Please see the following docs.
    R12: JBO-27122 Error Message Clicking On Supplier Accounting Link With Unexpected Error [ID 1218903.1]
    Supplier Management Accounting Link Gives Unexpected Error and JBO-27122 at SELECT * FROM (select pvsa.ADDRESS_STYLE [ID 1340655.1]
    Adding Accounting Information or Operating Unit Information fails with APP-FND-1564: ORACLE error 1722 in FDFGVD [ID 364265.1]
    Thanks,
    Hussein

  • [[DataDirect][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Column name or number of supplied values does not match table definition.]

    Hii ..
    need help on this ..
    This what I am doing ..
    I am using a DATAEXPORT function to export level0 data from my essbase 11.1.2.2 to Microsoft SQL 2008 tables.
    So what I did first I exported the level0 data to a flat file using DATAEXPORT and the created the SQL columns by the same  in that order only in my SQL table.
    When I run it fails with this error:
    ODBC Layer Error: [21S01] ==> [[DataDirect][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Column name or number of supplied values does not match table definition.]
    [Tue Jul 23 18:26:07 2013]Local/dataexp/dataexp/admin@Native Directory/1209813312/Info(1021014)
    ODBC Layer Error: Native Error code [213]
    [Tue Jul 23 18:26:07 2013]Local/dataexp/dataexp/admin@Native Directory/1209813312/Error(1012085)
    Unable to export data to SQL table [dataexp]. Check the Essbase server log and the system console to determine the cause of the problem.
    [Tue Jul 23 18:26:07 2013]Local/dataexp/dataexp/admin@Native Directory/1209813312/Info(1021002)
    SQL Connection is Freed
    [Tue Jul 23 18:26:07 2013]Local/dataexp/dataexp/admin@Native Directory/1209813312/Warning(1080014)
    Transaction [ 0x1c50001( 0x51ee7d66.0x80342 ) ] aborted due to status [1012085].
    [Tue Jul 23 18:26:07 2013]Local/dataexp/dataexp/admin@Native Directory/1209813312/Info(1012579)
    Total Calc Elapsed Time for [test.csc] : [1.44] seconds
    =============================================================
    I did a simple test on my Sample.basic application then ..
    loaded the calc data to it and then used the below script to export to a flat file
    //ESS_LOCALE English_UnitedStates.Latin1@Binary
    SET DATAEXPORTOPTIONS
                    DataExportLevel "Level0";
                    DataExportOverwriteFile ON;
                    DataExportColFormat OFF;
                    DataExportDimHeader OFF;
    FIX(
                "Jan",
                "Sales",
                "Actual"
    /*DATAEXPORT "File" "," "/home/hypadmin/samtest.txt";*/
    DATAEXPORT "DSN" "Abhitest" "sample" "sa" "welcome1";
    ENDFIX
    out put as below:
    "Sales"
    "100-30","California"
    "Jan","Actual",145
    Now In sql I created only 3 columns with name Jan/Sales/Actual and when I run this script again with comments removed .. I get the same error as what I have got in my first test case with other application ..
    but when I create the columns with same name as what its in export
    Sales/100-30/Califirnia/Jan/Actual
    It created the new rows successfully ..
    So with this I think the error which I am getting with my other application might be because of the same column issue  .. but then I have created all the columns by looking at the export file only as I did in sample ..
    Any idea would be helpful ..
    Thanks
    Abhishek
    I

    First make sure you add
    DataExportRelationalFile ON;
    to your set commands it is missing
    I alwats like to also add
    DataExportColHeader dimensionName;
    so I am sure what dimension is getting put into the columns.
    Then count the number of dimensions in your outline (exclude attribute dimensions). You need at least that many columns in your table  -1 + the number of  members you will be returning as columns in the export
    Taking your example Sample basic has 5 dimensions
    Measures
    Years
    Scenario
    Product
    Market
    Since you did not specify a dataexportcolheader it took the dense dimension Scenario as the columns. Your fix statement is limiting that to one member. Doing the math
    5 -1 + 1 = 5 columns in your table which is what you found works.  Suppose you fixed on bothe Actual and budget in scenario then you would need 6 columns 5 -1 +2

  • Misbehaving Custom Timed Script 3-State Monitor

    I am stumped for an action plan to resolve this issue and would gladly appreciate any possible help!!!
    Issue:
    Monitor has generated an alert with Resolution State=New when Healthy Expression is true and then later (without any configuration changes) another alert with Resolution State=New is generated when Unhealthy Expression is true.
    Last night/this morning, I saw both of the following generated as notifications:
    Last modified time: 2/10/2014 10:11:37 PM Alert description: Queue has a length of 4175 and has exceeded a threshold value of 3,500
    Last modified time: 2/11/2014 9:11:37 AM Alert description: Queue has a length of 770 and has exceeded a threshold value of 3,500
    Similarly created monitors which target other databases using different SQL scripts seem to behave properly.
    Assessment:
    Monitor targets SQL database object with Performance parent monitor, runs every 15 min and runs a SQL query to generate an integer value which is assigned to "PerfValue".
    Unhealthy expression is Property[@Name='PerfValue'] greater than or equal to 3500
    Degraded expression is Property[@Name='PerfValue'] equals 'unknown'
    Healthy expression is Property[@Name='PerfValue'] less than 3500
    Alert description is
    Queue has a length of $Data/Context/Property[@Name='PerfValue']$ and has exceeded a threshold value of 3,500
    Health is configured as follows:
    Health condition:Healthy = Operational State:Healthy = Health State:Healthy
    Health condition:Degarded = Operational State:Degraded = Health State:Warning
    Health condition:Unhealthy = Operational State:Unhealthy = Health State:Critical
    Generates alerts is enabled and Auto resolve is also enabled.
    Ideas? Thanks in advance!!

    Thanks for the response Markus.
    The string was provided by my predecessor as a type of placeholder value in case the client determined a threshold value for a Warning state.  You are correct that it doesn't make sense to mix type.
    Root cause has been identified and I am in the process of implementing it.
    The reference article that identified root cause is here:
    http://blogs.technet.com/b/jimmyharper/archive/2009/10/01/using-integers-and-other-non-string-data-types-in-rules-and-monitors.aspx
    For some unknown reason, this issue impacted only 2 of the ~10 new monitors that I setup within the same MP.  It would be great to know what particular action or detail caused this.  It seems I may need to regularly inspect the exported xml after
    any monitor changes.
    It is too bad the new monitor wizard does not provide a warning during monitor setup of unexpected results if a numerical operator is selected for a value type that it knows is a string.  This is especially true when using the Script-based monitor
    which I understand to always expect a returned integer value. Or it should show in the GUI what the actual data type it has assigned is.
    Thanks again for your interest and taking time to respond!

  • Standard Sql scripting Vs CE built-in functions ? Which one should I need to choose?

    Hello,
    My source is csv files and I need to load these source files into HANA after doing some Transformations based on multiple validations (for example , based on grade, some new column has to be populated with some relevant hikes i.e. need to use if/else logic, case logic, either insert or update in target table …etc. This validation should be done for each and every row).
    Assume some of the validations not possible through BODS and I need to implement this logic in HANA scripting (through procedures).
    I know HANA supports two kinds of writing scripts i.e. HANA standard sql statements and CE_functions and I’ve heard from HANA documentation that CE functions gives more performance than standard sql statements and we should not mix together in a single block of code.
    Please let me know which scenario should I go for?  (I doubt if we can do all the functionalities using CE functions?
    I am looking forward to your reply.
    Thanks,
    Sree

    Much awaited reply.
    Thanks a lot Jain !
    But just one more point to bring out, if some of requirements can be done through both CE functions and Scripting,  and some are possible through only scripting then we need to go for sql scripting only ..as we are not supposed to bring both the coding standards together, results in performance issues. ( Even your diagram shows either CE functions or Use SQL)
    am i right?
    Thanks,
    Sree

  • SQL Script in XE Cancels during Execution without returning any error(s)

    Hi all;
    I'm running a SQL script with a drop table and create table statement along with several hundred insert statements to load data into this table in a Oracle 10g XE database. There's a total of 213 SQL command lines in the script. (1 Drop Tbl/1 Create Tbl/211 Insert(s)).
    I run the script within the Script Editor in the Oracle XE web interface and it processes 45 of 213 of the SQL commands in the script successfully(1 Drop Tbl/1 Create Tbl/43 Insert(s)). Then the Manage Script Results screen shows a status of "Canceled". It doesn't even attempt to insert the other rows and spit back any error messages. I tried debugging by checking the consistency of the insert statements at the break point and couldn't find any discrepancy. The script just stops executing and shows this cancelled status? Can anyone help me figure out why all the lines of this script aren't being executed? I'd appreciate it a lot!
    Thanks.
    -GM

    I've spooled output to a file which I've pasted below in italic pre-tags. I abbreviated some of output to save space in this thread. I didn't want to include 600 rows showing "1 row created" 211 times with 3 spaces between each of them. So here is my abbreviated output:
    SQL> set define off;
    SQL> @\Oracle\UTC_Upload_100807.sql;
    Table tbl_UTC_HPS_Report dropped.
    Table tbl_UTC_HPS_Report created.
    211 rows created.
    SQL> describe tbl_UTC_HPS_Report;
    Name Null? Type
    STATUS VARCHAR2(255)
    CUSTOMER_NAME VARCHAR2(255)
    CUSTOMER_NUMBER VARCHAR2(255)
    LICENSE_DESCRIPTION VARCHAR2(255)
    CONTRACT_DATE VARCHAR2(30)
    CONTRACT_NUMBER VARCHAR2(255)
    QUANTITY NUMBER(5)
    INVOICE_DATE VARCHAR2(30)
    INVOICE_CCY_CODE VARCHAR2(30)
    INVOICE_NUMBER VARCHAR2(255)
    SUPPORT_PROGRAM VARCHAR2(255)
    RENEWAL_START_DATE VARCHAR2(30)
    RENEWAL_END_DATE VARCHAR2(30)
    INVOICE_AMT VARCHAR2(255)
    INSTANCE_NUMBER VARCHAR2(255)
    SQL> select * from tbl_UTC_HPS_Report;
    STATUS
    CUSTOMER_NAME
    CUSTOMER_NUMBER
    LICENSE_DESCRIPTION
    CONTRACT_DATE
    CONTRACT_NUMBER
    QUANTITY INVOICE_DATE INVOICE_CCY_CODE
    INVOICE_NUMBER
    SUPPORT_PROGRAM
    RENEWAL_START_DATE RENEWAL_END_DATE
    INVOICE_AMT
    INSTANCE_NUMBER
    ENTERED
    STATUS
    CUSTOMER_NAME
    CUSTOMER_NUMBER
    LICENSE_DESCRIPTION
    CONTRACT_DATE
    CONTRACT_NUMBER
    QUANTITY INVOICE_DATE INVOICE_CCY_CODE
    INVOICE_NUMBER
    SUPPORT_PROGRAM
    RENEWAL_START_DATE RENEWAL_END_DATE
    INVOICE_AMT
    INSTANCE_NUMBER
    United Technologies Corporation
    STATUS
    CUSTOMER_NAME
    CUSTOMER_NUMBER
    LICENSE_DESCRIPTION
    CONTRACT_DATE
    CONTRACT_NUMBER
    QUANTITY INVOICE_DATE INVOICE_CCY_CODE
    INVOICE_NUMBER
    SUPPORT_PROGRAM
    RENEWAL_START_DATE RENEWAL_END_DATE
    INVOICE_AMT
    INSTANCE_NUMBER
    The last select statement above results in continuous spitting out of column headings with no data. I've truncated it here to save space. When I go through the Oracle Database XE web front end I see that the table was created; however it says "This table has no data". So still no luck. Hope you can help. Thanks.
    -GM

  • Migrating SQL Script to stored procedure...

    I created a SQL script file to run in SQLPlus to
    generate a fixed-format text file (See EDI_PrepForSend
    below)
    How do i do the same thing in a stored
    package/procedure? Can I utilize the
    script I already have working? I need to
    do it in a stored procedure because I need
    to do dynamic queries.
    TIA
    Chuck Plinta
    [email protected]
    ++++++++++++++++++++++++++
    -- EDI_PrepForSend.sql
    SET CONCAT '#';
    SET ESCAPE OFF;
    SET TERM OFF
    -- Set's for flat file
    SET NEWPAGE 0
    SET SPACE 0
    SET LINESIZE 50
    SET PAGESIZE 0
    SET ECHO OFF
    SET FEEDBACK OFF
    SET HEADING OFF
    SET VERIFY OFF
    SPOOL o:\ClientData\EDI-Send\&2\EDI-HCFA-Dtl-&1-&3.txt
    COLUMN MC_Number FORMAT A15 HEADING MC_Number
    COLUMN MC_Line_Number FORMAT A3 HEADING Ln#
    COLUMN MC_CPT_Code FORMAT A5 HEADING Code
    COLUMN MC_CPT_Modifier FORMAT A2 HEADING Mod
    COLUMN MC_FDOS FORMAT A8 HEADING FDOS
    COLUMN MC_LDOS FORMAT A8 HEADING LDOS
    COLUMN MC_Line_Charge FORMAT 99999.99 HEADING Charge
    SELECT MC.ICN MC_Number,
    '???' MC_Line_Number,
    MC.CPT_Code MC_CPT_Code,
    MC.CPT_Modifier_1 MC_CPT_Modifier,
    TO_CHAR(MC.First_DOS,'YYYYMMDD') MC_FDOS,
    TO_CHAR(MC.Last_DOS,'YYYYMMDD') MC_LDOS,
    MC.Charge MC_Line_Charge
    FROM &1.Decision_Support DS,
    &1.Medical_Claims MC
    WHERE DS.Reprice_Status = 'U' AND
    MC.CID = DS.CID
    ORDER BY MC.ICN, MC.CID;
    SPOOL OFF

    You need to put your select statement in a parameterised function that returns a REF CURSOR. This is all well documented in the PL/SQL users guide.
    Then you amend your SQL*PLUS script to call the function
    VAR rc REFCURSOR
    EXEC :rc := yr_function('&1')
    PRINT rc
    Cheers, APC

  • Dynamic Update Queries - SQL Script

    Hi All,
    I have a table Account_info where columns are ACCT_NO and flag with other information (columns). We are receving a file which contains ACCT_NO and FLAG. Now i need to compare ACCT_NO for Table and file and based on it need to update FLAG column in table.
    To automate this process, i can develop a shell script, which load data from file to temp table and then update statement to update Account_info table. For batch process, i can write a for loop, which commit data after every 10,000 update.
    but client does not want this way. We have to send file to Production team, where they will load data manually into temp table.
    Once done, i have to write a update statement which will take 10000 records to update on every run and then commit it, so there will not be space/memory issue.
    For example, if table has 50,000 records, i have to create 5 update statement. and then i have to send all 5 queries as sql script and send it to Production support.
    It is difficult for me to do it daily.
    Is there any other way, where SQL script is dynamic and based on number of rows/10000 , it create UPDATE statement and run it daily.
    Regards,
    ACE

    ace_friends22 wrote:
    Hi All,
    I have a table Account_info where columns are ACCT_NO and flag with other information (columns). We are receving a file which contains ACCT_NO and FLAG. Now i need to compare ACCT_NO for Table and file and based on it need to update FLAG column in table.
    To automate this process, i can develop a shell script, which load data from file to temp table and then update statement to update Account_info table. For batch process, i can write a for loop, which commit data after every 10,000 update.Why not simply use an external table pointing at the file and use a single update statement? If you write a loop with intermittent commits, this is one of the worst known ways of processing data.
    but client does not want this way.And the client knows how to technically implement a solution then? Why aren't they doing it themselves then?
    We have to send file to Production team, where they will load data manually into temp table.Unnecessary. Use an External table
    Once done, i have to write a update statement which will take 10000 records to update on every run and then commit it, so there will not be space/memory issue.Oracle is an enterprise level database engine capable of processing millions of rows without space/memory issues. If you've encountered shuch an issue you should be trying to identify the cause of it rather than suppress the symptoms.
    For example, if table has 50,000 records, i have to create 5 update statement. and then i have to send all 5 queries as sql script and send it to Production support.Bad Idea ^tm^

  • Execute an SQL Script from Java (myScript.sql) ?

    Hello!
    I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
    I'm connecting to mySQL server using JDBC which works fine, but I was wondering
    how can I run an entire script file, say myScript.sql from within a Java class??
    (an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
    example of an SQL Scritp: myScript.sql>>
    //#create new db
    CREATE DATABASE sample_db;
    //#set active db
    USE sample_db;
    //#set table paramaters
    CREATE TABLE monkeys
    (name CHAR(20),
      age INT UNSIGNED,
      sex ENUM('M','F')
    //#create standard monkeys
    INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
    INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
    //#get recordset
    SELECT * FROM monkeys WHERE age < 50;Thanks for your help!

    The way I understand it is that your mysql.sql script file uses ';' as a delimeter between statements. So now what you can do is that read the whole file and put it inside a string/stringbuffer. Now put this string/stringbuffer to a stringTokenizer with delimeter set as ';'. this way you will recieve your exact statements without scratching your heads as where the statements begin/ends. :-)
    Now once you have your statements than its just a matter of executing them against the database.
    hope this helps.

Maybe you are looking for