4 Replies Latest reply: Dec 5, 2012 12:43 PM by John Spencer RSS

    Explain a function statement in a script

    978187
      Hi everyone,

      Can some help explain in the below sql in a script what the values for rowid=$1 and stat=$2 would be return.

      *******************************************
      update_stat()
      {
      rowid=$1
      stat=$2
      sqlplus -s <<EOF >/dev/null
      $UIDPWD
      set trims on feedback off head off pages 0
      update dbm_cdr_head
      set bi_auto_status = $stat,bi_auto_PP95=90,bi_prep_status=90
      --set bi_auto_status = $stat,bi_auto_PP95=90,bi_prep_status=90
      where rowid = '$rowid'
      ;
      EXIT
      EOF
      }

      *******************************************

      Thank you

      B
        • 1. Re: Explain a function statement in a script
          LPS
          here $1 and $2 are runtime variable or host variable ...whose vlaue will be passed @ Run Time for these....

          check for some sample unix scripts and google it....
          • 2. Re: Explain a function statement in a script
            EdStevens
            Slimdread wrote:
            Hi everyone,

            Can some help explain in the below sql in a script what the values for rowid=$1 and stat=$2 would be return.
            It's not a sql script, it a *nix (unix or linux) shell script, with standard input (stdin) redirection to sqlpus ..
            *******************************************
            update_stat()
            {
            define a function named 'update_stat' to be called elsewhere in the same shell script
            rowid=$1
            create an environment variable named rowid, and assign it the value of the first command line parameter passed to this shell script when it was called.
            stat=$2
            create an environment variable named stat and assign it the value of the second command line parameter passed to this shell script when it was called.
            sqlplus -s <<EOF >/dev/null
            start sqplus in silent mode. The "<<EOF" says to redirect the rest of the lines, up to the EOF, into sqlplus when sqlplus expects input from the keyboard. Th ">/dev/null" says to redirect all standard output to the bit bucket.
            $UIDPWD
            the value of environment variable UIDPWD becomes this command passed to sqlplus
            set trims on feedback off head off pages 0
            update dbm_cdr_head
            set bi_auto_status = $stat,bi_auto_PP95=90,bi_prep_status=90
            --set bi_auto_status = $stat,bi_auto_PP95=90,bi_prep_status=90
            where rowid = '$rowid'
            ;
            EXIT
            additional commands to sqlplus
            EOF
            tells the shell to stop redirecting to sqlplus, and process the rest of the lines itself.
            }
            end the definition of the function.

            >
            *******************************************

            Thank you

            B
            • 3. Re: Explain a function statement in a script
              John Spencer
              Ed:

              Just one minor correction. The $1 and $2 are nor neccesairly passed from the command line. They are the first and second parameters passed to the function, and could come from anywhere, not just the command line.

              John
              • 4. Re: Explain a function statement in a script
                EdStevens
                John Spencer wrote:
                Ed:

                Just one minor correction. The $1 and $2 are nor neccesairly passed from the command line. They are the first and second parameters passed to the function, and could come from anywhere, not just the command line.

                John
                Point taken.