Pl/sql script and select count()

Hello!
Is it possible somehow to put the result of (Select Select) count (h.id) in the "utl_file.put_line" (?)
in this script, plsql?


declare
cursor kursori is
SELECT count (h.id), n.state
OF popperson h, popnationality n
WHERE n.state > 3 and (n.state < 246) or n.state > 246
and h.registerstate = 1 and h.id = n.state group n.poppersonid;
Tietue kursori % ROWTYPE;
tiedosto utl_file.file_type;
Start
tiedosto: = utl_file.fopen (' TEST_OUTPUTDIR ',' test.txt ', 'W');
Open kursori;
loop
extract the kursori in tietue;
When the output kursori % NOTFOUND;
() UTL_FILE.put_line
tiedosto, 'Code '. Tietue. State | ' ' || Tietue. ?) ;
end loop;
close kursori;
UTL_FILE.fclose (tiedosto);
end;
/

Thank you! OV
declare
cursor kursori is
SELECT count(h.id) cnt, n.state
FROM popperson h, popnationality n
WHERE n.state > 3 and (n.state < 246 or n.state > 246)
and h.registerstate=1 and h.id=n.poppersonid Group by n.state;
tietue kursori%ROWTYPE;
tiedosto utl_file.file_type;
begin
tiedosto := utl_file.fopen ('TEST_OUTPUTDIR','test.txt', 'W');
open kursori;
loop
fetch kursori into tietue;
exit when kursori%NOTFOUND;
utl_file.put_line (
tiedosto, 'Code ' || tietue.state || ' ' || tietue.cnt);
end loop;
close kursori;
utl_file.fclose(tiedosto);
end;
/

p.s: not tested.

Concerning

REDA

Tags: Database

Similar Questions

  • What is the difference between count (1) selection of the tab and select count (*) tab;

    What is the difference between count (1) selection of the tab and select count (*) tab;

    994122 wrote:

    Hello

    SQL > set timing on

    SQL > select count (*) of the emp

    2 where deptno = 30;

    COUNT (*)

    ---------------

    6

    Elapsed time: 00:00:00.01

    SQL > select count (1) of the emp

    2 * where deptno = 30

    SQL > /.

    COUNT (1)

    -------------

    6

    Elapsed time: 00:00:00.01

    See that both give the same time

    Do you really think the 100th's of a second it takes 6 rows from counting will truly representative of the difference it takes actually?

    Such a small data set cannot possibly show no difference to these larger units of time (in the calculation of terms where we have millions of instructions per second in lieu)

    As the link to the FAQ provided in the response of Anton (first response on this thread) Watch, count (1) and count (*) are essentially the same, except that count (1) actually get re-written by the query re - write the step of the optimization to make it count (*).

    Generally 'count (*)' makes more sense language, because it reads like "count" while "count (1)" reads as "count we ', which does not have as much good sense when you actually count all.

  • Simple SQL script and export to excel

    Hi guys,.

    I need a script based on the following condition.

    I have a view with the name ZMATERIAL. I want back the 3 fields of view namely,

    ZMATNUM, ZMATCUR, ZMATATTR.

    What is the script that I should write?

    Also how to export data to excel sheet? any body can approach me step by step. I use the version of SQL Developer 1.5.

    Kind regards
    Stalin

    Hi and welcome to the Forum!

    To select data from a table or view, you must use the sql SELECT command. Example to get the data from your view, you can

    select ZMATNUM,ZMATCUR,ZMATATTR from ZMATERIAL
    

    As you said you use SQL Developer just run the query above in your sql developer and it will display the data. Click with the right button on the grid and export the data to excel file.

  • pl sql join and select the join columns. """" t"" c": invalid when debugging

    I noticed the error to the cc. Countries that appears because cc is not yet there at compile time (I had that
    Search this forum).

    is it not a small bit of developer of sql oracle is not a compilation from the outside to the inside/core but
    rather in the form of top-down?

    I'm fine with my conclusion? If so, how to do otherwise, that is, by specifying that cc.country is
    a column of countrycodes attached with table 6?


    SELECT DISTINCT 0,
    2,
    SUBSTR ("metable', 0, 1"): "_ABC";
    "ABC_". "metable,"
    "ABC". CC. country,
    '+'
    FROM table 6
    LEFT JOIN COUNTRYCODE cc
    ON cc. Code = metable
    WHERE metable IS NOT NULL
    AND <>metable "

    OK, but this:

    SELECT DISTINCT 0,
    2,
    SUBSTR('metable', 0, 1) || '_ABC',
    'ABC_' || 'metable',
    'ABC ' ||cc.Country ,
    '+'
    FROM table6
    LEFT JOIN COUNTRYCODE cc
    ON cc.Code = metable
    WHERE metable IS NOT NULL
    AND metable ''
    

    Is not a correct SQL statement - there are very obvious errors, so the error you get is maybe not quite relevant.

    It works:

    SELECT COUNT(cc.Country)
    FROM table6
    LEFT JOIN COUNTRYCODE cc
    ON cc.Code = metable
    WHERE metable IS NOT NULL;
    

    So, get a simple query that works first.

  • With separate SQL query and the counter is wrong.

    Hello

    I have another problem with a query.
    The following data:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    CREATE      TABLE      TABLE_1
       
    (       "ORDER_NR"        VARCHAR2 (12)
    ,        "PRIORITY"        VARCHAR2 (2)
    ,        "WO_STATUS"        VARCHAR2 (1)
    ,        "STATUS_DATE"        DATE
    ,       "ART_NR"                      VARCHAR2 (9)
    ,       "DESCRIPTION"      VARCHAR2 (255)
    ,                 "PRICE"                     VARCHAR2 (10)
    );
    
    CREATE      TABLE      TABLE_2
    (     "ART_NR"            VARCHAR(9)
    ,     "MODELL"              VARCHAR2(10)
    ,     "MANUFACT"         VARCHAR2(20)
    );
    
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300612',     '12',     'U',        TO_DATE('05-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'),     '005231987',     '1ST ANNUAL SERVICE',   '5000.2546');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300638',     '05',     'U',        TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'),     '005667821',     '3RD ANNUAL SERVICE',   '5269.7856');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300638',     '12',     'U',        TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'),     '005667821',     '1ST BIENNIAL SERVICE', '1234.4468');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300638',     '12',     'U',        TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'),     '005667821',     '3RD ANNUAL SERVICE',   '4366.7856');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300762',     '12',     'U',        TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'),     '018743356',     '3RD ANNUAL SERVICE',   '4462.8632');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300766',     '12',     'U',        TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'),     '018743356',     '2ND ANNUAL SERVICE',   '8762.6643');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300766',     '05',     'U',        TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'),     '018743356',     '1ST BIENNIAL SERVICE', '3425.6643');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300766',     '12',     'U',        TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'),     '018743356',     '2ND BIENNIAL SERVICE', '6678.6643');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300612',     '12',     'U',        TO_DATE('06-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'),     '005231987',     '1ST ANNUAL SERVICE',   '5000.2546');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300638',     '05',     'U',        TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'),     '005667821',     '3RD ANNUAL SERVICE',   '5269.7856');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300638',     '12',     'U',        TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'),     '005667821',     '1ST BIENNIAL SERVICE', '1234.4468');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300638',     '12',     'U',        TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'),     '005667821',     '3RD ANNUAL SERVICE',   '4366.7856');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300762',     '12',     'U',        TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'),     '018743356',     '3RD ANNUAL SERVICE',   '4462.8632');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300766',     '12',     'U',        TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'),     '018743356',     '2ND ANNUAL SERVICE',   '8762.6643');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300766',     '05',     'U',        TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'),     '018743356',     '1ST BIENNIAL SERVICE', '3425.6643');
    INSERT      INTO      TABLE_1      (ORDER_NR,              PRIORITY, WO_STATUS,  STATUS_DATE,                                             ART_NR,           DESCRIPTION,            PRICE) 
                  VALUES           ('1KKA1Z300766',     '12',     'U',        TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'),     '018743356',     '2ND BIENNIAL SERVICE', '6678.6643');
    
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT1');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT2');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT3');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT4');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT5');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT6');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT1');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT2');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT3');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT4');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT1');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT2');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT3');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT4');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT5');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT6');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT1');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT2');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT3');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT4');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT5');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005231987',     'X-RAY1',          'MANUFACT6');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT1');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT2');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT3');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('005667821',     'LASER',          'MANUFACT4');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT1');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT2');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT3');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT4');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT5');
    INSERT     INTO      TABLE_2      (ART_NR,            MODELL,         MANUFACT)
                  VALUES           ('018743356',     'VACCUM',          'MANUFACT6');
    COMMIT;
    And my request:
    SELECT T1.ART_NR
    , T2.MODELL
    , SUM(ROUND(T1.PRICE, 2)) AS TOTAL_PRICE
    , COUNT(*) AS QTY
    , TO_CHAR(T1.STATUS_DATE, 'MON-RR') AS MONTH
    FROM TABLE_1 T1, TABLE_2 T2
    WHERE T1.WO_STATUS = 'U'
    AND T1.ART_NR = T2.ART_NR
    AND TO_CHAR(T1.STATUS_DATE, 'MON-RR') = 'FEB-13'
    GROUP BY T2.MODELL
    , T1.ART_NR
    , TO_CHAR(T1.STATUS_DATE, 'MON-RR')
    And the result:
    ART_NR      MODELL     TOTAL_PRICE        QTY     MONTH
    ---------        ----------       -----------                ---------- ------
    018743356 VACCUM     559916.16            96        FEB-13 
    005667821 LASER        173936.48            48        FEB-13 
    005231987 X-RAY1          120006             24        FEB-13
    My problem now is the OTY ist wrong field should count how many times the equipment was in service in Feb - 13 and group them by "MODEL" the production area is not interesting to me, but this is my problem, a model can have several Manufacter and so I had a bad count for my Qty.

    The next step that I need is to group the result also by type of Service (annual or biannual), like this:
    ART_NR      MODELL     TOTAL_PRICE        QTY     MONTH   SERVICE_TYPE
    ---------        ----------       -----------                ---------- ------        ---------------------
    018743356 VACCUM      1234.56               4         FEB-13     ANNUAL
    018743356 VACCUM      4423.48               10       FEB-13     BIENNIAL
    005667821 LASER         4783.11               2         FEB-13     ANNUAL
    005667821 LASER         1123.77               22       FEB-13      BIENNIAL
    005231987 X-RAY1        8966.12               6        FEB-13      ANNUAL
    005231987 X-RAY1        7826.44              12        FEB-13      BIENNIAL
    These values are only out of my head, not the table, just to show what I need.

    Thanks for your help.

    Hosts Reinhard

    Hello

    990524 wrote:
    Hello

    Wow it's great.
    Thanks Frank.

    In my database, this query works like a charm, but I have a problem, sometimes the round command do not work then I get a total price of 1231.0000000000001, I
    tried of TRUNCATES the value, but it's always the same value.

    Sorry, I can not re - create the problem.

    And I put another line in the query that calculates the average price per model:

    , ROUND ( SUM (g.price) / COUNT(*) ,2 ) AS average
    

    Why not just

    , ROUND (AVG (g.price), 2)   AS average
    

    ?

    and in this line, I have the same problem with bad ROUNDS.

    Do you have an idea in this case?

    No, sorry. If I can't get the same behavior, myself, it is not that I do.

    Instead of ROUND, you can use TO_CHAR to (for example) display 2 digits after the decimal point. To_char will automatically round the result. Your front end (for example, the SQL * Plus COLUMN...) FORMAT command) can probably do the same thing.

  • When I go to create a script and select TV Script, the options it gives me are UK TV Script 1...

    How can I change size? Is it the same as US? It is not also tell me if it's a sitcom or drama format. How will I know what I need?

    We don't really have a standard model for the USA. The default templates we have for the United Kingdom are for British television shows. You can always take a default template and customize it according to your needs. Or you can share an example of script with us and we can suggest a model.

    Send through your example script to the: [email protected].

    Kind regards

    Sunny

  • How to assign the variable in the SQL script?

    I have the below running to generate the XML from the file.
    set long 100
    set pages 0
    set trimspool on
    set serveroutput on
    set echo off
    set terminal off
    variable out CLOB
    begin
            pack.proc('&&1','&&2',:out);
    end;
    /
    spool /dir/loc/file1.xml
    select :out from dual;
    spool off
    I'm queue in the order of the coil, the output to a file named file1.xml. I invoke this SQL script from a shell script, I will pass variable association 3rd since the shell script which I want to use in the file ' & & 3'.xml. Help me set this variable to the DIGITAL field in this SQL script and how can I add to the command of the coil?
    set long 100
    set pages 0
    set trimspool on
    set serveroutput on
    set echo off
    set terminal off
    variable out CLOB
    define var1='&1' -- to allow for more readable code
    define var2='&2'
    define var3 ='&3'
    begin
            pack.proc('&var1','&var2',:out);
    end;
    /
    spool /dir/loc/file&var3..xml -- note the substition variable has  . appended
    print out
    spool off
    

    ------------
    Sybrand Bakker
    Senior Oracle DBA

  • Set a variable to Select count (*)

    Hello

    I have the following statement that produce a result of '8' in Oracle SQL Developer.

    SELECT count (*)
    LIB_ISBN_T p,
    Table (XMLSequence)
    extract (p.ISBN_PAYLOAD,
    ((("/ ISBNdb/BookList/BookData/subjects/subject")));

    How can I get this value in a numeric variable so that I can make some statements about the variable If?

    I am using Oracle 10 g and APEX 4

    Thanks a lot for your help.

    Published by: PhilMan2 on November 29, 2010 16:34

    I learned that I had to use the INTO clause.

  • Catch a failed to connect in a script and allowing a new attempt

    Hello
    When we release new code we provide a control to the DBA script that runs all the data/DDL change scripts for different schemas. The script invites you to connect as the users involved to run each script.

    for example, the control script is as
    WHENEVER SQLERROR EXIT ROLLBACK
    
    ACCEPT TNS_STRING PROMPT 'Enter Database Tns Alias:'
    
    PROMPT login as SCHEMA1
    ACCEPT PASSWD PROMPT 'Enter password for SCHEMA1 Account:' HIDE
    CONNECT SCHEMA1/&PASSWD@&&TNS_STRING
    
    @schema1_ddl.sql
    @new_schema1_package.pks
    @new_schema1_package.pkb
    
    PROMPT login as SCHEMA2
    ACCEPT PASSWD PROMPT 'Enter password for SCHEMA1 Account:' HIDE
    CONNECT SCHEMA1/&PASSWD@&&TNS_STRING
    
    @schema2_ddl.sql
    @schema2_data.sql
    
    -- etc
    Sometimes the DBA type a password - for example, schema2 - and we are left with only half of a release. 'Procédures' mean they can't or don't edit the control file to comment made sections so it's a pain in the ass for them to get back to us, we change the script, we review the revised script, we get approval on change, etc.

    We were wondering if there is a way to catch a connection failure in a SQL script and give them a try-I ruined my brain, but I can't think of anything. Anyone?

    It is a 9i database and they run the scripts in 9i SQL * more.

    You can tweak the autour logic and the first fetch and check the two apsswords. Then start running scripts.

    not tested

    WHENEVER SQLERROR EXIT ROLLBACK
    
    ACCEPT TNS_STRING PROMPT 'Enter Database Tns Alias:'
    
    /* testing connect to Schema1 */
    PROMPT login as SCHEMA1
    ACCEPT PASSWD PROMPT 'Enter password for SCHEMA1 Account:' HIDE
    CONNECT SCHEMA1/&PASSWD@&&TNS_STRING
    
    disconnect
    
    /* testing connect to Schema2 */
    PROMPT login as SCHEMA2
    ACCEPT PASSWD2 PROMPT 'Enter password for SCHEMA2 Account:' HIDE
    CONNECT SCHEMA2/&PASSWD2@&&TNS_STRING
    
    disconnect 
    
    /* work on Schema1 */
    CONNECT SCHEMA1/&PASSWD@&&TNS_STRING
    
    @schema1_ddl.sql
    @new_schema1_package.pks
    @new_schema1_package.pkb
    
    /* work on Schema2 */
    CONNECT SCHEMA2/&PASSWD2@&&TNS_STRING
    
    @schema2_ddl.sql
    @schema2_data.sql
    
    -- etc
    

    Published by: Sven w. on January 11, 2011 13:41 - change the formatting

  • SQL script to check the status of the last command

    Hi all

    I need to make a SQL script and call it from Unix (bash) shell.


    =========================
    sqlplus vikas/vikas < < END
    coil /oracle/vikas/output.txt
    order 1
    command 2
    ...
    ....
    command N
    spool off;
    commit;
    END
    =========================


    It works perfectly, but my problem is that if a command fails, the other controls in suite works. However, I need to keep a check when a broken command that you exit the script.

    On unix, we have an option of echo $? to check the status of the previous command, but how to accomplish this SQL.

    Pls help!
    __________________
    == > VIKAS < ==

    =========================
    sqlplus vikas/vikas<>
    coil /oracle/vikas/output.txt
    WHENEVER SQLERROR EXIT; -Add this
    order 1
    command 2
    ...
    ....
    command N
    spool off;
    commit;
    END
    =========================

  • How can I select stuff of table has created in the PL/SQL script?

    When I execute a select statement, SQLplus complains of the table does not exist. But it has been created? Don't know what goes wrong... Thanks in advance...

    The code is as follows:




    DECLARE

    column_table varchar (50): = "column_table";
    r_count NUMBER (10): = 0;

    BEGIN
    column_table: = UPPER (column_table);

    -I created the table here and validation
    IMMEDIATELY RUN 'CREATE TABLE' | column_table | "(varchar2 (100) from table_name, column_name varchar2 (1000))';
    commit;

    IF someCondition THEN
    Bonneau
    -It's where SQLPLUS complains about the table or view does not exist
    Select count (1) in the column_table r_count where table_name = someValue;
    Bonneau
    END IF;


    END;
    /

    You will need to use dynamic sql to access objects created by using dynamic sql.
    >
    Select count (1) in the column_table r_count where table_name = someValue;
    >
    During this "compilation" the table declaration that it is trying to reference does not exist then you get an error.

    The table does exist when the code is executed.

  • How to format the output of a .sql script that has select statements.

    Hello

    I have a .sql script which is having several select statements. Each Select statement is to have hundreds of Table columns.

    When we run the .sql script, we are unable to read the output.

    Please let know us the commands that we include for better readable output format.

    You work with the lin standard set 80.
    Increase this setting to set lin 3000 or more.

  • SQL script on emp and dept

    Tables to be used:

    1 scott.emp

    2 scott.dept

    For all s deptno in dept table if there is at least 1 used in the emp table output should be 1 otherwise the output must be 0.

    For example, deptno in dept table 40 have no employees present in the emp table if the output should be 0.

    Desired output:

    REQ

    ----------

    0

    Now, if I add a line in the table emp which deptno is 40 (now for all deptnos in the dept table, there is record emp at least 1), production should be 1

    REQ

    ----------

    1

    I formed query as below but do not know how to do furthur

    SELECT count (empno), deptno from emp by deptno group

    Hello

    2742751 wrote:

    Select dept Dept. d

    where 0! =

    (select count (*) in e emp

    where e.deptno = d.deptno

    );

    This will not work; There is no column dept in the dept table.

    Select deptno from dept d

    where there are

    (select count (*) in e emp

    where e.deptno = d.deptno

    );

    Do not know how to perform tried furthur two queries

    Good start.  It's a good way to use a correlated EXISTS subquery.  (EXISTS subqueries are almost always correlated.  Why?  Discuss among you).

    The query above tells you what are departments have used; He said nothing on which federal departments have not used, and this is what primarily interests us.  There are probably still some departments that have employees (even if you test this in any case); the real question here is: Y at - it all departments that have not used?   So change IS not there and see what you get.

    SELECT DeptNo

    D DEPT

    WHERE DOES NOT EXIST)

    SELECT 1 - keep it simple

    FROM emp e

    WHERE e.deptno = d.deptno

    )

    ORDER BY deptno

    ;

    It's okay put you in the SELECT a clause subquery EXISTS; the subquery does not return actually what you say, the subquery just returns TRUE or FALSE. You need to select for syntax, but you might as well put something that is easy to type at this location.

    Here is the result of the above query:

    DEPTNO

    ----------

    40

    What is the problem with that?  I see two problems:

    It produces the real Department deptno; We want that it displays 0 where there is a Ministry without employee.  It's an easy solution: change the SELECT main clause so that it returns the literal 0 instead of deptno.

    The other problem is trickier.  The above query produces 1 row of output for each Department that satisfies the condition in the WHERE clause.  In the table scott.emp, it happens to be just 1 row, but if there were 2 or 3, or 2300 these departments, then the above query would produce 2 or 3 or 2300 lines of output.  What happens if 0 rows meet the condition in the WHERE clause?  Then the query would produce 0 lines of output.  It's no good: we want exactly 1 row of output, regardless of the number of rows satisfy the WHERE clause.  Do you know of any which is guaranteed to produce 1 row of output, regardless of the number of lines it finds, even if it is 0 rows?  An aggregate function without a GROUP BY doing the exact clause that: she produced exactly 1 row of output, no matter what, if anything, that it finds in the table, we can say:

    SELECT MIN (0) AS req

    D DEPT

    WHERE DOES NOT EXIST)

    SELECT 1

    FROM emp e

    WHERE e.deptno = d.deptno

    )

    ORDER BY deptno

    ;

    Output:

    REQ

    ----------

    0

    0 being the only value which is ever produced, no matter if we use MIN or MAX.  We could even use AVG or SUM if we wanted to be cute.

    However, there is still a problem: If no rows satisfy the WHERE clause, no 0 will be produced, so MIN returns null.  We want the query to display 1 in this case, not NULL, so we can use NVL do display 1 instead of NULL, like this:

    SELECT NVL (MIN (0)

    1

    ) AS req

    D DEPT

    WHERE DOES NOT EXIST)

    SELECT 1

    FROM scott.emp e

    WHERE e.deptno = d.deptno

    )

    ORDER BY deptno

    ;

    Furthermore, I copy the scott schema emp and dept tables in my schema to test this, so I could add or remove data to test the situations as

    • several services without employees
    • no representation without employees
    • no departments at all (emply dept table)
    • no departments with emplpoyees

    You don't want to edit any table provided by Oracle; You must keep the scott paintings exactly as they are, then, make copies you can change anything you want.

  • Create jobs and positions via PL/SQL script

    Hi, it is recommended to insert new jobs and positions via PL/SQL Script?

    I know it's possible, I'm not sure if it is recommended. especially when it's via a direct insertion.

    Is there an API for it?

    I have about 200 + positions I need to set in our Instance of the EBS Test.

    Thank you!

    The APIs are the best way to do it in batches of charges-

    Job: HR_JOB_API

    Position: HR_POSITION_API

    To know that all the seeds API, add the responsibility of integrated SOA gateway

  • Script to select several tables in indesign and editing

    Hi and I hope you can help.

    I need a script that will select all the tables in a doc great indd with tables imported from word.

    I read another question on here need to select all tables simliar

    but I don't have the knowledge of script to modify it according to my needs. I hope someone can help. Hope also I ask not too much either, but here goes.

    I need to select all the tables and the weight of the 0.25pt race

    Then select the row of the top of each column and fill it with 10% black, and make the top line (or cell heights) 'exactly' (not ' at least') height 5.09 mm

    That would make me really, but is it possible to adjust the width of the columns of these tables too using a script and style of cell?

    It would be rank 1 'exactly' mm 112,956 1 cell (cell style 1) and cell 2 row 1 'exactly' 4,956 (cell 2 style)

    Cell 1 (single cell) line 2 117.912 mm (cell style 3)

    1 (single cell) tier 3 the cell (cell 3 style)

    I really hope you can help, because it will allow me to win a load of time.

    Thank you 1 million - in the meantime I will continue to walk through them all manually hoping someone can help before I did all - but it seems that taking me days.

    Thanks again

    Andy

    Password: (ignore the bit of text that says I Anson v Stuart '-c' is just the beginning of the next table)

    start_zpsiby9gwys.jpg

    Finished format:

    finished%20look_zpsjukz9xeo.jpg

    I added the number 2 in the second row of cell 1 all on my own

    Hello

    Use the update below for the height of the top row.

    app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().bottomEdgeStrokeWeight = "0.25pt";
    app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().topEdgeStrokeWeight = "0.25pt";
    app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().leftEdgeStrokeWeight = "0.25pt";
    app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().rightEdgeStrokeWeight = "0.25pt";
    try
    {
    app.activeDocument.colors.item("Black10%").name;
    }
    catch (e){
    app.activeDocument.colors.add({name:"Black10%", model:ColorModel.process, colorValue:[0, 0, 0, 10]});
    }
    app.activeDocument.stories.everyItem().tables.everyItem().rows[0].fillColor = "Black10%";
    app.activeDocument.stories.everyItem().tables.everyItem().rows[0].properties = {autoGrow:false, minimumHeight:"5.09mm", maximumHeight:"5.09mm"};
    

    Thank you

    Kitty

Maybe you are looking for

  • The program is very slow to start and then when running. Caused by McAfee "Active Protection".

    Win XP Professional operating. TO 38.3.0 with lightning 4.0.3.1 Since the update of the program, it became initiate very slow and when finally the opening is generally slow, all around. Perform simple tasks like move a file, the program seems to wond

  • past messages

    Hi, I posted a few questions here, now I want to search these posts once again, how can I do? Sorry if this is the wrong place to ask simple questions like that.

  • I would like to organize the mail with Inbox and the text next

    I would like to read my mail to the right of the incoming mail and not lower or higher. Is this possible?

  • Where to buy Satellite L350-170?

    Hello I'm looking to replace my laptop L350D Eqiuim after an announcement of the accident it brewing and...I want to stay with Toshiba cos it very well built. I want to spend about £400 and was watching this more or less identical to the 1, I now htt

  • Touch Panel matching

    We currently profile C20 with touchscreens for control. Is there a way to set the username/password matching name so that it is different from the login / admin password? Sent by Cisco Support technique iPad App